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