#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int f[n + 1][11];
  int b[n + 1];
  ;
  for (int i = 0; i < n; ++i) {
    b[i] = 1;
    ;
    for (int j = 0; j < 10; ++j) {
      cin >> f[i][j];
      if (f[i][j] == 1) ++b[i];
    }
  }
  int p[n + 1][11];
  ;
  for (int i = 0; i < n; ++i) {
    ;
    for (int j = 0; j < 11; ++j) {
      cin >> p[i][j];
    }
  }
  vector<int> a(n);
  int ans = 0;
  int count;
  ;
  for (int i = 0; i < n; ++i) {
    count = -1.0e7 - 1;
    for (int j = 1; j < b[i]; ++j) {
      count = max(p[i][j], count);
    }
    ans += count;
  }
  cout << ans << endl;
  return 0;
}
