#include <bits/stdc++.h>
bool da[110][12];
int n, p[110][11], tin, ans = 0;
int main() {
  long long ans = 0;
  memset(p, 0, sizeof p);
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      std::cin >> da[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      std::cin >> p[i][j];
    }
  }
  ans = -(1 << 31);
  for (int i = 1; i < (1 << 10); i++) {
    int curr = 0, tc;
    for (int j = 0; j < n; j++) {
      int c = 0;
      for (int k = 0; k < 10; k++) {
        if ((i >> k & 1) && da[j][k]) c++;
      }
      curr += p[j][c];
      tc = c;
    }
    if (curr > ans) {
      ans = curr;
      std::cout << curr << " " << tc << std::endl;
    }
  }
  std::cout << ans;
  return 0;
}
