#include <bits/stdc++.h>
using namespace std;
int dfs(vector<int> &v, int a) {
  int tmp;
  for (int i = 1; i <= 3; i++) {
    tmp = a;
    tmp *= 10;
    tmp += i;
    if (tmp >= 11111) {
      v.push_back(tmp);
    } else {
      dfs(v, tmp);
    }
  }
}
int main(void) {
  int n;
  cin >> n;
  vector<vector<int> > v(n, vector<int>(10, 0)), p(n, vector<int>(11, 0));
  int tmp;
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (10); (j)++) {
      cin >> tmp;
      v[i][j] = tmp;
    }
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (11); (j)++) {
      cin >> tmp;
      p[i][j] = tmp;
    }
  }
  bool flg;
  int res = INT_MIN, value;
  vector<int> lst;
  vector<int> ncnt(n, 0);
  dfs(lst, 0);
  int e;
  int amari;
  for (int(i) = 0; (i) < (lst.size()); (i)++) {
    e = lst[i];
    value = 0;
    for (int(j) = 0; (j) < (5); (j)++) {
      amari = e % 10;
      e = e / 10;
      for (int(k) = 0; (k) < (n); (k)++) {
        if (amari == 3)
          ncnt[k] += v[k][2 * j] + v[k][2 * j + 1];
        else if (amari == 2)
          ncnt[k] += v[k][2 * j];
        else
          ncnt[k] += v[k][2 * j + 1];
      }
    }
    for (int(j) = 0; (j) < (n); (j)++) {
      value += p[j][ncnt[j]];
    }
    if (value >= res) res = value;
    ncnt.clear();
    ncnt = vector<int>(n, 0);
  }
  cout << res << endl;
  return 0;
}
