#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
long long int arr[200][200], ones[200], money[200][200], mx[200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 10; j++) {
      cin >> arr[i][j];
      if (arr[i][j]) cnt++;
    }
    ones[i] = cnt;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) cin >> money[i][j];
  }
  for (int i = 0; i < n; i++) {
    long long int cur = -INT_MAX;
    for (int j = 1; j <= ones[i]; j++) cur = max(cur, money[i][j]);
    mx[i] = cur;
  }
  long long int ans = -INT_MAX;
  for (int i = 0; i < n; i++) {
    long long int cur = mx[i];
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      long long int temp = max(money[j][0], mx[j]);
      if (temp >= 0) cur += temp;
    }
    ans = max(ans, cur);
  }
  cout << ans << endl;
  return 0;
}
