#include <bits/stdc++.h>
using namespace std;
int n, ans, mx, loc, num;
int f[105][15], p[105][15], t[105];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 10; j++) {
      cin >> f[i][j];
      if (f[i][j]) f[i][0]++;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10; j++) cin >> p[i][j];
  for (int i = 1; i <= n; i++) {
    mx = -(int)1e9;
    loc = -1;
    for (int j = 0; j <= f[i][0]; j++) {
      if (mx < p[i][j]) {
        mx = p[i][j];
        loc = j;
      }
    }
    t[i] = mx;
    if (loc == 0) num++;
  }
  if (num == n) {
    ans = 0;
    mx = -(int)1e9;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= f[i][0]; j++)
        if (mx < p[i][j]) {
          mx = p[i][j];
          loc = i;
        }
    for (int i = 1; i <= n; i++)
      if (i == loc)
        ans += mx;
      else
        ans += t[i];
  } else
    for (int i = 1; i <= n; i++) ans += t[i];
  cout << ans;
  return 0;
}
