#include <bits/stdc++.h>
using namespace std;
int N;
int F[103][7];
int P[103][13];
int c[103][103];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    for (int j = 1; j <= 5; j++) {
      int x, y;
      scanf("%d%d", &x, &y);
      F[i][j] = x * 2 + y;
    }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 11; j++) scanf("%d", &P[i][j]);
  int ret = -1 << 30;
  for (int jos = 1; jos <= 1024; jos++) {
    int cnt[103] = {0}, ans = 0;
    for (int i = 0; i < N; i++) {
      for (int k = 1; k < 10; k += 2) {
        int p = jos >> k;
        cnt[i] += F[i][(k + 1) / 2] & 1 + ((F[i][(k + 1) / 2] / 2) & 1);
      }
      ans += P[i][cnt[i]];
    }
    if (ans > ret) ret = ans;
  }
  printf("%d\n", ret);
  return 0;
}
