#include <bits/stdc++.h>
using namespace std;
long long i = 0, j = 0, k = 0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s,
          t = 1, u, v, w, x, y, z, maxx = INT_MIN, minn = INT_MIN, ans = 0,
          sum = 0, flag = 0, cnt = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  long long A[n];
  for (long long i = 0; i < (n); i++) {
    A[i] = 0;
    for (long long j = 0; j < (10); j++) {
      cin >> x;
      A[i] += x;
    }
  }
  for (long long i = 0; i < (n); i++) {
    maxx = INT_MIN;
    for (long long j = 0; j < (11); j++) {
      cin >> x;
      if (j <= A[i]) {
        maxx = max(maxx, x);
      }
      if (minn < x && j == 1) {
        minn = x;
      }
    }
    ans += maxx;
  }
  if (ans == 0) {
    cout << minn << endl;
  } else
    cout << ans << endl;
  return 0;
}
