#include <bits/stdc++.h>
int main() {
  int min = 999;
  int N, L = 0, i, j, t = 0, sum = 0;
  int F[100][14], a[100] = {0};
  long long P[100][15];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) scanf("%d", &F[i][j]);
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 11; j++) scanf("%d", &P[i][j]);
  for (i = 0; i < N; i++) {
    sum = 0;
    int max = -999;
    int max2 = -999;
    for (j = 0; j < 10; j++) sum += F[i][j];
    for (j = 0; j <= sum; j++) {
      if (P[i][j] > max) {
        max = P[i][j];
      }
    }
    for (j = 1; j <= sum; j++) {
      if (P[i][j] > max2) max2 = P[i][j];
    }
    a[i] = max - max2;
    L += max;
  }
  int b = 0;
  for (i = 0; i < N; i++) {
    b += P[i][0];
    if (a[i] < min) {
      min = a[i];
    }
  }
  if (b == L)
    printf("%d", L - min);
  else
    printf("%d", L);
  return 0;
}
