#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
int main(void) {
  long long int N;
  cin >> N;
  long long int F[N][5][2];
  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];
      }
    }
  }
  long long int P[N][11];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }
  long long int value = -(1ll << 60);
  for (int i = 1; i < 1024; ++i) {
    long long int o[10];
    for (int j = 0; j < 10; ++j) {
      o[j] = (i & (1 << j)) > 0 ? 1 : 0;
    }
    long long int count[N];
    for (int j = 0; j < N; ++j) {
      count[j] = 0;
    }
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < 10; ++k) {
        count[j] += o[k] * F[j][k / 2][k % 2];
      }
    }
    long long int tempValue = 0;
    for (int j = 0; j < N; ++j) {
      tempValue += P[j][count[j]];
    }
    value = max(tempValue, value);
  }
  cout << value << endl;
  return 0;
}
