#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const int INF = 1000000007;
int N;
int Memo[101][5][2];
int P[101][10];
int dfs(int idx, vector<int> C) {
  int ans = 0;
  if (idx == 5) {
    for (int i = 0; i < N; ++i) {
      ans += P[i][C[i]];
    }
    return ans;
  }
  vector<int> D(N);
  for (int i = 0; i < N; ++i) {
    D[i] = C[i];
    if (Memo[i][idx][0]) {
      D[i]++;
    }
  }
  ans = max(ans, dfs(idx + 1, D));
  for (int i = 0; i < N; ++i) {
    D[i] = C[i];
    if (Memo[i][idx][1]) {
      D[i]++;
    }
  }
  ans = max(ans, dfs(idx + 1, D));
  for (int i = 0; i < N; ++i) {
    D[i] = C[i];
    if (Memo[i][idx][0]) {
      D[i]++;
    }
    if (Memo[i][idx][1]) {
      D[i]++;
    }
  }
  ans = max(ans, dfs(idx + 1, D));
  return ans;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 5; ++j) {
      for (int k = 0; k < 2; ++k) {
        cin >> Memo[i][j][k];
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }
  vector<int> B(N, 0);
  int ans = dfs(0, B);
  cout << ans << "\n";
  return 0;
}
