#include <bits/stdc++.h>
using namespace std;
int n;
int f[105][7][4];
int p[105][13];
int c[105];
int main(void) {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++)
      for (int k = 1; k <= 2; k++) cin >> f[i][j][k];
  for (int i = 1; i <= n; i++)
    for (int k = 0; k <= 10; k++) cin >> p[i][k];
  long long ans = (-10000005);
  for (int k = 1; k < 1024; k++) {
    memset(c, 0, 105);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 10; j++) {
        int tmp = (k >> j) % 2;
        if (tmp == 1 && f[i][j / 2 + 1][j % 2 + 1] == 1) {
          c[i]++;
        }
      }
    }
    long long cost = 0;
    for (int i = 1; i <= n; i++) {
      cost += (long long)p[i][c[i]];
    }
    if (ans < cost) ans = cost;
  }
  cout << ans;
  return 0;
}
