#include <bits/stdc++.h>
using namespace std;
int N;
vector<bitset<10>> f(101);
vector<vector<int>> p(101, vector<int>(11, 0));
bitset<10> bit;
int ans = -INT_MAX;
void rec(int cnt = 0) {
  if (cnt == N) {
    if (!bit.count()) return;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
      if (!bit[i]) {
        sum += p[i][0];
        continue;
      }
      sum += *max_element(p[i].begin() + 1, p[i].begin() + f[i].count() + 1);
    }
    ans = max(ans, sum);
    return;
  }
  bit[cnt] = true;
  rec(cnt + 1);
  bit[cnt] = false;
  rec(cnt + 1);
  return;
}
int main(void) {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 10; ++j) {
      int a;
      scanf("%d", &a);
      f[i][j] = a;
    }
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 11; ++j) scanf("%d", &p[i][j]);
  rec();
  printf("%d\n", ans);
  return 0;
}
