#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int n;
int f[110][5][2];
int p[110][10];
int func(bitset<10> bs) {
  int obj = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int ii = 0; ii < 10; ii++) {
      int j = ii / 2;
      int k = ii % 2;
      if (bs[ii] == 1 && f[i][j][k] == 1) {
        cnt++;
      }
    }
    obj += p[i][cnt];
  }
  return obj;
}
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 < 11; j++) {
      cin >> p[i][j];
    }
  }
  int opt = -999999999;
  for (int i = 0; i < 1 << 10; i++) {
    if (i == 0) {
      continue;
    }
    bitset<10> bs(i);
    int obj = func(bs);
    if (obj > opt) {
      opt = obj;
    }
  }
  cout << opt << endl;
}
