#include <bits/stdc++.h>
using namespace std;
const int nax = 100;
int N;
int cnt_ones[nax];
int P[nax][11];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      int x;
      cin >> x;
      if (x) ++cnt_ones[i];
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= 10; ++j) {
      cin >> P[i][j];
    }
  }
  long long res = 0;
  int flag = 0;
  for (int i = 0; i < N; ++i) {
    long long r = -INT_MAX;
    int ff = 0;
    for (int j = 0; j <= cnt_ones[i]; ++j) {
      if (P[i][j] > r) ff = j;
      r = max(r, (long long)P[i][j]);
    }
    if (ff == 0) ++flag;
    res = max(res, r + res);
  }
  if (flag == N) {
    res = -INT_MAX;
    for (int i = 0; i < N; ++i) {
      long long r = -INT_MAX;
      for (int j = 1; j <= cnt_ones[i]; ++j) {
        r = max(r, (long long)P[i][j]);
      }
      res = max(res, r);
    }
  }
  cout << res << "\n";
  return 0;
}
