#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> fv(n, 0);
  for (auto& f : fv) {
    int temp;
    for (int i = 0; i < 10; ++i) {
      cin >> temp;
      f += temp;
    }
  }
  vector<int> cv(n, -100000000);
  for (int i = 0; i < n; ++i) {
    int temp;
    for (int j = 0; j <= 10; ++j) {
      cin >> temp;
      if (j <= fv[i] && cv[i] < temp) {
        cv[i] = temp;
      }
    }
  }
  sort(cv.begin(), cv.end());
  long long ret = 0;
  if (cv[n - 1] <= 0) {
    ret = cv[n - 1];
  } else {
    for (int i = n - 1; 0 <= i; --i) {
      if (0 < cv[i]) {
        ret += cv[i];
      }
    }
  }
  cout << ret << endl;
  return 0;
}
