#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  bool F[100][100];
  int profits[100][100];
  int min = -10000001;
  int ans = 0;
  bool flag = false;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> profits[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 10; j++) {
      if (F[i][j] == true) {
        if (profits[i][j] >= 0) {
          ans += profits[i][j];
          flag = true;
        } else if (min > profits[i][j])
          min = profits[i][j];
      }
    }
    if (flag == false) ans += min;
    flag = false;
    min = -10000001;
  }
  cout << ans << endl;
  return 0;
}
