#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> open(110);
  int f;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f;
      open[i] += f;
    }
  }
  int ma = -1e7, mi = -1e7, ct = 0;
  int p, ans = 0;
  for (int i = 0; i < N; i++) {
    ma = -1e7;
    for (int j = 0; j <= 10; j++) {
      cin >> p;
      if (j <= open[i]) {
        if (ma < p) {
          ma = p;
          if (j != 0) ct++;
        }
        if (j != 0) {
          mi = max(mi, p);
        }
      }
    }
    ans += ma;
  }
  if (ct == 0) ans += mi;
  cout << ans << endl;
}
