#include <bits/stdc++.h>
using namespace std;
int res;
void dfs(int d, vector<int>& now, vector<vector<int> >& F,
         vector<vector<int> >& P, bool used) {
  if (d == 10) {
    if (used) {
      int score = 0;
      for (int i = 0; i < (int)now.size(); ++i) {
        score += P[i][now[i]];
      }
      res = max(score, res);
    }
    return;
  }
  vector<int> temp = now;
  for (int i = 0; i < (int)now.size(); ++i) {
    temp[i] += F[i][d];
  }
  dfs(d + 1, now, F, P, used);
  dfs(d + 1, temp, F, P, true);
}
int main(void) {
  int N;
  cin >> N;
  vector<vector<int> > F(N, vector<int>(10));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> F[i][j];
    }
  }
  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];
    }
  }
  vector<int> now(N, 0);
  res = -(1 << 28);
  dfs(0, now, F, P, false);
  cout << res << endl;
  return 0;
}
