#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 0, b, c, n, ans = 0, max;
  vector<int> v;
  vector<vector<int>> w;
  w.resize(2);
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> b;
      a += b;
    }
    v.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> c;
      w[i].push_back(c);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < v[i] + 1; j++) {
      if (j == 0)
        max = w[i][j];
      else
        max = w[i][j];
      if (max < w[i][j]) max = w[i][j];
    }
    ans += max;
    cout << max;
  }
  cout << ans;
  return 0;
}
