#include <bits/stdc++.h>
using namespace std;
const long mod = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> open(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      int test;
      cin >> test;
      if (test == 1) {
        open.at(i)++;
      }
    }
  }
  int count = 0;
  vector<int> noshop(N);
  bool shopopen = false;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < 10; j++) {
      int b;
      cin >> b;
      if (j == 0) {
        noshop.at(i) = b;
      }
      if (j < open.at(i)) {
        if (b > a) {
          a = b;
          shopopen = true;
        }
      }
    }
    count += a;
  }
  if (shopopen == false) {
    sort(noshop.begin(), noshop.end());
    ;
    reverse(noshop.begin(), noshop.end());
    ;
    count += noshop.at(0);
  }
  cout << count << endl;
}
