#include <bits/stdc++.h>
using namespace std;
long long N;
long long F[100][5][2];
long long P[100][10];
long long eigyo[5][2];
long long solve(long long x, long long y) {
  eigyo[x / 2][x % 2] = y;
  if (x == 9) {
    long long check = 0;
    for (long long j = 0; j < 10; j++) {
      if (eigyo[j / 2][j % 2] == 0) check += 1;
    }
    if (check == 10) return -1000000000000;
    long long reword = 0;
    for (long long i = 0; i < N; i++) {
      long long count = 0;
      for (long long j = 0; j < 10; j++) {
        if (eigyo[j / 2][j % 2] == 1 && F[i][j / 2][j % 2] == 1) count += 1;
      }
      reword += P[i][count];
    }
    return reword;
  } else {
    return max(solve(x + 1, 0), solve(x + 1, 1));
  }
}
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < 5; j++) {
      cin >> F[i][j][0] >> F[i][j][1];
    }
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j <= 10; j++) {
      cin >> P[i][j];
    }
  }
  long long res = max(solve(0, 0), solve(0, 1));
  cout << res << endl;
  return 0;
}
