#include <bits/stdc++.h>
using namespace std;
const int N = 1000060;
const int mod = (int)1e9 + 7;
const int MX = 1000020;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  int f[n][5][2];
  int lim[n];
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    for (int j = 0; j < 5; ++j) {
      for (int k = 0; k < 2; ++k) {
        cin >> f[i][j][k];
        if (f[i][j][k] == 1) cnt++;
      }
    }
    lim[i] = cnt;
  }
  int res = 0;
  bool ok = 0;
  int mx[n];
  fill_n(mx, n, -1e9);
  int p[n][11];
  for (int i = 0; i < n; ++i) {
    int bst = -1e9;
    int bst_day = -1;
    for (int j = 0, x; j <= 10; ++j) {
      cin >> p[i][j];
      x = p[i][j];
      if (j <= lim[i]) {
        if (x >= bst) {
          bst = x;
          bst_day = j;
        }
        if (j > 0) mx[i] = max(mx[i], x);
      }
    }
    if (bst_day != 0) ok = true;
    res += bst;
  }
  if (ok)
    cout << res << endl;
  else {
    int RES = -1e9;
    for (int i = 0; i < n; ++i) {
      RES = max(res - p[i][0] + mx[i], RES);
    }
    cout << RES << endl;
  }
  return 0;
}
