#include <bits/stdc++.h>
using namespace std;
template <typename T>
T id(T b) {
  return b;
};
template <class It>
bool all(It f, It l) {
  return std::all_of(f, l, id<bool>);
}
template <class It>
bool any(It f, It l) {
  return std::any_of(f, l, id<bool>);
}
const int MAX_N = 100;
int n;
int f[MAX_N] = {};
int p[MAX_N][10];
int main() {
  cin >> n;
  int x;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++) {
        cin >> x;
        if (x == 1) f[i] |= (1 << (2 * j + k));
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 10; j++) cin >> p[i][j];
  int res = INT_MIN;
  for (int pat = 1; pat < (1 << 10); pat++) {
    int temp = 0;
    for (int i = 0; i < n; i++) {
      int c = __builtin_popcount(pat & f[i]);
      temp += p[i][c];
    }
    res = max(res, temp);
  }
  cout << res << endl;
  return 0;
}
