#include <bits/stdc++.h>
using namespace std;
int n;
int f[100];
int p[100][10];
int eigyou(int day, int time) { return (1 << (day << 1)) << time; }
int rieki(int eigyoubi) {
  int rieki = 0;
  for (int i = 0; i < n; i++) {
    int kaburi = f[i] & eigyoubi;
    int num = 0;
    for (int j = 0; j < 10; j++) {
      if ((kaburi >> j) & 1 != 0) num++;
    }
    rieki += p[i][num];
  }
  return rieki;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    f[i] = 0;
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        int in;
        cin >> in;
        if (in != 0) f[i] |= eigyou(j, k);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  int ans = -0x7FFFFFFF;
  for (int i = 1; i < 1 << 10; i++) {
    ans = max(ans, rieki(i));
  }
  cout << ans << endl;
  return 0;
}
