#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int N;
int F[100][5][2];
int P[100][11];
int bitcount(int bits) {
  int num = 0;
  for (; bits != 0; bits &= bits - 1) {
    num++;
  }
  return num;
}
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 < 10; j++) {
      cin >> P[i][j];
    }
  }
  int res = -1000000000;
  for (int s = 1; s < (1 << 10); s++) {
    int tmp = 0;
    for (int shop = 0; shop < N; shop++) {
      int c = 0;
      for (int d = 0; d < 10; d++) {
        if (((1 << d) & s) > 0 && F[shop][d % 5][d / 5] == 1) c++;
      }
      cout << s << " " << c << endl;
      tmp += P[shop][c];
    }
    chmax(res, tmp);
  }
  cout << res << endl;
}
