#include <bits/stdc++.h>
using namespace std;
int n, ans;
map<int, int> m;
int val[10];
int main() {
  cin >> n;
  int f[n][10];
  int p[n][10];
  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];
    }
  }
  for (int j = 0; j < 10; j++) {
    for (int i = 0; i < n; i++) {
      val[j] += f[i][j] * p[i][j];
    }
  }
  for (int i = 0; i < 10; i++) {
    cout << val[i] << ' ';
  }
  cout << endl;
  sort(val, val + 10);
  reverse(val, val + 10);
  ans = val[0];
  for (int i = 1; i < 10; i++) {
    if (val[i] > 0) ans += val[i];
  }
  cout << ans << endl;
  system("pause");
}
