#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(11, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  vector<vector<long long int>> p(n, vector<long long int>(12, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  vector<long long int> sum(n, 0), sum2(n, 0);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    sum[i] = p[0][1];
    for (int j = 0; j < 10; j++) {
      if (f[i][j] == 1) {
        cnt++;
      }
      if (cnt != 0 && sum[i] < p[i][cnt]) {
        sum[i] = p[i][cnt];
      }
    }
  }
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (sum[i] < p[i][0]) {
      sum2[i] = p[i][0];
      num++;
    } else {
      sum2[i] = sum[i];
    }
  }
  if (num == n) {
    long long int tnp = sum[0];
    int k = 0;
    for (int i = 1; i < n; i++) {
      if (tnp > sum[i]) {
        tnp = sum[i];
        k = i;
      }
    }
    sum2[k] = sum[k];
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += sum2[i];
  }
  cout << ans << endl;
  return 0;
}
