#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
int a[500][500];
int b[500];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int t;
      scanf("%d", &t);
      b[i] += t;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int maxx = -(int)1e8;
  int sum = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int now = max_element(a[i], a[i] + b[i] + 1) - a[i];
    if (now != 0) {
      flag = 1;
    } else {
      maxx = *max_element(a[i] + 1, a[i] + b[i] + 1) - a[i][now];
    }
    sum += a[i][now];
  }
  if (flag) {
    cout << sum << "\n";
  } else {
    cout << sum + maxx << "\n";
  }
  return 0;
}
