#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, q, sum, mx, a[11];
int p[107][12];
bool f[11], bar;
vector<pair<int, int> > v;
int main() {
  cin >> n;
  for (j = 1; j <= n; j++) {
    k = 0;
    for (i = 1; i <= 10; i++) {
      cin >> f[i];
      if (f[i]) k++;
    }
    a[j] = k;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 10; j++) cin >> p[i][j];
  }
  for (i = 1; i <= n; i++) {
    mx = INT_MIN;
    for (j = 0; j <= a[i]; j++) {
      mx = max(mx, (long long)p[i][j]);
    }
    if (mx == p[i][0]) {
      k = mx;
      mx = INT_MIN;
      for (j = 1; j <= a[i]; j++) mx = max(mx, (long long)p[i][j]);
      v.push_back(make_pair(k, mx));
    } else
      sum += mx;
  }
  int mn = INT_MAX, mni;
  for (i = 0; i < v.size(); i++) {
    if (v[i].second < mn) {
      mn = v[i].second;
      mni = i;
    }
  }
  for (i = 0; i < v.size(); i++) {
    if (mni == i)
      sum += v[i].first;
    else
      sum += v[i].second;
  }
  cout << sum;
}
