#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int c[N], p[N][11];
void solve() {
  int n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int x;
      cin >> x;
      if (x) c[i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) cin >> p[i][j];
    if (c[i] == 0)
      res += p[i][0];
    else {
      int x = -2e7;
      for (int j = 1; j <= c[i]; j++) x = max(x, p[i][j]);
      if (res == 0 || x > 0)
        res += x;
      else if (res < 0 && x > res)
        res = x;
    }
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
