#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> freq_max(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      freq_max[i] += tmp;
    }
  }
  vector<vector<int>> profits(n);
  vector<int> profits_max(n, -1e9);
  for (int i = 0; i < n; i++) profits[i] = vector<int>();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      int tmp = 0;
      cin >> tmp;
      if (j <= freq_max[i]) {
        profits[i].push_back(tmp);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < profits[i].size(); j++) {
      profits_max[i] =
          profits[i][j] > profits_max[i] ? profits[i][j] : profits_max[i];
    }
  }
  bool profits_zero = false;
  for (int i = 0; i < n; i++) {
    if (profits_max[i] == profits[i][0]) {
      profits_zero = true;
    }
  }
  if (profits_zero) {
    for (int i = 0; i < n; i++) {
      profits[i][0] = -1e9;
      profits_max[i] = -1e9;
      for (int j = 0; j < profits[i].size(); j++) {
        profits_max[i] =
            profits[i][j] > profits_max[i] ? profits[i][j] : profits_max[i];
      }
    }
  }
  sort(profits_max.begin(), profits_max.end());
  long long acc = profits_max[0];
  for (int i = 1; i < n; i++) {
    acc += profits_max[i] + acc >= profits_max[i] ? profits_max[i] : 0;
  }
  cout << acc << endl;
  return 0;
}
