#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> lim(0);
  for (int i = 0; i < N; i++) {
    int num = 0;
    for (int j = 0; j < 10; j++) {
      int a;
      cin >> a;
      if (a == 1) num++;
    }
    lim.push_back(num);
  }
  vector<vector<long long>> check(N, vector<long long>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      long long a;
      cin >> a;
      check[i][j] = a;
    }
  }
  long long zero = 1e7, ans = 0;
  for (int i = 0; i < N; i++) {
    long long pro = -1e7;
    for (int j = 1; j <= lim[i]; j++) {
      pro = max(pro, check[i][j]);
    }
    long long b = check[i][0] - pro;
    zero = min(zero, b);
    pro = max(pro, check[i][0]);
    ans += pro;
  }
  if (zero > 0) ans -= zero;
  cout << ans << endl;
}
