#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  bool F[N][5][2];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> F[i][j][0] >> F[i][j][1];
    }
  }
  int profit[N][11];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> profit[i][j];
    }
  }
  vector<int> money(N);
  for (int shop = 0; shop < N; shop++) {
    int cnt = 0;
    for (int day = 0; day < 5; day++) {
      for (int t = 0; t < 2; t++) {
        if (F[shop][day][t]) cnt++;
      }
    }
    money[shop] = profit[shop][cnt];
  }
  sort(money.begin(), money.end(), greater<int>());
  if (money[0] <= 0)
    cout << money[0] << endl;
  else {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (money[i] > 0) ans += money[i];
    }
    cout << ans << endl;
  }
  return 0;
}
