#include <bits/stdc++.h>
using namespace std;
int main() {
  int max_total = 0;
  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  vector<vector<int>> P(N, vector<int>(10));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F.at(i).at(j);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> P.at(i).at(j);
    }
  }
  for (int n = 1; n <= 1023; n++) {
    vector<char> T;
    while (n > 0) {
      T.push_back('0' + n % 2);
      n /= 2;
    }
    for (int i = 0; i <= 10 - T.size(); i++) {
      T.push_back('0');
    }
    reverse(T.begin(), T.end());
    vector<int> S;
    for (int i = 0; i < T.size(); i++) {
      S.at(i) = T.at(i) - '0';
    }
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
        if (S.at(j) == F.at(i).at(j)) {
          C[i]++;
        }
      }
    }
    int total = 0;
    for (int i = 0; i < N; i++) {
      total += P.at(i).at(C[i]);
    }
    max_total = max(max_total, total);
  }
  cout << max_total << endl;
  return 0;
}
