#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[n][5][2];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> f[i][j][0];
      cin >> f[i][j][1];
    }
  }
  int p[n][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  long long ans = -1;
  long long temp = 0;
  vector<int> count(n, 0);
  int target;
  for (int i = 1; i < 1 << 10; i++) {
    for (int j = 0; j < 5; j++) {
      target = i >> 2 * j;
      if (target % 2 == 1) {
        for (int i = 0; i < n; i++) {
          if (f[i][j][0] == 1) {
            count[i]++;
          }
        }
      }
      if ((target % 4) >= 2) {
        for (int i = 0; i < n; i++) {
          if (f[i][j][1] == 1) {
            count[i]++;
          }
        }
      }
    }
    for (int k = 0; k < n; k++) {
      temp += p[k][count[k]];
    }
    ans = max(ans, temp);
    temp = 0;
    for (int k = 0; k < n; k++) {
      count[k] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
