#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int n, f[100][10], p[100][11], i, j, k,
      sum = 0, mx, mn = INF, b[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, s = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++) {
      cin >> f[i][j];
      if (f[i][j] == 0) {
        b[j] = 0;
      }
    }
  }
  for (i = 0; i < 10; i++) {
    if (b[i] == 1) {
      s++;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 11; j++) {
      cin >> p[i][j];
      if (p[i][j] < mn) {
        mn = p[i][j];
      }
    }
  }
  for (i = 0; i < n; i++) {
    k = 0;
    mx = -INF;
    for (j = 0; j < 10; j++) {
      if (f[i][j] == 1) {
        k++;
      }
    }
    for (j = max(1, s); j <= k; j++) {
      if (mx < p[i][j]) {
        mx = p[i][j];
      }
    }
    sum += mx;
  }
  cout << max(sum, mn) << endl;
}
