#include <bits/stdc++.h>
using namespace std;
inline void scd(int &a) { scanf("%d", &a); }
inline void scdd(int &a, int &b) { scanf("%d %d", &a, &b); }
inline void sctd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
inline void sctlld(long long int &a, long long int &b, long long int &c) {
  scanf("%I64d %I64d %I64d", &a, &b, &c);
}
inline void scdlld(long long int &a, long long int &b) {
  scanf("%I64d %I64d", &a, &b);
}
inline void sclld(long long int &a) { scanf("%I64d", &a); }
inline void scllu(unsigned long long int &a) { scanf("%I64u", &a); }
inline void scdllu(unsigned long long int &a, unsigned long long int &b) {
  scanf("%I64u %I64u", &a, &b);
}
inline void sctllu(unsigned long long int &a, unsigned long long int &b,
                   unsigned long long int &c) {
  scanf("%I64u %I64u %I64u", &a, &b, &c);
}
template <class Ver>
inline void prd(Ver a) {
  cout << a << "\n";
};
template <class Ver>
inline void prdd(Ver a, Ver b) {
  cout << a << " " << b << "\n";
};
template <class Ver>
inline void prtd(Ver a, Ver b, Ver c) {
  cout << a << " " << b << " " << c << "\n";
};
inline void debug() { printf("asd\n"); }
template <class Ver>
inline void debugd(Ver a) {
  cout << "--- " << a << endl;
};
template <class Ver>
inline void debugdd(Ver a, Ver b) {
  cout << "--- " << a << " " << b << endl;
};
template <class Ver>
inline void debugtd(Ver a, Ver b, Ver c) {
  cout << "--- " << a << " " << b << " " << c << endl;
};
void st() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  st();
  int ver = 0, niy = 0, hbk = 0;
  int sh[205] = {0};
  long long int ans = 0;
  scd(ver);
  int p[205][20] = {0};
  for (int i = 0; i < ver; ++i) {
    for (int j = 0; j < 10; ++j) {
      scd(niy);
      sh[i] += niy;
    }
  }
  int x = 0;
  long long int idx[205] = {0};
  long long int ch[205] = {0};
  for (int i = 0; i < ver; ++i) {
    for (int j = 0; j < 11; ++j) {
      scd(p[i][j]);
    }
    long long int currans = LLONG_MIN;
    for (int j = sh[i]; j >= 0; --j) {
      if (currans < p[i][j]) {
        idx[i] = j;
        ch[i] = p[i][j];
        currans = p[i][j];
      }
    }
    ans += currans;
  }
  for (int i = 0; i < ver; ++i) {
    if (idx[i] > 0) {
      prd(ans);
      return 0;
    }
  }
  long long int chidx = 0;
  long long int currans = LLONG_MIN;
  long long int mn = LLONG_MAX;
  vector<int> idxmin;
  for (int i = 0; i < ver; ++i) {
    if (sh[i] > 0 && mn >= p[i][0]) {
      mn = p[i][0];
    }
  }
  for (int i = 0; i < ver; ++i) {
    if (mn == p[i][0]) idxmin.push_back(i);
  }
  for (int i = 0; i < idxmin.size(); ++i) {
    for (int j = sh[idxmin[i]]; j >= 1; --j) {
      if (currans < p[idxmin[i]][j]) {
        chidx = idxmin[i];
        currans = p[idxmin[i]][j];
      }
    }
  }
  ans = 0;
  for (int i = 0; i < ver; ++i) {
    ans = ans + (i == chidx ? currans : ch[i]);
  }
  prd(ans);
  return 0;
}
