#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll a[110];
ll a1[110][12];
int getidx[110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      int t;
      cin >> t;
      if (t) a[i]++;
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> a1[i][j];
    }
  }
  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    ll value = -10000000;
    for (int j = 0; j <= a[i]; ++j) {
      if (value < a1[i][j]) {
        value = max(value, a1[i][j]);
        getidx[i] = j;
      }
    }
    sum += value;
  }
  bool flag = false;
  for (int i = 0; i < N; ++i) {
    if (getidx[i] != 0) flag = true;
  }
  if (flag)
    cout << sum << endl;
  else {
    ll maxV = -1000000;
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j <= a[i]; ++j) {
        maxV = max(maxV, a1[i][j]);
      }
    }
    cout << maxV << endl;
  }
  return 0;
}
