#include <bits/stdc++.h>
using namespace std;
int n;
void solve() {
  vector<vector<int> > p;
  vector<int> sum(n);
  int i, j, tag = 0, ans = 0;
  for (i = 0; i < n; i++) {
    vector<int> tmp(11, 0);
    p.push_back(tmp);
  }
  for (i = 0; i < n; i++) {
    int temp = 0;
    for (j = 0; j < 10; j++) {
      int x;
      cin >> x;
      temp += x;
    }
    sum[i] = temp;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 11; j++) cin >> p[i][j];
    if (p[i][0] <= 0) {
      int xtag = 0;
      for (j = 1; j < 11; j++)
        if (p[i][j] >= 0) {
          xtag = 1;
          break;
        }
      if (xtag) tag = 1;
    } else
      tag = 1;
  }
  if (!tag) {
    ans = -1000000000000;
    for (i = 0; i < n; i++) {
      for (j = 2; j < 11; j++) p[i][j] = max(p[i][j], p[i][j - 1]);
      ans = max(ans, p[i][sum[i]]);
    }
  } else {
    for (i = 0; i < n; i++) {
      for (j = 1; j < 11; j++) p[i][j] = max(p[i][j], p[i][j - 1]);
      ans += p[i][sum[i]];
    }
  }
  cout << ans << endl;
}
int main() {
  while (cin >> n) solve();
}
