#include <bits/stdc++.h>
using namespace std;
int N;
vector<bitset<10>> f(101);
vector<vector<int>> p(101, vector<int>(11, 0));
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]);
  vector<vector<pair<int, int>>> v(N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= f[i].count(); ++j)
      v[i].push_back(make_pair(p[i][j], j));
    sort(v[i].begin(), v[i].end(), greater<pair<int, int>>());
  }
  int ans = 0, cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (v[i][0].second == 0) ++cnt;
    ans += v[i][0].first;
  }
  if (cnt == N) {
    int ans2 = -INT_MAX;
    for (int i = 0; i < N; ++i)
      ans2 = max(ans2, (ans - v[i][0].first) + v[i][1].first);
    printf("%d\n", ans2);
  } else
    printf("%d\n", ans);
  return 0;
}
