#include <bits/stdc++.h>
using namespace std;
long long ceil2(long long a, long long b) {
  if (a % b) {
    return a / b + 1;
  } else {
    return a / b;
  }
}
struct edge {
  long long to, cost;
};
long long ans = -2000001145;
long long n, m;
long long f[111][2][6];
long long p[111][11];
signed main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) {
      for (long long k = 0; k < 2; k++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 10 + 1; j++) {
      cin >> p[i][j];
    }
  }
  for (long long i = 0; i < 1 << 10; i++) {
    if (i == 0) continue;
    long long smallans = 0;
    for (long long j = 0; j < n; j++) {
      long long cnt = 0;
      for (long long k = 0; k < 10; k++) {
        if (((1 << k) & i) && f[j][k / 2][k % 2]) cnt++;
      }
      smallans += p[j][cnt];
    }
    ans = max(ans, smallans);
  }
  cout << ans << endl;
}
