#include <bits/stdc++.h>
using namespace std;
bool SecondCompare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
bool SecondCompareDes(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
int n;
int f[101][11], p[101][12], co[101];
int main() {
  int mi = -10000000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
      if (f[i][j] == 1) co[i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  int cou = 0;
  int ans = 0, mans = -10000000;
  for (int i = 0; i < n; i++) {
    mans = -10000000;
    for (int j = 0; j <= co[i]; j++) {
      if (mans < p[i][j]) {
        cou += j;
        mans = p[i][j];
      }
    }
    ans += mans;
  }
  if (cou == 0) {
    for (int i = 0; i < n; i++) {
      if (co[i] >= 1 && mi < p[i][1]) {
        mi = p[i][1];
      }
    }
    ans = mi;
  }
  cout << ans << endl;
}
