stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cctype>

#include <iostream>

#include <algorithm>

#include <ext/pb_ds/hash_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#include <queue>

#define ri register int 

#define ll long long 

#define ull unsigned long long 

using std::min;

using std::max;

using std::lower_bound;

using namespace __gnu_pbds;

template <class T>inline void read(T &x){

    x=0;int ne=0;char c;

    while(!isdigit(c=getchar()))ne=c=='-';

    x=c-48;

    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;

    x=ne?-x:x;return ;

}

const int maxn=200005;

const int inf=0x7fffffff;

int n,nn,a[maxn],b[maxn],c[maxn],mx=-inf,mi=inf;

ll sum[maxn<<2];

inline void update(int x,int d){for(;x<=nn;x+=x&(-x))sum[x]+=d;}

inline ll query(int x){ll ans=0;for(;x;x-=x&(-x))ans+=sum[x];return ans;}

inline ll chk(int k){

    ll ans=0;

    b[0]=0;

    for(ri i=1;i<=n;i++){

        b[i]=b[i-1]+((a[i]<=k)?1:-1);

        c[i]=b[i];

        ans+=(b[i]>0);

    }

    std::sort(c+1,c+1+n);

    nn=std::unique(c+1,c+1+n)-(c+1);

    memset(sum,0,sizeof(sum));

    for(ri i=1;i<=n;i++){

    	b[i]=lower_bound(c+1,c+1+nn,b[i])-c;

        ans+=query(b[i]-1);

        update(b[i],1);

    }

    return ans;

}

int main(){

    read(n);

    for(ri i=1;i<=n;i++){

        read(a[i]);

        mi=min(mi,a[i]),mx=max(mx,a[i]);

    }

    int L=mi,R=mx,mid,ans;

	ll lim=1ll*n*(n+1)/4+1;

    while(L<=R){

        mid=(L+R)>>1;

        if(chk(mid)>=lim)ans=mid,R=mid-1;

        else L=mid+1;

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 40.000360714600404x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<set>

#define MN 100005

using namespace std;

int n,tt,a[MN],num[MN],tmp[MN],tmpx[MN];

long long tx;

void mergesort(int ll,int rr){

	if(ll==rr)return;

	int mid=(ll+rr)>>1;

	mergesort(ll,mid),mergesort(mid+1,rr);

	int tl=ll,tr=mid+1,now=0;

	while(tl<=mid&&tr<=rr){

		if(tmp[tl]<tmp[tr])tmpx[++now]=tmp[tl++];

		else {

			tx+=tl-ll;

			tmpx[++now]=tmp[tr++];

		}

	}

	while(tl<=mid)tmpx[++now]=tmp[tl++];

	while(tr<=rr)tx+=tl-ll,tmpx[++now]=tmp[tr++];

	for(int i=ll,j=1;i<=rr;i++,j++)tmp[i]=tmpx[j];

}

bool check(int mid){

	for(int i=1;i<=n;i++)

		tmp[i]=tmp[i-1]+(a[i]<=mid?1:-1);

	tx=0;mergesort(0,n);

	return tx>=(1ll*n*(n+1)/4+1);

}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]),num[++tt]=a[i];sort(num+1,num+tt+1);tt=unique(num+1,num+n+1)-num;

	int l=1,r=tt-1,ans=tt-1;

	while(l<=r){

		int mid=(l+r)>>1;

		if(check(num[mid]))ans=mid,r=mid-1;

		else l=mid+1;

	}printf("%d\n",num[ans]);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;



int h[100005], dp[100005], n, k;



int go(int idx){

    //cout << idx << endl;

    if(idx == n-1)return 0;

    if(dp[idx] != -1)return dp[idx];

    int ans = 1e9 + 7;

    for(int j = 1; j <= k; j++){

        if(idx + j < n){

            ans = min(ans, go(idx+j) + abs(h[idx]-h[idx+j]));

        }

    }

    return dp[idx] = ans;

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

    for(int i = 0; i < n; i++){

        cin >> h[i];

    }

    /*

    for(int i = 1; i < n; i++){

        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);

        for(int j = 2; j <= k && (i-j) >= 0; j++){

            dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[j]));

        }

    }

    cout << dp[n-1] << endl;*/

    memset(dp, -1, sizeof dp);

    cout << go(0) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3951981131609095x):
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;



int h[100005], dp[100005], n, k;



