#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void PLAY() {}
int f[105][100];
int p[105][100];
int n;
int main() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 10; j++) cin >> f[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10; j++) cin >> p[i][j];
  long long res = 0;
  int cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= 10; j++) cnt += f[i][j] == 1;
    int mx = INT_MIN;
    int idx = -1;
    for (int j = 0; j <= cnt; j++) {
      if (mx <= p[i][j]) {
        mx = p[i][j];
        idx = j;
      }
    }
    cnt2 += idx == 0;
    res += mx;
  }
  if (cnt2 == n) {
    res = INT_MIN;
    for (int i = 1; i <= n; i++) res = max(1LL * p[i][1], res);
  }
  cout << res << endl;
  return 0;
}
