#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, ans = -1e7, open, num, sum, minus = 0;
  cin >> N;
  vector<int> NUM(N);
  vector<int> MAX(N, -1e7);
  int P[N][11];
  for (int i = 0; i < N; i++) {
    sum = 0;
    for (int j = 0; j < 10; j++) {
      cin >> open;
      if (open) sum++;
    }
    NUM[i] = sum;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> num;
      P[i][j] = num;
    }
  }
  sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= NUM[i]; j++) {
      if (P[i][j] > MAX[i]) MAX[i] = P[i][j];
    }
    if (MAX[i] > 0) {
      sum += MAX[i];
    } else {
      minus++;
    }
  }
  if (minus == N) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= NUM[i]; j++) {
        if (ans < P[i][j] && P[i][j] < 0) {
          ans = P[i][j];
        }
      }
    }
    cout << ans << endl;
  } else {
    cout << sum << endl;
  }
}
