#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int F[201][11], n[201] = {0};
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= 10; j++) {
      cin >> F[i][j];
      if (F[i][j] == 1) n[i]++;
    }
  }
  int P[201][11];
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> P[i][j];
    }
  }
  int out = 0, z = 0;
  for (int i = 1; i <= N; i++) {
    int ma = -10000000, ma1 = -10000000, ind = 0;
    for (int j = 0; j <= n[i]; j++) {
      if (ma < P[i][j]) {
        ma = P[i][j];
        ind = j;
      }
    }
    if (ind == 0) z++;
    out += ma;
  }
  if (z == N) {
    int ma = -10000000, ma1 = -10000000, ind = 0, indd = 0;
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= n[i]; j++) {
        if (ma < P[i][j]) {
          ma = P[i][j];
          ind = i;
          indd = j;
        }
      }
    }
    out = out + ma - P[ind][0];
  }
  cout << out << endl;
  return 0;
}
