#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> cnt(N);
  int ans = 0;
  for (int i = 0; i < (int)(N); i++) {
    int c = 0;
    for (int i = 0; i < (int)(10); i++) {
      int a;
      cin >> a;
      if (a == 1) c++;
    }
    cnt[i] = c;
  }
  int min_num = 1e9;
  int max_num = -1e9;
  bool judge = 1;
  for (int i = 0; i < (int)(N); i++) {
    int c = -1e9;
    int d = -1e9;
    for (int j = 0; j < (int)(11); j++) {
      int b;
      cin >> b;
      if (j <= cnt[i]) {
        if (j == 0) min_num = min(min_num, b);
        if (j != 0) max_num = max(max_num, b);
        if (b > c) {
          c = b;
          d = j;
        }
      }
    }
    if (d != 0) judge = 0;
    ans += c;
  }
  if (judge) ans = ans - min_num + max_num;
  cout << ans << endl;
}
