#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int f[n][5][2];
  int p[n][11];
  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];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  int profit = 0;
  for (int i = 0; i < n; i++) {
    profit += p[i][0];
  }
  int cnt[n];
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
  }
  vector<int> v;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < 2; l++) {
          if (l == 0) {
            if (f[k][i][j] == 1) {
              profit = profit + p[k][cnt[k] + 1] - p[k][cnt[k]];
              cnt[k]++;
              v.push_back(profit);
            }
          } else {
            v.push_back(profit);
          }
        }
      }
    }
  }
  sort(v.begin(), v.end());
  cout << v.back() << endl;
  return 0;
}
