#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int f[n][10], p[n][11];
  int count[n];
  int ans = 0;
  int check, use;
  int a = 0;
  for (int i = 0; i < n; i++) {
    count[i] = 0;
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
      if (f[i][j] == 1) count[i]++;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++) cin >> p[i][j];
  for (int i = 0; i < n; i++) {
    int check = -1000000000;
    use = 0;
    for (int j = 0; j <= count[i]; j++) {
      if (check < max(check, p[i][j])) use = j;
      check = max(check, p[i][j]);
    }
    ans += check;
    a += use;
  }
  if (a > 0)
    cout << ans << endl;
  else if (a == 0) {
    ans = -1000000000;
    for (int i = 0; i < n; i++)
      for (int j = 1; j <= count[i]; j++) ans = max(ans, p[i][j]);
    cout << ans << endl;
  }
  return 0;
}
