#include <bits/stdc++.h>
using namespace std;
int f[107][11], p[107][12], k[12], s[107];
int main() {
  int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 10; j++) cin >> f[i][j];
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 10; j++) cin >> p[i][j];
  }
  int q, ans = -100000;
  while (k[0] == 0) {
    q = 10;
    while (k[q] == 1) {
      k[q] = 0;
      q--;
    }
    k[q]++;
    bool t = true;
    for (i = 1; i <= 10; i++) {
      if (k[i] == 1) t = false;
    }
    if (t == true) continue;
    for (i = 1; i <= n; i++) {
      s[i] = 0;
      for (j = 1; j <= 10; j++) {
        if (f[i][j] == k[j] && k[j] == 1) s[i]++;
      }
    }
    int maxv = 0;
    for (i = 1; i <= n; i++) maxv += p[i][s[i]];
    if (maxv > ans) {
      ans = maxv;
    }
  }
  cout << ans << endl;
  return 0;
}
