#include <bits/stdc++.h>
using namespace std;
int a[1000][5][2];
int b[1000][10];
int n;
long long dp[100][11][11];
long long f(int i, int x, int y) {
  if (i == n) return 0;
  if (dp[i][x][y] != -1) return dp[i][x][y];
  long long sol;
  int c = 0;
  for (int j = 0; j < 5; ++j)
    for (int k = 0; k < 2; ++k) {
      if (a[i][j][k] == 1 && j * 2 + k >= x && j * 2 + k <= y) {
        c++;
      }
    }
  sol = b[i][c] + f(i + 1, x, y);
  return dp[i][x][y] = sol;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 5; ++j)
      for (int k = 0; k < 2; ++k) cin >> a[i][j][k];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 11; ++j) cin >> b[i][j];
  memset(dp, -1, sizeof(dp));
  long long sol = -1e9;
  for (int i = 0; i <= 9; ++i)
    for (int j = i; j <= 9; ++j) sol = max(sol, f(0, i, j));
  cout << sol;
  return 0;
}
