#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::pair;
using std::printf;
using std::sort;
using std::string;
using std::vector;
template <typename T>
void dump(vector<T> vec) {
  for (auto x : vec) {
    std::cout << x << " ";
  }
  std::cout << std::endl;
}
const long long int MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  int tmp;
  vector<vector<int> > shops(N, vector<int>(10, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> tmp;
      shops[i][j] = tmp;
    }
  }
  vector<vector<int> > profits(N, vector<int>(11, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= 10; ++j) {
      cin >> tmp;
      profits[i][j] = tmp;
    }
  }
  vector<int> earn(1024, 0);
  int cnt, tmp_earn;
  for (int guhehe = 1; guhehe <= 1023; ++guhehe) {
    int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
    i0 = (guhehe & (1 << 0)) >> 0;
    i1 = (guhehe & (1 << 1)) >> 1;
    i2 = (guhehe & (1 << 2)) >> 2;
    i3 = (guhehe & (1 << 3)) >> 3;
    i4 = (guhehe & (1 << 4)) >> 4;
    i5 = (guhehe & (1 << 5)) >> 5;
    i6 = (guhehe & (1 << 6)) >> 6;
    i7 = (guhehe & (1 << 7)) >> 7;
    i8 = (guhehe & (1 << 8)) >> 8;
    i9 = (guhehe & (1 << 9)) >> 9;
    tmp_earn = 0;
    for (int n = 0; n < N; ++n) {
      cnt = 0;
      cnt += i0 * shops[n][0];
      cnt += i1 * shops[n][1];
      cnt += i2 * shops[n][2];
      cnt += i3 * shops[n][3];
      cnt += i4 * shops[n][4];
      cnt += i5 * shops[n][5];
      cnt += i6 * shops[n][6];
      cnt += i7 * shops[n][7];
      cnt += i8 * shops[n][8];
      cnt += i9 * shops[n][9];
      tmp_earn += profits[n][cnt];
    }
    earn[guhehe] = tmp_earn;
  }
  int earn_max = earn[1];
  for (int i = 2; i < 1024; ++i) {
    if (earn_max < earn[i]) {
      earn_max = earn[i];
    }
  }
  dump<int>(earn);
  printf("%d\n", earn_max);
}
