#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int f[100][10];
  int p[100][11];
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 10; j++) {
      scanf("%d", &f[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  int c = 0, sum = 0, ans = 0;
  for (int k = 0; k < 10000; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 10; j++) {
        if (f[i][j] == 1) c++;
      }
      sum += p[i][c];
    }
    if (ans < sum) ans = sum;
  }
  printf("%d", sum);
}
