#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  std::vector<int> f(n, 0);
  map<int, map<int, long long> > p_map;
  std::vector<std::vector<int> > p_vec(n, std::vector<int>(11, 0));
  std::vector<long long> p_ans(n + 1, 0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int open;
      cin >> open;
      if (open) {
        f[i]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      long long tmp;
      cin >> tmp;
      if (p_map[i].find(tmp) == p_map[i].end()) {
        p_map[i].insert(make_pair(tmp, j));
      } else {
        if (f[i] < p_map[i][tmp]) {
          p_map[i].erase(tmp);
          p_map[i].insert(make_pair(tmp, j));
        }
      }
      p_vec[i][j] = tmp;
    }
  }
  int open = 0;
  for (int i = 0; i < n; i++) {
    sort(p_vec[i].rbegin(), p_vec[i].rend());
    for (auto p : p_vec[i]) {
      if (f[i] >= p_map[i][p]) {
        p_ans[i] = p;
        if (p_map[i][p]) {
          open++;
        }
        break;
      }
    }
  }
  sort(p_ans.rbegin(), p_ans.rend());
  if (open == 0) {
    for (int i = 0; i < n; i++) {
      for (size_t j = 1; j < p_vec[i].size(); j++) {
        if (f[i] >= p_map[i][p_vec[i][j]]) {
          p_ans[i] = p_vec[i][j];
          break;
        }
      }
    }
  }
  for (size_t i = 0; i < p_ans.size(); i++) {
    ans += p_ans[i];
    if (p_ans[i + 1] < 0) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
