#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp, p, t[105], v[105], maxv, d[105], flag = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    p = 0;
    for (int j = 0; j < 10; j++) {
      scanf("%d", &temp);
      if (temp == 1) p++;
    }
    t[i] = p;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) scanf("%d", &v[j]);
    maxv = v[0];
    temp = t[i];
    sort(v, v + temp + 1);
    if (v[temp] == maxv && flag == 0)
      d[i] = v[temp] - v[temp - 1];
    else
      flag = 1;
    ans = ans + v[temp];
  }
  if (flag == 0) {
    sort(d, d + n);
    ans = ans - d[n - 1];
  }
  printf("%d", ans);
  return 0;
}
