#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)(a.size())

template<class T> 
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}

template<class T> 
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}

//コーナーケースに気をつけろ！
int main() {
    ll n;   cin >> n;
    vector<ll> a(n+1, 0);
    rep(i, n)   cin >> a[i+1];
    vector<vector<ll> > s(n+1, vector<ll>(n+2, 0));
    vector<vector<int> > pre(n+1, vector<int>(n+1, 0));
    for (int i = 1; i <= n; i++){
        vector<int> last(i, 0);
        ll s = 0;
        for (int j = 1; j <= n; j++) {
            s = (s + a[j]) % i;
            pre[i][j] = last[s];
            last[s] = j;
        }
    }
    vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0));
    dp[0][0] = 1;
    ll mod = 1e9+7;
    for (int r = 1; r <= n; r++) {
        for (int k = 1; k <= n; k++) {
            dp[r][k] = (dp[pre[k][r]][k] + dp[pre[k][r]][k-1]) % mod;
        }
    }
    ll ans = 0;
    for (int k = 1; k <= n; k++)
        ans = (ans + dp[n][k]) % mod;
    cout << ans << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>
#include <bitset>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N][5];
  REP(i,N)REP(j,5)cin>>A[i][j];
  int OK=0;
  int NG=1e9+1;
  while(NG-OK>1){
    int c=(OK+NG)/2;
    bool dp[4][1<<5]={0};
    dp[0][0b00000]=1;
    // cerr<<c<<endl;
    int pi[N];
    REP(i,N){
      pi[i]=0;
      REP(j,5)if(A[i][j]>=c)pi[i]|=1<<j;
      // cerr<<bitset<5>(pi[i])<<endl;
    }
    REP(i,N){
      REP(n,3)REP(p,1<<5)if(dp[n][p]){
        dp[n+1][p|pi[i]]=true;
      }
    }
    if(dp[3][0b11111])OK=c;
    else NG=c;
  }
  cout<<OK<<endl;
  return 0;
}
