#include <bits/stdc++.h>
double pi = acos(-1);
const long long mod = 1000000007;
using namespace std;
void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long N = 1000005;
long long fact[N], invfact[N];
long long power(long long x, long long y) {
  if (y <= 0) return 1LL;
  long long z = power(x, y / 2);
  if (y % 2) return (((z * z) % mod) * x) % mod;
  return (z * z) % mod;
}
void pre() {
  fact[0] = invfact[0] = invfact[1] = fact[1] = 1;
  for (long long i = 2; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;
  for (long long i = 2; i < N; i++)
    invfact[i] = (invfact[i - 1] * power(i, mod - 2)) % mod;
}
long long nCr(long long n, long long k) {
  return (((fact[n] * invfact[n - k]) % mod) * invfact[k]) % mod;
}
const long long N1 = 1e6 + 1;
vector<long long> isprime(N1, 1), prime;
void seive() {
  for (long long i = 2; i < sqrt(N1) + 1; i++) {
    if (isprime[i]) {
      for (long long j = i * i; j < N1; j += i) isprime[j] = 0;
      prime.push_back(i);
    }
  }
  for (long long i = sqrt(N1) + 1; i < N1; i++)
    if (isprime[i]) prime.push_back(i);
}
struct dsu {
  vector<long long> par, rank;
  dsu(long long n) : par(n + 1), rank(n + 1) {
    for (long long i = 0; i <= n; i++) {
      par[i] = i;
      rank[i] = 1;
    }
  }
  long long root(long long a) {
    if (a == par[a]) return a;
    return par[a] = root(par[a]);
  }
  void merge(long long a, long long b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (rank[a] > rank[b]) swap(a, b);
    par[b] = a;
  }
  set<long long> parent(long long n) {
    set<long long> s;
    for (long long i = 1; i <= n; i++) {
      s.insert(root(i));
    }
    return s;
  }
};
void solve() {
  long long n;
  cin >> n;
  long long f[n + 1][6][3], p[n + 1][11];
  long long a[n + 1];
  for (long long i = 1; i < n + 1; i++) {
    long long cnt = 0;
    for (long long j = 1; j < 6; j++)
      for (long long k = 1; k < 3; k++) {
        cin >> f[i][j][k];
        if (f[i][j][k]) cnt++;
      }
    a[i] = cnt;
  }
  long long sum = 0, cnt = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < 11; j++) cin >> p[i][j];
    long long mx = INT_MIN, cnt2 = 0;
    for (long long j = 0; j < a[i] + 1; j++) {
      if (mx <= p[i][j]) {
        mx = p[i][j];
        cnt2 = max(cnt2, j);
      }
    }
    cnt += cnt2;
    sum += 1LL * mx;
  }
  if (cnt != 0) {
    cout << sum << endl;
    return;
  }
  sum = INT_MIN;
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < a[i] + 1; j++) sum = max(sum, 1LL * p[i][j]);
  cout << sum << endl;
}
int main() {
  optimizeIO();
  long long r = 1;
  { solve(); }
}
