#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long int q = 1e9;
  long long int n, f[1010][1010], p[1010][1010], c[1010] = {}, ans = 0,
                                                 yojo = -q, siri = 0, del = -q;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++) {
      cin >> f[i][j];
      if (f[i][j] > 0) c[i]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (c[i]) {
      for (int j = 1; j <= c[i]; j++) {
        yojo = max(yojo, p[i][j]);
      }
      if (yojo > 0) {
        ans += yojo;
      } else {
        if (yojo == 0)
          siri++;
        else
          del = max(yojo, del);
      }
    }
    yojo = -q;
  }
  if (ans == 0 && siri == 0) {
    cout << del << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
