#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n;
  cin >> n;
  vector<vector<vector<long long> > > f(
      n, vector<vector<long long> >(5, vector<long long>(2, 0)));
  vector<vector<long long> > p(n, vector<long long>(11, 0));
  vector<long long> cnt(n);
  bool flag = false;
  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 >> f[i][j][k];
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long c = 0;
    for (long long j = 0; j < 5; j++) {
      for (long long k = 0; k < 2; k++) {
        if (f[i][j][k] == 1) {
          c++;
        }
      }
    }
    long long m = -1145141919810;
    for (long long j = 0; j <= c; j++) {
      m = max(m, p[i][j]);
    }
    sum += m;
  }
  cout << sum << endl;
  return 0;
}
