#include <bits/stdc++.h>
const int INF = 0x7fffffff;
using namespace std;
int f[100 + 5];
int p[100 + 5][10 + 5];
long long mx[100 + 5][3];
int sit[100 + 5][3];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int t = 0;
    for (int j = 1; j <= 10; j++) {
      int x;
      scanf("%d", &x);
      if (x == 1) t++;
    }
    f[i] = t;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    long long mx1 = -INF, mx2 = -INF;
    int sit1 = 0, sit2 = 0;
    for (int j = 0; j <= f[i]; j++) {
      if (p[i][j] > mx1) {
        mx2 = mx1;
        sit2 = sit1;
        mx1 = p[i][j];
        sit1 = j;
      } else if (p[i][j] > mx2) {
        mx2 = p[i][j];
        sit2 = j;
      }
    }
    mx[i][0] = mx1;
    sit[i][0] = sit1;
    if (mx2 != -INF) {
      mx[i][1] = mx2;
      sit[i][1] = sit2;
    }
  }
  long long ans = 0, tot = 0;
  for (int j = 1; j <= n; j++) {
    ans += mx[j][0];
    tot += sit[j][0];
  }
  if (tot != 0) {
    printf("%lld", ans);
  } else {
    long long change = -mx[1][0] + mx[1][1];
    for (int i = 2; i <= n; i++) {
      if (mx[i][1] - mx[i][0] < change) {
        change = mx[i][1] - mx[i][0];
      }
    }
    printf("%lld", ans + change);
  }
  return 0;
}
