#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long arr[n][10];
  long long cnt1[n];
  for (long long i = 0; i < n; i++) {
    long long blah = 0;
    for (long long j = 0; j < 10; j++) {
      cin >> arr[i][j];
      blah += arr[i][j] == 1 ? 1 : 0;
    }
    cnt1[i] = blah;
  }
  long long ans = 0;
  std::vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long index = cnt1[i];
    long long maxi = -1e8;
    long long x;
    for (long long j = 0; j < 11; j++) {
      cin >> x;
      if (j >= 1 && j <= index) maxi = max(maxi, x);
    }
    v.push_back(maxi);
  }
  sort(v.begin(), v.end(), greater<long long>());
  if (v[0] <= 0) {
    cout << v[v.size() - 1] << endl;
  } else {
    long long ans = 0;
    for (long long i = 0; i < v.size(); i++) {
      if (v[i] >= 0) ans += v[i];
    }
    cout << ans << endl;
  }
}
