#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);
  int ans = -1000000000;
  for (int i = 1; i < 1024; i++) {
    bool flag[10];
    int tmp0 = i;
    for (int j = 0; j < 10; j++) {
      flag[j] = tmp0 % 2;
      tmp0 /= 2;
    }
    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] == 1 && flag[day * 2 + t] == 1) cnt++;
        }
      }
      money[shop] = profit[shop][cnt];
    }
    sort(money.begin(), money.end(), greater<int>());
    if (money[0] <= 0)
      ans = max(ans, money[0]);
    else {
      int tmp = 0;
      for (int j = 0; j < N; j++) {
        if (money[j] > 0) tmp += money[j];
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
