#include <bits/stdc++.h>
using namespace std;
int n, f[100][10], p[100][10], ans = 0x80000000;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) scanf("%d", &f[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) scanf("%d", &p[i][j]);
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (cur.first == 10) {
      int res = 0;
      for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < 10; j++)
          if (f[i][j] && (cur.second & (1 << j))) cnt++;
        res += p[i][cnt];
      }
      if (res > ans) ans = res;
      printf("%d %d\n", cur.second, res);
    } else {
      q.push(make_pair(cur.first + 1, cur.second * 2));
      q.push(make_pair(cur.first + 1, cur.second * 2 + 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}
