#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int M = 15;
int main() {
  long long int n, f[N], p[N][M], x, ans = -100000000, ans2 = 0;
  bool b = 0;
  cin >> n;
  memset(f, 0, sizeof(f));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> x;
      f[i] += x;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
    x = *max_element(p[i] + 1, p[i] + f[i] + 1);
    if (x >= 0) {
      b = 1;
      ans2 += x;
    }
    ans = max(ans, p[i][1]);
  }
  if (b) {
    cout << ans2 << '\n';
  } else {
    cout << ans << '\n';
  }
}
