#include <bits/stdc++.h>
using namespace std;
const int iinf = 1 << 29;
const long long linf = 1ll << 61;
int N;
int F[101][6][3];
int P[101][11];
int main(int argc, char* argv[]) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= 5; j++) {
      int a, b;
      scanf("%d%d", &a, &b);
      F[i][j][1] = a;
      F[i][j][2] = b;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &P[i][j]);
    }
  }
  int m = 0xffffffff;
  for (int i = 1; i < (1 << 10); i++) {
    int s = 0;
    for (int k = 1; k <= N; k++) {
      int t = 0;
      for (int j = 0; j < 10; j++) {
        if (i & (1 << j)) {
          t += F[k][j / 2 + 1][j % 2 + 1];
        }
      }
      s += P[k][t];
    }
    m = max(m, s);
  }
  printf("%d\n", m);
  return 0;
}
