#include <bits/stdc++.h>
int main(void) {
  int n;
  int i, j, mask;
  int tmp;
  int f[100] = {0};
  int p[100][11] = {0};
  int kabutta;
  int profit = 0;
  long int answer = -10000000;
  scanf("%d", &n);
  for (i = 0; i < n * 10; i++) {
    scanf(" %d", &tmp);
    if (tmp == 1) {
      f[i / 10] += (int)pow(2, (9 - i % 10));
    }
  }
  for (i = 0; i < n * 11; i++) {
    scanf(" %d", &p[i / 11][i % 11]);
  }
  for (i = 1; i < (1 << 10); i++) {
    for (j = 0; j < n; j++) {
      kabutta = 0;
      if ((i & f[j]) > 0) {
        for (mask = 1; mask < (1 << 10); mask = (mask << 1)) {
          if (((i & f[j]) & mask) == mask) {
            kabutta++;
          }
        }
      }
      profit += p[j][kabutta];
    }
    answer = answer > profit ? answer : profit;
    profit = 0;
  }
  printf("%ld\n", answer);
  return 0;
}
