#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  vector<ll> f(n);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 10; j++) {
      ll x;
      cin >> x;
      f[i] += x;
    }
  }
  vector<ll> p(n);
  vector<ll> zero(n);
  for (ll i = 0; i < n; i++) {
    cin >> zero[i];
    ll Max = -1e16;
    ll sum = 0;
    for (ll j = 1; j < 11; j++) {
      ll x;
      cin >> x;
      if (j <= f[i]) {
        Max = max(Max, x);
      }
    }
    p[i] = Max;
  }
  ll rMax = -1e16;
  ll basho = 0;
  for (ll i = 0; i < n; i++) {
    if (p[i] > rMax) {
      rMax = p[i];
      basho = i;
    }
  }
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    if (i == basho) {
      rMax = max(zero[i], p[i]);
      continue;
    } else {
      sum += max(zero[i], p[i]);
    }
  }
  cout << rMax + sum << endl;
  return 0;
}
