#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  scanf("%lld", &N);
  long long F[N][5][2];
  long long P[N][11];
  long long cnt[N];
  memset((cnt), 0, sizeof(cnt));
  for (long long i = 0; i < N; ++i) {
    for (long long j = 0; j < 5; ++j) {
      for (long long k = 0; k < 2; ++k) {
        scanf("%lld", &F[i][j][k]);
        cnt[i] += F[i][j][k];
      }
    }
  }
  for (long long i = 0; i < N; ++i) {
    for (long long j = 0; j <= 10; ++j) {
      scanf("%lld", &P[i][j]);
    }
  }
  vector<long long> sol;
  long long PROFIT = 0;
  long long closed = 0;
  for (long long i = 0; i < N; ++i) {
    long long MAX = -1e9;
    for (long long j = 1; j <= cnt[i]; ++j) {
      MAX = max(MAX, P[i][j]);
    }
    if (P[i][0] > MAX) {
      ++closed;
    }
    sol.push_back(max(P[i][0], MAX));
  }
  for (auto it : sol) {
    PROFIT += it;
  }
  if (closed == N) {
    vector<long long> hehe;
    for (long long i = 0; i < N; ++i) {
      long long WHAT = P[i][1];
      for (long long j = 1; j <= cnt[i]; ++j) {
        WHAT = max(WHAT, P[i][j]);
      }
      hehe.push_back(-sol[i] + WHAT);
    }
    cout << PROFIT + *max_element(hehe.begin(), hehe.end()) << endl;
    return 0;
  }
  cout << PROFIT << endl;
  return 0;
}
