#include <bits/stdc++.h>
long long int N;
long long int F[123][6][3];
long long int P[12];
long long int buf;
long long int Sum[6][3] = {0};
long long int ans = 0, max = -1145141919810;
int main() {
  std::cin >> N;
  for (int a = 0; a < N; ++a)
    for (int b = 0; b < 5; ++b)
      for (int c = 0; c < 2; ++c) {
        std::cin >> F[a][b][c];
        Sum[b][c] += F[a][b][c];
      }
  for (int a = 0; a < N; ++a) {
    for (int b = 0; b < 11; ++b) {
      std::cin >> buf;
      P[b] += buf;
    }
  }
  for (int a = 0; a < 11; ++a) {
    for (int b = 0; b < 5; ++b)
      for (int c = 0; c < 2; ++c) {
        ans += std::max(0LL, P[Sum[b][c]]);
        max = std::max(max, P[Sum[b][c]]);
      }
  }
  if (ans == 0) ans = max;
  printf("%lld\n", ans);
  return 0;
}
