/*Author-Nilesh Chandra(isocyanide7)*/
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       ll n,i,j,ans=0;
       cin>>n;
       vector <ll> v(n);
       map <ll,ll> mp;
       for(auto &u:v)
        cin>>u,mp[u+200]++;
       for(i=0;i<=400;i++)
        for(j=i+1;j<=400;j++)
         ans+=mp[i]*mp[j]*(i-j)*(i-j);
       cout<<ans;     
   }
}
//https://atcoder.jp/contests/zone2021/tasks/zone2021_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool chk(vector<vector<int>> &arr, int mid)
{
    int n=arr.size();
    set<int> st;
    for (int i = 0; i < n; i++)
    {
        int c=0;
        for (int j = 0; j < 5; j++)
        {
            int bit=0;
            if(arr[i][j]>=mid) bit=1;
            c+=(bit<<j);
        }
        st.insert(c);
    }
    for(auto e:st)
        for(auto f:st)
            for(auto g:st)
            {
                if((e|f|g)==31)
                    return 1;
            }
    return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(5, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 5; j++)
            cin >> arr[i][j];
    }

    int l = 1, r = 1e9 + 1;
    while (l < r)
    {
        int mid = (l + r)/2;
        if(chk(arr,mid))    l=mid+1;
        else r=mid;
    }
    cout<<l-1<<endl;
}
