#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
int main() {
  int N, open, value;
  int neg = -INF;
  cin >> N;
  vector<int> v(N);
  ll ans = 0;
  for (int(i) = 0; (i) < (N); ++(i)) {
    int cnt = 0;
    for (int(j) = 0; (j) < (10); ++(j)) {
      cin >> open;
      open ? ++cnt : 0;
    }
    v[i] = cnt;
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    int MAX = 0;
    for (int(j) = 0; (j) < (11); ++(j)) {
      cin >> value;
      if (j > v[i]) continue;
      MAX = max(MAX, value);
      if (value < 1 && j != 0) neg = max(neg, value);
    }
    ans += MAX;
  }
  if (!ans) ans = neg;
  cout << (ans) << endl;
  ;
}
