#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int f_count[n];
  memset(f_count, 0, sizeof(f_count));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 11; ++j) {
      int f;
      cin >> f;
      f_count[i] += f;
    }
  }
  int p[n][11];
  bool run = false;
  ll total_p = 0;
  for (int i = 0; i < n; ++i) {
    int max_p = (int)-1e7;
    for (int j = 0; j <= f_count[i]; ++j) {
      cin >> p[i][j];
      if (max_p <= p[i][j]) {
        max_p = p[i][j];
        run += j > 0;
      }
    }
    for (int j = f_count[i] + 1; j < 11; ++j) {
      cin >> p[i][j];
    }
    total_p += (ll)max_p;
  }
  if (!run) {
    int min_adj = (int)1e7;
    for (int i = 0; i < n; ++i) {
      int adj = (int)-1e7;
      for (int j = 1; j <= f_count[i]; ++j) {
        adj = max(adj, p[i][j]);
      }
      min_adj = min(min_adj, adj - p[i][0]);
    }
    total_p += (ll)min_adj;
  }
  cout << total_p << '\n';
  return 0;
}
