#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int** F = new int*[N];
  int** P = new int*[N];
  int* max_p = new int[N];
  for (int i = 0; i < N; i++) {
    F[i] = new int[11];
    P[i] = new int[12];
  }
  for (int i = 0; i < N; i++) {
    F[i][0] = 0;
    for (int j = 1; j < 11; j++) {
      cin >> F[i][j];
      F[i][0] += F[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    P[i][0] = -256;
    for (int j = 1; j < 12; j++) {
      cin >> P[i][j];
    }
  }
  int max = 0;
  int flag = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= F[i][0] + 1; j++) {
      if (P[i][j] > P[i][0]) {
        P[i][0] = P[i][j];
      }
    }
    max += P[i][0];
  }
  for (int i = 0; i < N; i++) {
    if (P[i][0] == P[i][1]) flag++;
  }
  int min_p = 0;
  if (flag == N) {
    max = 0;
    for (int i = 1; i < N; i++) {
      if (P[min_p][0] > P[i][0]) {
        max += P[min_p][0];
        min_p = i;
      } else {
        max += P[i][0];
      }
    }
    P[min_p][0] = P[min_p][2];
    for (int j = 3; j <= F[min_p][0] + 1; j++) {
      if (P[min_p][j] > P[min_p][2]) {
        P[min_p][0] = P[min_p][j];
      }
    }
    max += P[min_p][0];
  }
  cout << max << endl;
  for (int i = 0; i < N; i++) {
    delete[] F[i];
    delete[] P[i];
  }
  delete[] F;
  delete[] P;
  return 0;
}
