#include <bits/stdc++.h>
using namespace std;
int open[10] = {0};
int N;
int F[100][5][2], P[100][11], cnt[100] = {0};
unsigned long long max_bene = -10000000000;
void cal(int n) {
  if (n < 10) {
    open[n] = 0;
    cal(n + 1);
    open[n] = 1;
    cal(n + 1);
  } else {
    int benefit = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 5; j++) {
        if (open[2 * j] && F[i][j][0]) ++cnt[i];
        if (open[2 * j + 1] && F[i][j][1]) ++cnt[i];
      }
    }
    for (int i = 0; i < N; i++) {
      benefit += P[i][cnt[i]];
    }
    int flag = 0;
    for (int i = 0; i < 10; i++) {
      if (open[i]) flag = 1;
    }
    if ((max_bene < benefit) && flag) max_bene = benefit;
    for (int i = 0; i < N; i++) cnt[i] = 0;
  }
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  cal(0);
  cout << max_bene << endl;
  return 0;
}
