#include <bits/stdc++.h>
using namespace std;
void showBit(unsigned b) {
  for (int j = 9; j >= 0; j--) {
    cout << ((b >> j) & 1);
  }
}
int main() {
  int N;
  cin >> N;
  vector<unsigned> F(N);
  for (int i = 0; i < N; i++) {
    unsigned tmp = 0;
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        tmp <<= 1;
        int f;
        cin >> f;
        tmp |= f;
      }
    }
    F[i] = tmp;
  }
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 10; j++) {
      int p;
      cin >> p;
      P[i][j] = p;
    }
  }
  int ans = -11000000;
  for (unsigned b = 1; b < (1 << 10); b++) {
    int x = 0;
    for (int j = 0; j < N; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++) {
        cnt += ((b >> k) & (F[j] >> k) & 1);
      }
      x += P[j][cnt];
    }
    ans = max(x, ans);
  }
  cout << ans << endl;
  return 0;
}
