#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f;
  int p[n][11];
  int f_num[n];
  int max_n = 0;
  for (int i = 0; i < n; i++) {
    f_num[i] = 0;
    for (int j = 0; j < 10; j++) {
      cin >> f;
      f_num[i] += f;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  int p1[n], p2[n];
  int s1[n], s2[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    p1[i] = -10000001;
    p2[i] = -10000001;
    for (int j = 0; j <= f_num[i]; j++) {
      if (p[i][j] > p1[i]) {
        s1[i] = j;
        p1[i] = p[i][j];
      }
      if (p[i][j] > p2[i] && p[i][j] != p1[i]) {
        p2[i] = p[i][j];
        s2[i] = j;
      }
    }
    if (s1[i] != 0) cnt++;
    max_n += p1[i];
  }
  if (cnt == n) {
    cout << max_n << endl;
  } else {
    cout << max_n - p1[0] + p2[0] << endl;
  }
  return 0;
}
