#include <bits/stdc++.h>
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long int;
const int MOD = 1000000007;
const int INTMAX = 1001001000;
const ll LLMAX = 1010010010010010000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<vector<vector<ll> > > F(N, vector<vector<ll> >(5, vector<ll>(2)));
  for (ll i = 0; i < N; i++)
    for (ll j = 0; j < 5; j++) cin >> F[i][j][0] >> F[i][j][1];
  vector<vector<ll> > P(N, vector<ll>(10));
  for (ll i = 0; i < N; i++)
    for (ll j = 0; j < 10; j++) cin >> P[i][j];
  ll ans = -LLMAX;
  for (ll i = 1; i < pow(2, 10); i++) {
    bool J[5][2];
    ll ii = i;
    for (ll k = 0; k < 5; k++) {
      for (ll j = 0; j < 2; j++) {
        if (ii % 2 == 0)
          J[k][j] = false;
        else
          J[k][j] = true;
        ii /= 2;
      }
    }
    vector<ll> count(N, 0);
    for (ll j = 0; j < N; j++) {
      for (ll k = 0; k < 5; k++) {
        for (ll l = 0; l < 2; l++) {
          if (F[j][k][l] == 1 && J[k][l] == 1) {
            count[j]++;
          }
        }
      }
    }
    ll sum = 0;
    for (ll j = 0; j < N; j++) {
      sum += P[j][count[j]];
    }
    chmax(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
