#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007LL;
long long int ar[500056], br[500056];
long long int dp[101];
vector<long long int> pec;
set<long long int> st;
map<long long int, long long int> has;
vector<pair<long long int, long long int> > vp;
long long int maxi;
int stats[201][20];
long long int prof[201][10];
long long int initial[201];
void solve(vector<long long int> vec, int siz, long long int n, int indx) {
  long long int c;
  long long int ans = 0;
  if (vec.size() == siz) {
    for (int j = 1; j <= n; j++) {
      c = 0;
      for (int k = 1; k <= 10; k++) {
        if (vec[k - 1] == stats[j][k] && vec[k - 1] == 1) c++;
      }
      ans += prof[j][c];
    }
    maxi = max(maxi, ans);
    return;
  }
  vec.push_back(1);
  vec.push_back(1);
  solve(vec, siz, n, indx + 2);
  vec.pop_back();
  vec.pop_back();
  vec.push_back(0);
  vec.push_back(1);
  solve(vec, siz, n, indx + 2);
  vec.pop_back();
  vec.pop_back();
  vec.push_back(1);
  vec.push_back(0);
  solve(vec, siz, n, indx + 2);
}
int main() {
  long long int n, p, t, j, a, x, y = 0, k, l, m, z, b, c, e, f, q, s, flag = 0,
                                  sum = 0, res = 0, num, g, h;
  long long int i, u, v, w, ans, maxm = -1, r, minm = 999999999999;
  bool fl = 0;
  long long int d;
  string str;
  maxi = -999999999999999;
  vector<long long int> vec;
  vec.clear();
  for (i = 0; i <= 101; i++) dp[i] = -1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 10; j++) cin >> stats[i][j];
  }
  for (i = 1; i <= n; i++) {
    cin >> prof[i][0];
    for (j = 1; j <= 10; j++) cin >> prof[i][j];
  }
  vec.push_back(1);
  vec.push_back(1);
  solve(vec, 10, n, 2);
  vec.clear();
  vec.push_back(0);
  vec.push_back(1);
  solve(vec, 10, n, 2);
  vec.clear();
  vec.push_back(1);
  vec.push_back(0);
  solve(vec, 10, n, 2);
  cout << maxi;
  return 0;
}
