#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<vector<int>>> f(110, vector<vector<int>>(10, vector<int>(5, 0)));
vector<vector<pair<int, int>>> p(110);
int main(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= 5; ++j)
      for (int k = 1; k <= 2; ++k) scanf("%d", &f[i][j][k]);
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= 10; ++j) {
      int a;
      scanf("%d", &a);
      p[i].push_back(make_pair(a, j));
    }
    sort(p[i].begin(), p[i].end(), greater<pair<int, int>>());
  }
  vector<int> w(N + 1);
  for (int i = 1; i <= N; ++i) {
    int cnt = 0;
    for (int j = 1; j <= 5; ++j)
      for (int k = 1; k <= 2; ++k)
        if (f[i][j][k]) ++cnt;
    w[i] = cnt;
  }
  vector<vector<pair<int, int>>> v(N + 1);
  for (int i = 1; i <= N; ++i) {
    int cnt = 0;
    for (int j = 0; j <= 10; ++j) {
      if (p[i][j].second <= w[i]) v[i].push_back(p[i][j]), ++cnt;
      if (cnt == 2) break;
    }
  }
  int ans = 0, cnt = 0;
  for (int i = 1; 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 = 1; 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;
}
