#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<vector<int>>> f(n, vector<vector<int>>(5, vector<int>(2, 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];
      }
    }
  }
  vector<vector<int>> p(n, vector<int>(11, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  vector<vector<int>> joif(5, vector<int>(2, 0));
  int maxtotal = -1000000;
  for (int i = 1; i < 1024; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        if ((i & (1 << (k * 5 + j)))) {
          joif[j][k] = 1;
        } else {
          joif[j][k] = 0;
        }
      }
    }
    int totalcount = 0;
    for (int ii = 0; ii < n; ii++) {
      int counter = 0;
      for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 2; k++) {
          if (joif[j][k] == f[ii][j][k] && joif[j][k] == 1) {
            counter++;
          }
        }
      }
      totalcount += p[ii][counter];
    }
    maxtotal = max(maxtotal, totalcount);
  }
  cout << maxtotal << endl;
}
