#include <bits/stdc++.h>
using namespace std;
const int MINF = -(1 << 29);
bool f[102][11];
bool k[11];
int p[102][11];
int I;
bool non;
int mem[101][11][11];
int slv2(int ix, int cnt) {
  if (mem[I][ix][cnt] != MINF) return mem[I][ix][cnt];
  if (ix > 10) {
    if (cnt == 0) {
      non = true;
      int tmp = MINF;
      for (int j = (1); j <= (10); ++j) {
        if (f[I][j]) tmp = max(MINF, p[I][j]);
      }
      return tmp;
    }
    return mem[I][ix][cnt] = p[I][cnt];
  }
  int rec = MINF;
  if (f[I][ix] == 1 && f[I][ix + 1] == 1) rec = max(rec, slv2(ix + 2, cnt + 2));
  if (f[I][ix] || f[I][ix + 1]) rec = max(rec, slv2(ix + 2, cnt + 1));
  return mem[I][ix][cnt] = max(rec, slv2(ix + 2, cnt));
}
int main() {
  int n;
  int ans = 0;
  fill_n(**mem, 101 * 11 * 11, MINF);
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (10); ++j) {
      cin >> f[i][j];
      k[j] |= f[i][j];
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (0); j <= (10); ++j) cin >> p[i][j];
  }
  for (int i = (1); i <= (n); ++i) {
    I = i, ans += slv2(1, 0);
    if (non) break;
  }
  if (non) {
    for (int i = (1); i <= (n); ++i) I = i, ans = min(ans, slv2(1, 0));
  }
  cout << (ans) << '\n';
}