int go(int idx){

    //cout << idx << endl;

    if(idx == n-1)return 0;

    if(dp[idx] != -1)return dp[idx];

    int ans = 1e9 + 7;

    for(int j = 1; j <= k; j++){

        if(idx + j < n){

            ans = min(ans, go(idx+j) + abs(h[idx]-h[idx+j]));

        }

    }

    return dp[idx] = ans;

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

    for(int i = 0; i < n; i++){

        cin >> h[i];

    }

    for(int i = 1; i < n; i++){

        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);

        for(int j = 2; j <= k; j++){

            if(i-j >= 0){

                dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));

            }

        }

    }

    cout << dp[n-1] << endl; /*

    memset(dp, -1, sizeof dp);

    cout << go(0) << endl;*/

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cstring>

#include<cmath>

#include<iomanip>

#include<string>

using namespace std;

int main(){

    long long int k,x,a;

    cin>>k>>x;

    for(int i=1;i<=(2*k-1);i++)

 {a=x-k+i;

 cout<<a<<" ";

 }

 cout<<endl;

    return 0;



}




// Faster C++ solution for the same problem (measured speedup: 5.223888782233414x):
///d. one clue

#include <stdio.h>

#include <math.h>



int main()

{

    int k,x;

    scanf("%d %d",&k, &x);



    for(int i=x-k+1;i<=x+k-1;i++){

        printf("%d ",i);

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

long long a[100007];

int n,m;long long ans;

int main()

{

	cin>>n;

	for(int i=1;i<=n;++i)

	{

	int x;

	scanf("%d",&x);

	++a[x];

	ans+=x;

	}

	cin>>m;

	for(int i=1;i<=m;++i)

	{

		long long x,y;

		scanf("%lld%lld",&x,&y);

		ans+=(y-x)*a[x];

		a[y]+=a[x];

		a[x]=0;

		printf("%lld\n",ans);

	}

	return 0;

	

}

// Faster C++ solution for the same problem (measured speedup: 5.200265800296407x):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std; 

typedef long long LL;

const int MAXN=1E5+10;

int f[MAXN],sum[MAXN],tong[MAXN],a[MAXN];

long long sumans;



int main() {

	int N,K;

	scanf("%d",&N);

	sumans=0;

	for(int i=1;i<=N;++i) {

		scanf("%d",&a[i]);

		sumans+=a[i];

		tong[a[i]]+=1;

	}

	scanf("%d",&K);

	for(int i=1;i<=K;++i) {

		int b,c;scanf("%d%d",&b,&c);

		sumans-=1ll*tong[b]*b;

		sumans+=1ll*tong[b]*c;

		

		tong[c]+=tong[b];

		tong[b]=0;

		

		printf("%lld\n",sumans);

	}

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;



const int yu = 1e5+103;

int n, k;

int dp[yu];

int a[yu];

int f(int i){

	if (i==n-1) return 0;

	if(dp[i]!=-1) return dp[i];

	int pqr = abs(a[i]-a[i+1])+f(i+1);

	for(int j=2; j<=k; j++){

		if(i+j<n) pqr = min(pqr, abs(a[i]-a[i+j])+f(i+j));

	}

	return dp[i]=pqr;

}

int main(){

	cin>>n>>k;

	for(int i=0; i<n; i++) cin>>a[i];

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.404394567144052x):
#include <bits/stdc++.h>

#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);

#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

using namespace std;

typedef long long ll;



const int N = 1e5;



int arr[N], memo[N], n, k;



int dp() {

	for(int i = 2; i < n; ++i)

		memo[i] = 1e9;

	memo[1] = abs(arr[0] - arr[1]);

	for(int i = 2; i < n; ++i)

		for(int j = i - 1; j >= max(0, i - k); --j)

			memo[i] = min(memo[i], abs(arr[i] - arr[j]) + memo[j]);

	return memo[n - 1];

}



int main() {

    Data_Nerd



	scanf("%d%d", &n, &k);



    for(int i = 0; i < n; ++i)

    	scanf("%d", arr + i);



    cout << dp();



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll N,K;

ll h[100010];

ll dp[100010];

ll call(int i)

{

    if(i==N) return 0;

    

    if(dp[i]!=-1) return dp[i];

    

    dp[i]=abs(h[i+1]-h[i]) + call(i+1);

    for(ll j=2;j<=K;j++)

    {

        if(i+j<=N)

    dp[i]=min(dp[i],abs(h[i+j]-h[i]) + call(i+j));

        else break;

    

        

    }

    return dp[i];

}

int main()

{

    cin>>N>>K;

    for(ll i=1;i<=N;i++)

    {

        cin>>h[i];

    }

    memset(dp,-1,sizeof(dp));

    cout<<call(1);

}

// Faster C++ solution for the same problem (measured speedup: 1.801395148041295x):
#include <bits/stdc++.h>

 

using namespace std;

 

int main() {

    int N,K;

    cin>>N>>K;

    if(N==1)

    {

        cout<<0;

        return 0;

    }

    int h[N];

    

    for(int i=0;i<N;i++)

    {

        cin>>h[i];

    }

    

    int val[N];

  for(int i=0;i<N;i++)

  {

    val[i]=INT_MAX;

  }

    val[0]=0;

    

    for(int i=1;i<N;i++)

    {

        for(int j=i-1;j>=0 && i-j<=K;j--)

        {

          val[i]=min(val[i],abs(h[i]-h[j])+val[j]);

        }

    }

  

    cout<<val[N-1];

    return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

#define rep(i, n) for ( int i = 0; i < n; i++ )

#define MAX 200

#define INFTY (1<<21)

int n, m, T[MAX][MAX], P[MAX][MAX];



void valid(int sx, int sy, int &lx, int &ly ){

    int ax = -1, ay;

    rep(y, m) rep(x, m){

	if ( P[x][y] == -1 ) continue;

	if ( P[x][y] != T[sx+x][sy+y] ) return;

	if ( ax == -1 ) {ay = y; ax = x;}

    }

    if ( ay < ly || (ay == ly && ax < lx) ) {ly = sy+ay; lx = sx+ax; }

}



bool rotate(int sx, int sy){

    int tmp[MAX][MAX];

    int ly = INFTY, lx;

    rep(r, 4){

	valid(sx, sy, lx, ly);

	rep(y, m) rep(x, m) tmp[x][y] = P[x][y];

	rep(y, m) rep(x, m) P[y][m-x-1] = tmp[x][y];

    }

    if ( ly == INFTY ) return false;

    cout << lx+1 << " " << ly+1 << endl;

    return true;

}



void compute(){

    rep(y, n-m+1) rep(x, n-m+1) if ( rotate(x, y) ) return;

    cout << "NA" << endl;

}



main(){

    while( cin >> n >> m && n ){

	rep(y, n) rep(x, n) cin >> T[x][y];

	rep(y, m) rep(x, m) cin >> P[x][y];

	compute();

    }

}

// Faster C++ solution for the same problem (measured speedup: 4.721838616229994x):
#include<cstdio>



#define rep(i, n) for ( int i = 0; i < n; i++ )

#define MAX 200

#define INFTY (1<<21)

int n, m, T[MAX][MAX], P[MAX][MAX];



void valid(int sx, int sy, int &lx, int &ly ){

    int ax = -1, ay;

    rep(y, m) rep(x, m){

	if ( P[x][y] == -1 ) continue;

	if ( P[x][y] != T[sx+x][sy+y] ) return;

	if ( ax == -1 ) {ay = y; ax = x;}

    }

    if ( ay < ly || (ay == ly && ax < lx) ) {ly = sy+ay; lx = sx+ax; }

}



bool rotate(int sx, int sy){

    int tmp[MAX][MAX];

    int ly = INFTY, lx;

    rep(r, 4){

	valid(sx, sy, lx, ly);

	rep(y, m) rep(x, m) tmp[x][y] = P[x][y];

	rep(y, m) rep(x, m) P[y][m-x-1] = tmp[x][y];

    }

    if ( ly == INFTY ) return false;

    printf("%d %d\n", lx+1, ly+1);

    return true;

}



void compute(){

    rep(y, n-m+1) rep(x, n-m+1) if ( rotate(x, y) ) return;

    printf("NA\n");

}



main(){

    while( scanf("%d %d", &n, &m) && n ){

	rep(y, n) rep(x, n) scanf("%d", &T[x][y]);

	rep(y, m) rep(x, m) scanf("%d", &P[x][y]);

	compute();

    }

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	string a;

	int k;

	cin>>k;

	cin>>a;

	int len=a.size();

	if(len<=k)

	 cout<<a<<endl;

	else

	{

		for(int i=0;i<k;++i)

		 cout<<a[i];

		cout<<"..."<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.321713686102251x):
#include<stdio.h>

#include<string.h>



int main()

{

	int n;

	scanf("%d",&n);

	char str[102];

	scanf("%s",&str);

	int len=strlen(str);

	if(len>n)

	{

		str[n]='.';

		str[n+1]='.';

		str[n+2]='.';

		str[n+3]='\0';

	}

	printf("%s",str);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long ll;

const int c=1e5+5;

const ll mod=1e9+7,M=998244353;

vector<ll>sold;

vector<ll>enem;

int n,k;

ll ans=1e18;

ll arr[c];

ll dp[c];

ll solve (int i)

{

    if(i==n-1)

    {

        return 0;



    }

    if(dp[i]!=-1)

    {

        return dp[i];

    }

    ans=abs(arr[i]-arr[i+1])+solve(i+1);

    for(int j=2;j<=k;j++){

    if(i<n-j){

     ans=min(ans,abs(arr[i]-arr[i+j])+solve(i+j));



    }

}

return dp[i]=ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>n>>k;

    for (int i=0; i<n; i++)

    {

        cin>>arr[i];

    }

    memset(dp,-1,sizeof dp);



    cout<<solve(0);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.819376377011567x):
#include<bits/stdc++.h>

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

ll  ara[mx];

ll  cost[mx];

int main()

{

    ll n,k;

    cin>>n>>k;

    for(ll  i=1;i<=n;i++) cin>>ara[i];

    cost[1]=0;

    cost[2]=abs(ara[2]-ara[1]);

    for(ll  i=3;i<=n;i++)

    {

        cost[i]=LLONG_MAX;

        for(ll  j=1;j<=min(i-1,k);j++)

        {

            cost[i]=min(cost[i],cost[i-j]+abs(ara[i]-ara[i-j]));

        }

    }

    cout<<cost[n]<<endl;





}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int N=2e5+5;

ll a[N],dp[N],n,k;

int main(){

	cin>>n>>k;

	for(int i=1;i<=n;++i)

		cin>>a[i];

	dp[1]=0;

    dp[0]=0;

    for(int i=2;i<=n;++i)

    	dp[i]=inf;

    for(int i=2;i<=n;++i)

     for(int j = 1;j<=k;++j)

        {

            if(i-j<1) break;

            dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));

        }

		cout<<dp[n];

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.679119301000766x):
#include <cstdio>

#include <cstring>



using namespace std;



const int maxn = 1e5+5;

int n,K;

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	memset(f,0x3f,sizeof(f));

	scanf("%d %d",&n,&K);

	for (int i = 1; i <= n; i++) {

		scanf("%d",&h[i]);

	}

	f[0] = f[1] = 0;

	for (int i = 2; i <= n; i++) {

		for (int k = 1; k <= K && k < i; k++){

			f[i] = min(f[i-k]+abs(h[i],h[i-k]),f[i]);

		}

	}

	printf ("%d\n",f[n]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef long double ld;



int n;

ll v[(1 << 16)];

int mat[16][16];

vector<int> m[(1 << 16)];



void get_masks(int idx, int mask, int a)

{

    if(idx == n){

      m[a].push_back(mask);

      return;

    }

    get_masks(idx + 1, mask, a);

    if(mask & (1 << idx))

    {

      get_masks(idx + 1, mask ^ (1 << idx), a);

    }

}



ll dp[(1 << 16)];

bool mark[(1 << 16)];

ll solve(int mask)

{

    if(mask == (1 << n) - 1)

      return 0;

    ll &ans = dp[mask];

    if(mark[mask])

      return ans;

    mark[mask] = 1;

    ans = -1e12;

    for(auto &x: m[mask])

    {

      ans = max(ans, solve(mask | x) + v[x]);

    }

    return ans;

}



int main()

{

    cin >> n;

    for(int i = 0; i < n; i++)

      for(int j = 0; j < n; j++)

        cin >> mat[i][j];

    for(int i = 0; i < (1 << n); i++)

    {

      vector<int> p;

      for(int j = 0; j < 16; j++)

      {

        if(i & (1 << j))

          p.push_back(j);

      }

      ll val = 0;

      for(int k = 0; k < p.size(); k++)

        for(int z = k + 1; z < p.size(); z++)

          val += mat[p[k]][p[z]];

      int newMask = i;

      for(int j = 0; j < n; j++)

        newMask ^= (1 << j);

      get_masks(0, newMask, i);

      v[i] = val;

    }

    memset(dp, -1, sizeof(dp));

    cout << solve(0);

}


// Faster C++ solution for the same problem (measured speedup: 1.2013181546087117x):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



const int N = (1 << 16) + 5;

int arr[16][16];

int n;

ll val[N];

vector<int> m[N];

ll dp[N];



void get_masks(int idx, int mask, int pos)

{

  if(idx == n)

  {

    if(mask)

      m[pos].push_back(mask);

    return;

  }

  get_masks(idx + 1, mask, pos);

  if(mask & (1 << idx))

    get_masks(idx + 1, mask ^ (1 << idx), pos);

}



int main()

{

  cin >> n;

  for(int i = 0; i < n; i++)

    for(int j = 0; j < n; j++)

      cin >> arr[i][j];

  for(int i = 0; i < (1 << n); i++)

  {

    for(int j = 0; j < n; j++)

    {

      for(int k = j + 1; k < n; k++)

      {

        if((i & (1 << j)) && (i & (1 << k)))

          val[i] += arr[j][k];

      }

    }

  }

  for(int i = 0; i < (1 << n); i++)

  {

    int newMask = i;

    for(int j = 0; j < n; j++)

      newMask ^= (1 << j);

    get_masks(0, newMask, i);

  }

  for(int i = (1 << n) - 2; i >= 0; i--)

  {

    for(auto &x: m[i])

    {

      dp[i] = max(dp[i], dp[i | x] + val[x]);

    }

  }

  cout << dp[0];

  return 0;

}
// Slower C++ solution:
//by Top1

#include <bits/stdc++.h>

     

#define f first

#define s second

#define int long long

#define ld long double

#define ull unsigned long long

#define pii pair <int, int>

#define pll pair <long, long>

#define mp make_pair

#define pb push_back

#define pf push_front

#define pp pop_back

#define rev reverse

#define all(s) s.begin(), s.end()

#define sz(s) (int)s.size()

#define forn(i, a, b) for (int i = a; i <= b; i++)

#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);

#define nxtp next_permutation

#define pvtp prev_permutation

#define KZ return 

#define x1 x21212121

#define y1 y21212121

#define sqr(x) x * x 

 

const int inf = INT_MAX;

const int mod = 1e9 + 7;

const int maxn = 6e5 + 111;

     

using namespace std;



int n, k, a[maxn], dp[maxn], t, q;



void solve(){    

	cin >> n >> k;



	for (int i = 1; i <= n; i++)

		cin >> a[i];



	dp[2] = abs(a[2] - a[1]);



	for (int i = 3; i <= n; i++){

		dp[i] = dp[i - 1] + abs(a[i - 1] - a[i]);

		for (int j = 2; j <= k && i - j > 0; j++)

			dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));

	}

	cout << dp[n];

}



main(){

    boost;

	    

	q = 1;



	while (q--){

		solve();

	}

}


// Faster C++ solution for the same problem (measured speedup: 5.2796946225586545x):
#include<cstdio>

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

ll n,k,h[100005],dp[100005];



int main(){

	if (file_io){

		freopen(".in","r",stdin);

		freopen(".out","w",stdout);

	}

	

	scanf("%lld%lld",&n,&k);

	

	for (i=1; i<=n; ++i){

		scanf("%lld",&h[i]);

	}

	

	dp[1]=0;

	for (i=2; i<=n; ++i){

		dp[i]=2e9;

		for (t=max(1ll,i-k); t<i; ++t){

			dp[i]=min(dp[t]+abs(h[i]-h[t]),dp[i]);

		}

	}

	

	printf("%lld\n",dp[n]);

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



const int N = 16;



ll dp[1 << N], cost[1 << N], a[N + 1][N + 1];

int n;



vector<int> get_bits(int mask)

{

    vector<int> bits;



    for(int i = 0; (1 << i) <= mask; i++)

        if((1 << i) & mask)

            bits.push_back(i);



    return bits;

}



ll solve(int mask)

{

    // cout << "enter: " << mask << endl;



    ll &ans = dp[mask];



    if(ans != -1)

        return ans;



    ans = cost[mask];

    auto bits = get_bits(mask);

    int sz = bits.size();



    for(int submasks = 1; submasks < (1 << sz); submasks++)

    {

        int next = 0;

        for(int i = 0; i < sz; i++)

            if((1 << i) & submasks)

                next |= 1 << bits[i];



        ans = max(ans, cost[next] + solve(mask & ~next));

    }



    // cout << mask << " " << ans << endl;



    return ans;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    memset(dp, -1, sizeof(dp));



    cin >> n;



    for(int i = 0; i < n; i++)

        for(int j = 0; j < n; j++)

            cin >> a[i][j];



    for(int mask = 0; mask < (1 << n); mask++)

    {

        auto bits = get_bits(mask);

        int sz = bits.size();



        for(int i = 0; i < sz; i++)

            for(int j = i + 1; j < sz; j++)

                cost[mask] += a[bits[i]][bits[j]];

    }



    // cout << "here" << endl;

    // exit(0);



    cout << solve((1 << n) - 1) << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.529833613827799x):
#include <bits/stdc++.h>

using namespace std;

const int N = (1 << 16) + 50;

int n;

long long mem[N], a[17][17], s[N];

bool vis[N];



long long score(int bm) {

	long long ans = 0;

	for (int i = 0; i < n; i++) {

		if (!(bm & (1 << i))) continue;

		for (int j = i + 1; j < n; j++) {

			if (!(bm & (1 << j))) continue;

			ans += a[i][j];

		}

	}

	return ans;

}



long long dp(int bm) {

	if (__builtin_popcount(bm) <= 1) {

		return 0;

	}

	if (vis[bm]) {

		return mem[bm];

	}

	vis[bm] = true;



	long long ans = 0;

	for (int fbm = bm; fbm; fbm = (fbm - 1) & bm) {

		long long tans = s[fbm] + dp(bm & ~fbm);

		ans = max(ans, tans);

	}



	return mem[bm] = ans;

}



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	

	cin >> n;



	for (int i = 0; i < n; i++) {

		for (int j = 0; j < n; j++) {

			cin >> a[i][j];

		}

	}



	for (int i = 1; i < (1 << n); i++) {

		s[i] = score(i);

	}



	cout << dp((1 << n) - 1) << endl;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

string s;

char f[20];

int main(){

	int tot=0;

	cin>>s;

	for(int i=0;i<s.size();i++){

		if(s[i]=='B'){

			if(tot>0)tot--;

		}

		else f[++tot]=s[i];

	}

	for(int i=1;i<=tot;i++)

	cout<<f[i];

	cout<<"\n";

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.276633638664502x):
#include <stdio.h>

#include <string.h>



void hekerman(char x[105]);



int main() {



    char x[105];



    scanf("%s", x);



    hekerman(x);



    return 0;

}



void hekerman(char x[105]) {



    int i, cnt = 0;

    char y[105];

    

    for(i = 0; i < strlen(x); i++) {

        if(x[i] == 'B') {

            cnt--;

        } else {

            y[cnt++] = x[i];

        }



        if(cnt < 0) {

            cnt = 0;

        }

    }



    for(i=0; i<cnt; i++) {

        printf("%c", y[i]);

    }

    printf("\n");



}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cstring>

#include<iomanip>

#include<cmath>

#define ll long long

using namespace std;

const int N=100010;





int main() {

    std::ios::sync_with_stdio(false);

    std::cin.tie(NULL);

    std::cout.tie(NULL);

    int n,m;

    int a[N];

    int ans=0;

    cin>>n>>m;

    for(int i=0;i<n;i++){

        cin>>a[i];

        if(a[i]>=m)

            ans++;

    }

     cout<<ans<<endl;



    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.1517169054294305x):
#include<stdio.h>

int main()

{

    int N,K,h[100000],n,i;

    scanf("%d%d",&N,&K);

    for(i=0,n=0;i<N;i++){

    scanf("%d",&h[i]);

    if(h[i]>=K){

        n=n+1;

      }

    }

    printf("%d\n",n);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int a[1000010],n,r,s1,s2;

int main(){

	scanf("%d",&n);

	for(int i=0;i<(1<<n);i++)

		scanf("%d",&a[i]);

	for(int i=1;i<(1<<n);i++){

		s1=a[0],s2=0;

		for(int j=i;j;j=(j-1)&i){

			if(a[j]>s1){

				s2=s1;

				s1=a[j];

			}

			else if(a[j]>s2)

				s2=a[j];

		}

		r=max(r,s1+s2);

		printf("%d\n",r);

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.080688231539603x):
#include <algorithm>

#include <cstdio>

#include <cstring>



#define int long long



const int Maxv = 300010; 



int ans[Maxv], max[Maxv], num, n; 



signed main() {

    scanf("%lld", &n); 

    

    for (int i = 0; i < (1 << n); i++) {

        scanf("%lld", &num); 

    

        for(int j = i; j < (1 << n); ((++j) |= i)) {

            ans[j] = std::max(ans[j], max[j] + num); 

            max[j] = std::max(max[j], num); 

        }

    }

       

    for (int i = 1; i < 1 << n; i++) {

        printf("%lld\n", ans[i]); 

        ans[i + 1] = std::max(ans[i + 1], ans[i]); 

    }

    

    return 0; 

}