#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int f[101][6][3];
  int p[101][11];
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < 6; j++) {
      for (int k = 1; k < 3; k++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  long long answer;
  for (int i = 1; i < 2048; i++) {
    int mon1 = i % 2;
    int mon2 = (i / 2) % 2;
    int tue1 = (i / 4) % 2;
    int tue2 = (i / 8) % 2;
    int wed1 = (i / 16) % 2;
    int wed2 = (i / 32) % 2;
    int thu1 = (i / 64) % 2;
    int thu2 = (i / 128) % 2;
    int fri1 = (i / 256) % 2;
    int fri2 = (i / 512) % 2;
    int open[101];
    for (int j = 1; j < n + 1; j++) {
      open[j] = f[j][1][1] * mon1 + f[j][1][2] * mon2 + f[j][2][1] * tue1 +
                f[j][2][2] * tue2 + f[j][3][1] * wed1 + f[j][3][2] * wed2 +
                f[j][4][1] * thu1 + f[j][4][2] * thu2 + f[j][5][1] * fri1 +
                f[j][5][2] * fri2;
    }
    long long compare = 0;
    for (int j = 1; j < n + 1; j++) {
      compare = compare + p[j][open[j]];
    }
    if (i > 1) {
      answer = max(answer, compare);
    } else {
      answer = compare;
    }
  }
  cout << answer << endl;
  return 0;
}
