#include <bits/stdc++.h>
using namespace std;
int f[105][6][3], p[105][15], n, pr[15];
long long ans;
int calc() {
  long long ts = 0;
  for (int i = 1; i <= n; i++) {
    int c = 0;
    for (int j = 1; j <= 5; j++) {
      for (int k = 1; k <= 2; k++) {
        if (pr[(j - 1) * 2 + (k - 1)] == f[i][j][k] && f[i][j][k] == 1) {
          c++;
        }
      }
    }
    ts += (long long)p[i][c];
  }
  return ts;
}
void gao(int c, int x) {
  if (c == 10) {
    long long tv = calc();
    ans = ans > tv ? ans : tv;
    return;
  }
  if (x != c) {
    pr[c] = 0;
    gao(c + 1, x);
  }
  pr[c] = 1;
  gao(c + 1, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      for (int k = 1; k <= 2; k++) {
        scanf("%d", &f[i][j][k]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  ans = -0xfffffff;
  for (int i = 0; i < 10; i++) {
    gao(0, i);
  }
  printf("%lld\n", ans);
}
