#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<long long>> f(n, vector<long long>(11));
  vector<int> maximumNum(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 10; j++) {
      cin >> f[i][j];
      maximumNum[i] += f[i][j];
    }
  }
  vector<vector<long long>> p(n, vector<long long>(11));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  vector<long long> maximumProfit(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= maximumNum[i]; j++) {
      if (j == 0)
        maximumProfit[i] = p[i][j];
      else
        maximumProfit[i] = max(maximumProfit[i], p[i][j]);
    }
  }
  long long ans = 0LL;
  sort(maximumProfit.begin(), maximumProfit.end(), greater<int>());
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (0 < maximumProfit[i]) {
      ans += maximumProfit[i];
      cnt++;
    }
  }
  if (cnt == 0) ans += maximumProfit[0];
  cout << ans << endl;
  return 0;
}
