#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const long long INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const long long MODLL = (long long)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int n;
  cin >> n;
  vector<vector<vector<int> > > f(n,
                                  vector<vector<int> >(5, vector<int>(2, 0)));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> f[i][j][k];
      }
    }
  }
  vector<vector<int> > p(n, vector<int>(11));
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (11); ++j) cin >> p[i][j];
  int m = 10;
  int res = -INF;
  for (int s = 1; s < (1 << m); s++) {
    vector<int> sum(n, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (s & (1 << j)) {
          sum[i] += f[i][j / 2][j % 2];
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += p[i][sum[i]];
    }
    res = max(res, ans);
  }
  cout << res << endl;
  return 0;
}
