#include <bits/stdc++.h>
using namespace std;
int n, sum, k;
int num[100] = {};
long long int valmax[100] = {};
int search(int m, long long int val) {
  if (m < n)
    return max(search(m + 1, val), search(m + 1, val + valmax[m]));
  else
    return max(val, val + valmax[m]);
}
int main() {
  long long int info[11];
  cin >> n;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < 10; j++) {
      cin >> k;
      sum += k;
    }
    num[i] = sum + 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> info[j];
    }
    valmax[i] = *max_element(&info[1], &info[num[i]]);
  }
  cout << (n == 1 ? valmax[0] : search(1, valmax[0])) << endl;
}
