#include <bits/stdc++.h>
using namespace std;
int x[101];
int main() {
  int n;
  int f[103][10];
  int p[103][11];
  cin >> n;
  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 <= 10; j++) {
      cin >> p[i][j];
    }
  }
  int ans = 0;
  int cnt;
  int sum;
  int s;
  int ss;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    sum = 0;
    s = -10000000;
    ss = -10000000;
    for (int j = 0; j <= 10; j++) {
      if (f[i][j] == 1) cnt++;
    }
    for (int j = 0; j <= cnt; j++) {
      if (s <= p[i][j]) {
        s = p[i][j];
        if (j != 0) flag = true;
      }
      if (j != 0) ss = max(ss, p[i][j]);
    }
    x[i] = ss;
    sum += s;
    ans += sum;
  }
  sort(x, x + n);
  cout << ans << endl;
  return 0;
}
