#include <bits/stdc++.h>
using namespace std;
bool F[100][10] = {};
long long P[100][11] = {};
int getMatchNum(int n, int i) {
  int num = 0;
  int d = 0;
  while (i) {
    if (i % 2 == 1 && F[n][d]) {
      num++;
    }
    i = i >> 1;
    d++;
  }
  return num;
}
int main() {
  int N;
  cin >> N;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  long long maxV = -1 << 30;
  for (int i = 1; i < 1 << 10; i++) {
    long long margin = 0;
    for (long long n = 0; n < N; n++) {
      long long m = getMatchNum(n, i);
      margin += P[n][m];
    }
    cout << margin << endl;
    maxV = max(maxV, margin);
  }
  cout << maxV << endl;
  return 0;
}
