#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> x(n, vector<int>(10));
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(10); ++j) {
      cin >> x.at(i).at(j);
    }
  }
  vector<vector<int>> p(n, vector<int>(11));
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(11); ++j) {
      cin >> p.at(i).at(j);
    }
  }
  bool ex = false;
  vector<int> co(n);
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(10); ++j) {
      if (x.at(i).at(j) == 1) {
        co.at(i)++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); ++i) {
    int now = p.at(i).at(0);
    for (int j = (1); j < (int)(co.at(i) + 1); j++) {
      if (now < p.at(i).at(j)) {
        now = p.at(i).at(j);
        ex = true;
      }
    }
    ans += now;
  }
  if (ex) {
    cout << ans << endl;
  } else {
    int ans2 = 0;
    for (int i = 0; i < (int)(n); ++i) {
      if (p.at(i).at(0) > 0) {
        ans2 += p.at(i).at(0);
      }
    }
    int s = 1001001001;
    for (int i = 0; i < (int)(n); ++i) {
      for (int j = (1); j < (int)(co.at(i) + 1); j++) {
        s = min(s, p.at(i).at(0) - p.at(i).at(j));
      }
    }
    ans2 -= s;
    cout << ans2 << endl;
  }
}
