#include <bits/stdc++.h>
using namespace std;
int N;
int F[101][5][2], P[101][11], open[11];
long long int ans = -100000000;
long long int f() {
  long long int res = 0;
  for (int i = 0; i < N; i++) {
    int c = 0, d = 0;
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        if (F[i][j][k] == 1 && open[d] == 1) c++;
        d++;
      }
    }
    res += P[i][c];
  }
  return res;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  for (int i = 1; i < 1 << 10; i++) {
    for (int j = 0; j < 10; j++) open[j] = 0;
    int x = i, c = 0;
    while (x > 0) {
      if (x % 2 == 1) open[c] = 1;
      x /= 2;
      c++;
    }
    ans = max(f(), ans);
  }
  cout << ans << endl;
  return 0;
}
