#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, f[100][10], p[100][11], ans = 0, max_n = -10000001;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  bool flag_0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 10; j++) {
      if (f[i][j]) {
        cnt++;
      }
    }
    flag_0 = true;
    int max_p = -10000001;
    for (int j = 0; j <= cnt; j++) {
      if (max_p < p[i][j]) {
        max_p = p[i][j];
        if (j == 0) {
          flag_0 = true;
        } else {
          flag_0 = false;
        }
      }
      if (max_n < p[i][j] && p[i][j] < 0) {
        max_n = p[i][j];
      }
    }
    ans += max_p;
  }
  if (flag_0) {
    cout << max_n << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
