#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[n];
  for (int i = 0; i < n; i++) {
    f[i] = 0;
    for (int j = 0; j < 10; j++) {
      int m;
      cin >> m;
      if (m == 1) f[i]++;
    }
  }
  long p[n][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) cin >> p[i][j];
  }
  long ans = 0;
  for (int i = 0; i < n; i++) {
    long num = p[i][1];
    for (int j = 2; j <= f[i]; j++) {
      num = max(num, p[i][j]);
    }
    if (i == 0 || num > 0) ans += num;
  }
  cout << ans << endl;
}
