#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1061109567;
const double EPS = 1e-10;
int main() {
  int N, buf;
  long long x = 0;
  cin >> N;
  int F[N][5][2];
  int P[N][11];
  int max[N];
  int time[N];
  bool flag = false;
  for (int i = 0; i < N; i++) {
    max[i] = 0;
    time[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]) {
          max[i]++;
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    buf = P[i][0];
    for (int j = 0; j <= max[i]; j++) {
      if (P[i][j] > buf) {
        buf = P[i][j];
        time[i] = j;
      }
    }
    x += buf;
  }
  for (int i = 0; i < N; i++) {
    if (time[i] != 0) {
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << x << endl;
    return 0;
  } else {
    x = -INF;
    for (int i = 0; i < N; i++) {
      for (int j = 1; j <= max[i]; j++) {
        if (P[i][j] > x) {
          x = P[i][j];
        }
      }
    }
  }
  cout << x << endl;
  return 0;
}
