#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> F(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      F[i] += tmp;
    }
  }
  vector<vector<int>> P(n, vector<int>(11));
  int zeroMinIndex = 0;
  int zeroMin = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> P[i][j];
      if (j == 0 && F[i] > 0) {
        if (zeroMin > P[i][j]) {
          zeroMin = P[i][j];
          zeroMinIndex = i;
        }
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int mx = INT_MAX * -1;
    for (int j = 0; j <= F[i]; j++) {
      if (j == 0 && i == zeroMinIndex) continue;
      mx = max(mx, P[i][j]);
    }
    sum += mx;
  }
  cout << sum << endl;
}
