#include <bits/stdc++.h>
using namespace std;
int n;
int f[100][5][2];
int p[100][10];
int main() {
  bool good = false;
  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];
    }
  }
  int result = 0;
  for (unsigned long ii = 1; ii < 1024; ++ii) {
    int count[100] = {0};
    for (int j = 0; j < 5; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (0 != (1 & (ii >> j * 2 + k))) continue;
        for (int i = 0; i < n; ++i) {
          if (1 == f[i][j][k]) {
            count[i]++;
          }
        }
      }
    }
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += p[i][count[i]];
    }
    if (ii == 1) result = sum;
    result = (result < sum) ? sum : result;
  }
  cout << result << endl;
  return 0;
}
