#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int n, f[100], p[100][10], a, m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    f[i] = 0;
    for (int j = 0; j < 5; j++) {
      scanf("%d %d", &m, &a);
      f[i] = (f[i] << 1) + m;
      f[i] = (f[i] << 1) + a;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  int k = 1024;
  int l;
  int profit;
  int ans = -10000000;
  int temp;
  int c;
  for (int i = 1; i < k; i++) {
    profit = 0;
    for (int j = 0; j < n; j++) {
      c = 0;
      temp = f[j];
      temp = temp & i;
      while (temp > 0) {
        c += temp % 2;
        temp /= 2;
      }
      profit += p[j][c];
    }
    ans = (profit > ans ? profit : ans);
  }
  printf("%d\n", ans);
  return 0;
}
