#include <bits/stdc++.h>
using namespace std;
int resolve(int schedule[], int n, int f[][5][2], int p[][10], int index);
int main() {
  int n;
  cin >> n;
  int f[n][5][2];
  int p[n][10];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> p[i][j];
    }
  }
  int schedule[10];
  int max;
  max = resolve(schedule, n, f, p, 0);
  cout << max << endl;
}
int resolve(int schedule[], int n, int f[][5][2], int p[][10], int index) {
  if (index == 10) {
    int o_c = 0;
    for (int i = 0; i < 10; i++) {
      o_c += schedule[i];
    }
    if (o_c == 0) {
      return -10e7 * n;
    }
    int rev = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (schedule[j] == 1 && f[i][j / 2][j % 2] == 1) {
          cnt++;
        }
      }
      if (cnt > 0) {
        rev += p[i][cnt - 1];
      }
    }
    return rev;
  }
  int rev0, rev1;
  schedule[index] = 0;
  rev0 = resolve(schedule, n, f, p, index + 1);
  schedule[index] = 1;
  rev1 = resolve(schedule, n, f, p, index + 1);
  return (rev0 > rev1) ? rev0 : rev1;
}
