#include <bits/stdc++.h>
using namespace std;
long long n, x, p[101][11];
vector<long long> a;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long cur = 0;
    for (int j = 0; j < 10 && cin >> x; j++) cur += x;
    a.push_back(cur);
  }
  long long mx = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
      if (j && j <= a[i]) mx = max(mx, p[i][j]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long cur = 0;
    for (int j = 0; j <= a[i]; j++) cur = max(cur, p[i][j]);
    ans += cur;
  }
  int ch = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= a[i]; j++)
      if (p[i][j] >= 0) ch = 1;
  }
  if (!ch)
    cout << mx << endl;
  else
    cout << ans << endl;
  return 0;
}
