#include <bits/stdc++.h>
#pragma GCC optimize("O3")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},
                            {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
long long n, f[105][105], cnt[105], ans = -1e18, p[105][105];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 5; j++) {
      cin >> f[i][j] >> f[i][j + 5];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  for (long long mask = 1; mask < (1 << 10); mask++) {
    vector<long long> vec;
    memset(cnt, 0, sizeof(cnt));
    for (long long j = 0; j < 10; j++) {
      if (mask & (1 << j)) {
        for (long long i = 1; i <= n; i++) {
          cnt[i] += f[i][j];
        }
      }
    }
    long long x = 0;
    for (long long i = 1; i <= n; i++) x += p[i][cnt[i]];
    ans = max(ans, x);
  }
  return cout << ans, 0;
}
