#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int F[N][5][2];
  int count[N];
  for (int i = 0; i < N; i++) count[i] = 0;
  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];
        if (F[i][j][k] == 1) {
          count[i]++;
        }
      }
    }
  }
  int P[N][11];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 10; j++) cin >> P[i][j];
  }
  int x = 0;
  int z_count = 0;
  int max2 = -100000000;
  for (int i = 0; i < N; i++) {
    int max = -100000000;
    int max_id = 0;
    for (int j = 1; j <= count[i]; j++) {
      if (max < P[i][j]) {
        max = P[i][j];
        max_id = j;
      }
    }
    if (max < P[i][0]) {
      if (max2 < max) max2 = max;
      z_count++;
      max = P[i][0];
    }
    x += max;
  }
  if (z_count == N) x = max2;
  cout << x << "\n";
  return 0;
}
