#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, close = 0, MIN = 1e9, sec = -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;
  }
  open = 0;
  for (int(i) = 0; (i) < (N); ++(i)) {
    int MAX = 0;
    for (int(j) = 0; (j) < (11); ++(j)) {
      cin >> value;
      if (j > v[i]) continue;
      if (MAX <= value) {
        MAX = value;
        if (!!j) ++open;
      }
      if (!j) MIN = min(MIN, value);
      if (!!j) sec = max(sec, value);
    }
    ans += MAX;
  }
  if (!open) ans += sec - MIN;
  cout << (ans) << endl;
  ;
}
