#include <bits/stdc++.h>
int main() {
  int N = 0;
  std::scanf("%d", &N);
  std::vector<int64_t> shops;
  shops.resize(N);
  for (int i = 0; i < N; i++) {
    int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10;
    scanf("%d %d %d %d %d %d %d %d %d %d", &f1, &f2, &f3, &f4, &f5, &f6, &f7,
          &f8, &f9, &f10);
    shops[i] = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10;
  }
  bool opened = false;
  int second = -INT_MAX;
  int64_t result = 0;
  for (int i = 0; i < N; i++) {
    int p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11;
    scanf("%d %d %d %d %d %d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6, &p7,
          &p8, &p9, &p10, &p11);
    using P = std::pair<uint32_t, int>;
    std::vector<P> p;
    p.resize(11);
    p[0] = std::make_pair(0, p1);
    p[1] = std::make_pair(1, p2);
    p[2] = std::make_pair(2, p3);
    p[3] = std::make_pair(3, p4);
    p[4] = std::make_pair(4, p5);
    p[5] = std::make_pair(5, p6);
    p[6] = std::make_pair(6, p7);
    p[7] = std::make_pair(7, p8);
    p[8] = std::make_pair(8, p9);
    p[9] = std::make_pair(9, p10);
    p[10] = std::make_pair(10, p11);
    std::sort(p.begin(), p.end(),
              [](const P& a, const P& b) { return a.second > b.second; });
    second = std::max(second, p2);
    for (const auto& e : p) {
      if (shops[i] >= e.first) {
        opened = e.first > 0;
        result += e.second;
        break;
      }
    }
  }
  if (!opened) {
    std::cout << second << std::endl;
  } else {
    std::cout << result << std::endl;
  }
  return 0;
}
