#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);
  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;
  long long c = 0;
  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++) {
        if (f[i][j][k] == 1) {
          c++;
        }
      }
    }
    cnt[i] = c;
    long long p_max = -1145141919810;
    if (!flag) {
      for (long long j = 1; j <= c; j++) {
        p_max = max(p[i][j], p_max);
      }
      flag = true;
    } else {
      for (long long j = 0; j <= c; j++) {
        p_max = max(p[i][j], p_max);
      }
    }
    sum += p_max;
  }
  cout << sum << endl;
  return 0;
}
