#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  for (int i = 0; (i) < (int)(n); i++)
    if (bit & (1 << i)) S.push_back(i);
  return S;
}
int main() {
  int n;
  cin >> n;
  vector<int> f(n);
  for (int i = 0; (i) < (int)(n); i++) {
    for (int j = 0; (j) < (int)(10); j++) {
      int a;
      cin >> a;
      f[i] += a;
    }
  }
  vector<vector<P>> p(n);
  for (int i = 0; (i) < (int)(n); i++) {
    for (int j = 0; (j) < (int)(11); j++) {
      int a;
      cin >> a;
      if (j > f[i]) continue;
      p[i].emplace_back(a, j);
    }
  }
  for (int i = 0; (i) < (int)(n); i++)
    sort((p[i]).begin(), (p[i]).end(), greater<P>());
  int flag = 0;
  ll res = 0;
  for (int i = 0; (i) < (int)(n); i++) {
    int bene = p[i][0].first, id = p[i][0].second;
    res += bene, flag += id;
  }
  if (flag == 0) {
    int mn = 1e9;
    for (int i = 0; (i) < (int)(n); i++) {
      int dist = p[i][0].first - p[i][1].first;
      mn = min(mn, dist);
    }
    res -= mn;
  }
  cout << res << endl;
}
