#include <bits/stdc++.h>
using namespace std;
bool isOpen;
int n, ans;
vector<int> opens, res, zero;
int main() {
  cin >> n;
  opens.resize(n);
  res.resize(n, -1e9);
  zero.resize(n);
  for (int i = 0; i < n; i++) {
    int open;
    for (int j = 0; j < 10; j++) {
      cin >> open;
      opens[i] += open;
    }
  }
  for (int i = 0; i < n; i++) {
    int cur = opens[i], price;
    cin >> price;
    zero[i] = price;
    for (int j = 0; j < 10; j++) {
      cin >> price;
      if (j < cur) {
        res[i] = max(price, res[i]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (zero[i] > res[i]) {
      ans += zero[i];
    } else {
      ans += res[i];
      isOpen = 1;
    }
  }
  if (!isOpen) {
    sort(zero.begin(), zero.end());
    sort(res.begin(), res.end());
    reverse(res.begin(), res.end());
    ans -= zero[0];
    ans += res[0];
  }
  cout << ans << endl;
}
