#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> v_t;
vector<vector<long long int>> v_p;
long long int dfs(int depth, long long int kaitenlist[], int N) {
  if (depth == 10) {
    int check = 0;
    for (int i = 0; i < 10; i++) {
      check += kaitenlist[i];
    }
    if (check == 0) return -1e7;
    long long int res = 0;
    for (int i = 0; i < N; i++) {
      check = 0;
      for (int j = 0; j < 10; j++) {
        check += kaitenlist[j] * v_t.at(i)[j];
      }
      res += v_p.at(i)[check];
    }
    return res;
  }
  kaitenlist[depth] = 1;
  long long int ret1 = dfs(depth + 1, kaitenlist, N);
  kaitenlist[depth] = 0;
  long long int ret2 = dfs(depth + 1, kaitenlist, N);
  return max(ret1, ret2);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<long long int> v;
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    v_t.push_back(v);
  }
  for (int i = 0; i < n; i++) {
    vector<long long int> v;
    for (int j = 0; j <= 10; j++) {
      int tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    v_p.push_back(v);
  }
  long long int list[10] = {};
  std::cout << dfs(0, list, n) << endl;
}
