#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p[110][20] = {0};
  long long cmax[110] = {0};
  long long n;
  cin >> n;
  long long f;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> f;
      cmax[i] += f;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 11; ++j) cin >> p[i][j];
  }
  bool flag = false;
  long long ans = 0, res = -1000000000;
  for (int i = 0; i < n; ++i) {
    long long c = p[i][0];
    for (int j = 0; j < cmax[i] + 1; ++j) {
      if (j > 0) res = max(res, p[i][j]);
      if (c < p[i][j]) {
        c = max(c, p[i][j]);
        flag = true;
      }
    }
    ans += c;
  }
  if (flag)
    cout << ans << endl;
  else
    cout << res << endl;
}
