#include <bits/stdc++.h>
using namespace std;
bool f[110][10][5], a[20];
int p[110][20], ans = -0x7fffffff, n;
void dfs(int k) {
  if (k > 10) {
    int sum = 0;
    for (int i = 1; i <= 10; i++) sum += a[i];
    if (sum == 0) return;
    int t[110] = {0}, ss = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= 5; j++)
        for (int k = 1; k <= 2; k++)
          if (f[i][j][k] == 1 && a[(j - 1) * 2 + k] == 1) t[i]++;
    for (int i = 1; i <= n; i++) ss += p[i][t[i]];
    ans = max(ans, ss);
    return;
  }
  dfs(k + 1);
  a[k] = 1;
  dfs(k + 1);
}
int main() {
  cin >> 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]);
  dfs(1);
  cout << ans << endl;
  return 0;
}
