#include <bits/stdc++.h>
using namespace std;
template <typename T>
void MACRO_VAR_Scan(T& t) {
  cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  cin >> first;
  MACRO_VAR_Scan(rest...);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  long long n;
  MACRO_VAR_Scan(n);
  ;
  vector<vector<int>> f(n, vector<int>(10));
  for (auto& r : f)
    for (auto& i : r) cin >> i;
  ;
  vector<vector<int>> p(n, vector<int>(11));
  for (auto& r : p)
    for (auto& i : r) cin >> i;
  ;
  int open[10];
  for (int i = 0; i < (n); i++) {
    int a = 0;
    for (int j = 0; j < (11); j++)
      if (f[i][j] == 1) a++;
    open[i] = a;
  }
  int M = -2000000000;
  long long sum = 0;
  for (int i = 0; i < (n); i++) {
    int b = -2000000000;
    for (int j = 0; j < (open[i] + 1); j++) {
      b = max(b, p[i][j]);
      if (p[i][j] < 0) {
        M = max(M, p[i][j]);
      }
    }
    if (b > 0) {
      sum += b;
    }
  }
  if (sum) {
    cout << (sum);
    cout << "\n";
    ;
    ;
  } else {
    cout << (M);
    cout << "\n";
    ;
    ;
  }
  return 0;
  ;
}
