#include <bits/stdc++.h>
using namespace std;
long long dy[4] = {1, 0, -1, 0};
long long dx[4] = {0, 1, 0, -1};
int32_t main() {
  long long n, v;
  cin >> n;
  vector<long long> t(n, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) {
      for (long long k = 0; k < 2; k++) {
        cin >> v;
        if (v == 1) {
          t[i]++;
        }
      }
    }
  }
  long long ans = 0, ma = -99999999999, a;
  bool f = false;
  for (long long i = 0; i < n; i++) {
    long long m = -99999999999;
    for (long long j = 0; j < 11; j++) {
      cin >> a;
      if (j <= t[i]) {
        if (m <= a) {
          m = a;
          if (j != 0) {
            f = true;
          }
        }
        if (j != 0) {
          ma = max(ma, a);
        }
      }
    }
    ans += m;
  }
  if (!f) {
    ans += ma;
  }
  cout << ans << endl;
}
