#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
const ll MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  int n;
  cin >> n;
  vi vec(n);
  for (long long i = 0; i < (long long)(n); i++) {
    ll cnt = 0;
    for (long long j = 0; j < (long long)(10); j++) {
      int a;
      cin >> a;
      cnt += a;
    }
    vec[i] = cnt;
  }
  vvl g(n, vl(11));
  for (long long i = 0; i < (long long)(n); i++)
    for (long long j = 0; j < (long long)(11); j++) cin >> g[i][j];
  ll ans = 0;
  ll zero_cnt = 0;
  ll zero_add = -MOD;
  for (long long i = 0; i < (long long)(n); i++) {
    pl memo = pl(-MOD, 0);
    for (long long j = 0; j < (long long)(vec[i] + 1); j++) {
      if (j != 0) chmax(zero_add, g[i][j] - g[i][0]);
      if (g[i][j] >= memo.first) {
        memo.first = g[i][j];
        memo.second = j;
      }
    }
    ans += memo.first;
    zero_cnt += (memo.second == 0);
  }
  if (zero_cnt == n) ans += zero_add;
  cout << ans << endl;
  return 0;
}
