#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9;
const long double eps = 1e-9;
const long double pi = acos(-1);
const long long int mod = 1000000007;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int i, j;
  long long int f[n][15];
  long long int c[n][15];
  long long int ans = 0;
  for (i = 0; i < n; ++i)
    for (j = 0; j < 10; ++j) cin >> f[i][j];
  for (i = 0; i < n; ++i) {
    for (j = 0; j < 11; ++j) {
      cin >> c[i][j];
    }
  }
  bool atleastek = false;
  long long int maxer[n];
  for (i = 0; i < n; ++i) maxer[i] = -inf;
  for (i = 0; i < n; ++i) {
    long long int ct = 0;
    for (j = 0; j < 10; ++j)
      if (f[i][j]) ct++;
    long long int mx = -inf;
    long long int pos = 0;
    for (j = 0; j <= ct; ++j) {
      if (c[i][j] >= mx) {
        mx = c[i][j];
        pos = j;
      }
      if (pos > 0) atleastek = true;
    }
    maxer[i] = mx;
    ans = ans + mx;
  }
  if (atleastek)
    cout << ans << '\n';
  else {
    long long int mxans = -inf;
    for (i = 0; i < n; ++i) {
      long long int ct = 0;
      for (j = 0; j < 10; ++j)
        if (f[i][j]) ct++;
      long long int pos = 0;
      long long int mx = -inf;
      for (j = 1; j <= ct; ++j) mx = max(mx, c[i][j]);
      long long int temp = ans - maxer[i] + mx;
      mxans = max(temp, mxans);
    }
    cout << mxans << '\n';
  }
  return 0;
}
