#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 109;
int arr[N], p[N][11], n, dp[N][2];
int rec(int pos, int take) {
  if (pos > n) {
    if (take) return 0;
    return -1000000007;
  }
  int& ret = dp[pos][take];
  if (~ret) return ret;
  ret = -1000000007;
  for (int i = 0; i <= arr[pos]; i++)
    umax(ret, rec(pos + 1, take | (i > 0)) + p[pos][i]);
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 10; j++) {
      int x;
      scanf("%d", &x);
      arr[i] += x;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10; j++) scanf("%d", &p[i][j]);
  printf("%d\n", rec(1, 0));
  return 0;
}
