#include <bits/stdc++.h>
using ll = long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(11));
  vector<int> count(n, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> f[i][j];
      if (f[i][j] == 1) ++count[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 10; ++j) cin >> p[i][j];
  }
  int maxv_sub = -10000005;
  vector<int> select(11, 0);
  for (int i = 0; i < n; ++i) {
    int maxv = 0;
    for (int j = 0; j <= count[i]; ++j) {
      if (maxv <= p[i][j]) {
        maxv = p[i][j];
        select[i] = j;
      }
      if (j) maxv_sub = max(maxv_sub, p[i][j]);
    }
    ans += maxv;
  }
  int k = 0;
  for (int i = 0; i < n; ++i) {
    if (select[i] == 0) ++k;
  }
  if (k == n) {
    int minv = 10000005;
    for (int i = 0; i < n; ++i) {
      minv = min(minv, p[i][0]);
    }
    ans += maxv_sub - minv;
  }
  cout << ans << endl;
  return 0;
}
