#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int F[110] = {0};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      int x;
      cin >> x;
      F[i] += x;
    }
  }
  long long P[110][20] = {0};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  long long res = 0;
  bool can = false;
  for (int i = 0; i < N; i++) {
    long long maxp = P[i][0];
    for (int j = 1; j <= F[i]; j++) {
      if (maxp <= P[i][j]) {
        maxp = P[i][j];
        can = true;
      }
    }
    res += maxp;
  }
  if (can) {
    cout << res << endl;
  } else {
    long long sub = 2 * 10000000;
    for (int i = 0; i < N; i++) {
      sort(P[i], P[i] + (F[i]), greater<long long>());
      sub = min(sub, P[i][0] - P[i][1]);
    }
    cout << res - sub << endl;
  }
  return 0;
}
