#include <bits/stdc++.h>
using namespace std;
int a[1000][5][2];
int b[1000][10];
int n;
long long dp[100][2];
long long f(int i, int x) {
  if (i == n)
    if (x == 1)
      return 0;
    else
      return -1e9;
  if (dp[i][x] != -1) return dp[i][x];
  long long sol;
  if (!x) {
    sol = b[i][1] + f(i + 1, 1);
    sol = max(sol, b[i][0] + f(i + 1, 0));
  } else
    sol = b[i][0] + f(i + 1, 1);
  int c = 0;
  for (int j = 0; j < 5; ++j)
    for (int k = 0; k < 2; ++k) {
      if (a[i][j][k] == 1) {
        c++;
      }
    }
  for (int j = 1; j <= c; ++j) {
    sol = max(sol, b[i][j] + f(i + 1, 1));
  }
  return dp[i][x] = 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));
  cout << f(0, 0);
  return 0;
}
