#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using IP = pair<int, int>;
const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll atcoder = 1e9 + 7;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0)
    return b;
  else
    gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  if (a < b) swap(a, b);
  return (a / gcd(a, b)) * b;
}
int main() {
  int n;
  cin >> n;
  int F[110][20] = {0};
  int p[110][20] = {0};
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) cin >> F[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++) cin >> p[i][j];
  ll ans;
  ll minF = linf;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ans = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (F[i][j] & bit >> j & 1) {
          cnt++;
        }
      }
      int maxp = -inf;
      for (int j = 0; j < cnt + 1; j++) {
        if (flag) ++j;
        maxp = max(maxp, p[i][j]);
      }
      if (maxp == p[i][0]) flag = true;
      ans += maxp;
    }
    ans = min(ans, minF);
  }
  cout << ans << endl;
  return 0;
}
