#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int f[105];
int p[105][15];
int main() {
  int n, a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++) {
      scanf("%d", &a);
      f[i] += a;
    }
  }
  int ma = -1e7 + 7;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  long long ans = 0;
  int st = 0;
  for (int i = 1; i <= n; i++) {
    ma = -1e7 + 7;
    for (int j = 0; j <= f[i]; j++) {
      if (p[i][j] > ma) {
        ma = p[i][j];
        st = max(j, st);
      }
    }
    ans += ma;
  }
  if (st != 0)
    cout << ans << endl;
  else {
    int en = 0;
    ma = -1e7 + 7;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= f[i]; j++) {
        if (p[i][j] > ma) {
          ma = p[i][j];
          st = i;
          en = j;
        }
      }
    }
    ans = ans - p[st][0] + ma;
    cout << ans << endl;
  }
  return 0;
}
