#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int F[N][10], pair<int, int>[N][11];
  map<int, int> m;
  for (int i = (int)0; i < (int)N; i++)
    for (int j = (int)0; j < (int)10; j++) {
      cin >> F[i][j];
      m[i] += F[i][j];
    }
  for (int i = (int)0; i < (int)N; i++)
    for (int j = (int)0; j < (int)11; j++) cin >> pair<int, int>[i][j];
  int count = 0;
  int max_array[N];
  int max2_array[N];
  memset(max_array, 0, sizeof(max_array));
  memset(max2_array, 0, sizeof(max2_array));
  for (int i = (int)0; i < (int)N; i++) {
    int idx = 0;
    max_array[i] = pair<int, int>[i][0];
    max2_array[i] = pair<int, int>[i][1];
    for (int j = (int)1; j < (int)m[i] + 1; j++) {
      if (max_array[i] < pair<int, int>[i][j]) {
        max_array[i] = pair<int, int>[i][j];
        idx = j;
      } else if (max2_array[i] < pair<int, int>[i][j]) {
        max2_array[i] = pair<int, int>[i][j];
      }
    }
    count += idx;
  }
  long long res = 0;
  if (count != 0) {
    for (int i = (int)0; i < (int)N; i++) res += max_array[i];
    cout << res << endl;
  } else {
    long long min_v = 1e9;
    int idx = 0;
    for (int i = (int)0; i < (int)N; i++) {
      if (min_v > max_array[i] - max2_array[i]) {
        idx = i;
        min_v = max_array[i] - max2_array[i];
      }
    }
    res = res - max_array[idx] + max2_array[idx];
    cout << res << endl;
  }
}
