#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int>> farr;
vector<vector<int>> parr;
bool isValid(string &state) {
  for (int i = 0; i < state.size(); i++) {
    if (state[i] == '1') {
      return true;
    }
  }
  return false;
}
int64_t calc(int idx, string state) {
  int64_t count = 0;
  for (int i = 0; i < 10; i++) {
    if (state[i] == '1' && farr[idx][i] == 1) {
      count++;
    }
  }
  return count;
}
int64_t dfs(string state) {
  if (state.size() == 10) {
    cout << state << endl;
    if (!isValid(state)) {
      return INT64_MIN;
    }
    int64_t profit = 0;
    for (int i = 0; i < N; i++) {
      int num = calc(i, state);
      profit += parr[i][num];
    }
    cout << profit << endl;
    return profit;
  }
  return max(dfs(state + "0"), dfs(state + "1"));
}
int main(int argc, char *argv[]) {
  cin >> N;
  cout << N << endl;
  farr = vector<vector<int>>(N, vector<int>(10));
  vector<vector<int>> farr1(N, vector<int>(10));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> farr[i][j];
    }
  }
  parr = vector<vector<int>>(N, vector<int>(11));
  for (int k = 0; k < N; k++) {
    for (int l = 0; l < 11; l++) {
      cin >> parr[k][l];
    }
  }
  int ans = dfs("");
  cout << ans << endl;
  return 0;
}
