#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n;
bool f[N][6][3];
int p[N][11];
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++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  int ans = -2e9;
  for (int mask = 1; mask < (1 << 20); mask++) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      int C = 0;
      for (int j = 0, X = 1; j < 20; j += 2, X++) {
        C += ((mask & (1 << j)) && f[i][X][1]);
        C += ((mask & (1 << (j + 1))) && f[i][X][2]);
      }
      cnt += p[i][C];
    }
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}
