#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>>;
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;
}
using pi = pair<int, int>;
using pl = pair<ll, ll>;
signed main() {
  int n;
  cin >> n;
  vl F(n);
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(10); j++) {
      int a;
      cin >> a;
      F[i] += a;
    }
  }
  ll zero_cnt = 0;
  ll zero_add = -MOD;
  ll ans = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    pl add = pl(-MOD, -1);
    ll memo;
    for (long long j = 0; j < (long long)(11); j++) {
      ll a;
      cin >> a;
      if (j == 0) memo = a;
      if (j != 0 && j <= F[i]) {
        chmax(zero_add, a - memo);
      }
      if (j <= F[i] && add.first <= a) {
        add = make_pair(a, j);
      }
    }
    ans += add.first;
    if (add.second == 0) zero_cnt++;
  }
  if (zero_cnt == n) {
    ans += zero_add;
  }
  cout << ans << endl;
  return 0;
}
