#include <bits/stdc++.h>
using namespace std;
int F[100][5][2];
int P[100][11];
int main(void) {
  int n;
  vector<int> cost;
  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 <= 10; j++) {
      cin >> P[i][j];
    }
  }
  long long sum = 0;
  int m = -1e9;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    long long temp = P[i][0];
    int count = 0;
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        if (F[i][j][k] == 1) {
          if (temp < P[i][++count]) {
            temp = P[i][count];
            flag = true;
          }
        }
      }
    }
    m = max(P[i][1], m);
    sum += temp;
  }
  if (flag) {
    cout << sum << endl;
  } else {
    cout << m << endl;
  }
  return 0;
}
