#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int MAXN = 1e5 + 5;
const long long MOD = 1e9 + 7;
int f[105][6][3];
int p[105][11];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++) scanf("%d", &f[i][j][k]);
  int aaa;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) scanf("%d", &p[i][j]);
  }
  int maxd = -0x3f3f3f3f;
  int ans = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    int suma = p[i][1];
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        sum += f[i][j][k];
        if (sum != 0) suma = max(suma, p[i][sum]);
      }
    }
    if (suma > 0) {
      flag = 1;
      ans += suma;
    }
    maxd = max(maxd, suma);
  }
  if (flag == 0)
    cout << maxd << endl;
  else
    cout << ans << endl;
  return 0;
}
