#include <bits/stdc++.h>
using namespace std;
int solve(int** schedule, int** p, vector<int> d, int n, int day, bool check) {
  if (day == 10) {
    if (!check) {
      int a = -1000000000;
      return a;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += p[i][d[i]];
    }
    return ans;
  }
  int ans = solve(schedule, p, d, n, day + 1, check);
  for (int i = 0; i < n; i++) {
    d[i] += schedule[i][day];
  }
  int ans2 = solve(schedule, p, d, n, day + 1, true);
  if (ans < ans2) ans = ans2;
  return ans;
}
int main(void) {
  int n = 0;
  cin >> n;
  int** schedule = new int*[n];
  int** p = new int*[n];
  for (int i = 0; i < n; i++) {
    schedule[i] = new int[10];
    p[i] = new int[10];
    for (int j = 0; j < 10; j++) {
      cin >> p[i][j];
    }
  }
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    d[i] = 0;
    for (int j = 0; j < 10; j++) {
      cin >> p[i][j];
    }
  }
  cout << solve(schedule, p, d, n, 0, false) << endl;
  return 0;
}
