#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100 + 10;
int open[SIZE] = {0};
int profits[SIZE][11] = {0};
bool p0max[SIZE];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  int t;
  int res1 = -1e8;
  int res = 0;
  int temp;
  bool noopen = true;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> t;
      open[i] += t;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> profits[i][j];
    }
  }
  for (int i = 0; i < n; i++)
    if (open[i] >= 1)
      for (int j = 1; j <= open[i]; j++) res1 = max(res1, profits[i][j]);
  for (int i = 0; i < n; i++) {
    temp = profits[i][0];
    for (int j = 1; j <= open[i]; j++) {
      if (temp <= profits[i][j]) {
        temp = profits[i][j];
        noopen = false;
      }
    }
    res += temp;
  }
  if (noopen)
    cout << res1 << endl;
  else
    cout << res << endl;
  return 0;
}
