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

//#include <windows.h>



int masu[100][100],mx,ice[100][100],n,m;



/**

void print()

{

	system("cls");

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

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

			printf("%d ",masu[i][j]);

		}

		puts("");

	}

}

/**/



void func(int x,int y,int now)

{

//	printf("%d",now);

//	print();

	

	if(masu[x+1][y]==1){

		masu[x][y]=0;

		func(x+1,y,now+1);

		masu[x][y]=1;

	}

	if(masu[x-1][y]==1){

		masu[x][y]=0;

		func(x-1,y,now+1);

		masu[x][y]=1;

	}

	if(masu[x][y+1]==1){

		masu[x][y]=0;

		func(x,y+1,now+1);

		masu[x][y]=1;

	}

	if(masu[x][y-1]==1){

		masu[x][y]=0;

		func(x,y-1,now+1);

		masu[x][y]=1;

	}

	else {

		if(mx<now){

			mx=now;

		}

	}

}



void func2()

{

	int i,j;

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

		for(j=1;j<=m;j++){

			masu[i][j]=ice[i][j];

		}

	}

}



int main(void)

{

	int i,j;

	

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

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

			for(j=1;j<=m;j++){

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

			}

		}

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

			for(j=1;j<=m;j++){

				func2();

				if(masu[i][j]==1){

					func(i,j,1);

				}

			}

		}

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

			for(j=0;j<100;j++){

				ice[i][j]=0;

				masu[i][j]=0;

			}

		}

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

		n=0;

		m=0;

		mx=0;

	}

	

	return 0;

}

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



int masu[100][100];

int n,m;

int ans,max;



void func(int x,int y){

	masu[x][y] = 0;

	ans++;

	if(max < ans) max = ans;

	if(masu[x][y+1] == 1 && y+1<100){

		func(x,y+1);

		masu[x][y+1] = 1;

	}

	if(masu[x][y-1] == 1 && y-1>-1){

		func(x,y-1);

		masu[x][y-1] = 1;

	}

	if(masu[x+1][y] == 1 && x+1<100){

		func(x+1,y);

		masu[x+1][y] = 1;

	}

	if(masu[x-1][y] == 1 && x-1>-1){

		func(x-1,y);

		masu[x-1][y] = 1;

	}

	masu[x][y] = 1;

	ans--;

}





int main(void){

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

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

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

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

			}

		}

		

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

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

				if(masu[i][j] == 1){

					ans=0;

					func(i,j);

				}

			}

		}

		

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

		max = 0;

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

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

				masu[i][j]=0;

			}

		}

	}

	return 0;

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

#include<iostream>

#include<cstring>

#include<string>

#include<algorithm>

using namespace std;

double dp[100010];

int N,M;

double p;

int g[20][20];

#define eps 1e-6

bool jud[20];

void dfs(int n)

{

    jud[n]=true;

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

    {

        if(g[n][i]&&!jud[i])

        {

            dfs(i);

        }

    }

}

int main()

{

    int i,j,k;

    int n,m,t;

    int a,b,s;

    scanf("%d%d%lf",&N,&M,&p);

    for(i=0;i<M;i++)

    {

        scanf("%d%d",&a,&b);

        a--;b--;

        if(a==b)

        {

            i--;M--;

            continue;

        }

        g[a][b]=g[b][a]=1;

    }

    p/=100.0;

    if(p<eps)

    {

        dfs(0);

        for(i=0;i<N;i++) if(!jud[i]) break;

        if(i==N) printf("1.000000000000\n");

        else printf("0.000000000000\n");

        return 0;

    }



    if(p>1.0-eps)

    {

        if(N>1) printf("0.000000000000\n");

        else printf("1.000000000000\n");

        return 0;

    }



    for(i=0;i<N;i++) dp[(1<<i)]=1.0;

    double pp;

    for(n=1;n<(1<<N);n++)

    {

        //cout<<n<<endl;

        for(i=0;i<N;i++) if(n==(1<<i)) break;

        if(i<N) continue;

        for(a=0;a<N;a++) if(n&(1<<a)) break;

        for(b=0;b<N;b++) if((n&(1<<b))&&b!=a) break;

        for(m=n&(n-1);m;m=n&(m-1))

        {

            if(m&(1<<a)) continue;

            if(!(m&(1<<b))) continue;

            t=n&(~m);pp=1.0;

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

                if(((1<<i)&m)&&g[a][i]) pp*=p;

            pp=1.0/pp-1.0;

            dp[n]+=dp[m]*dp[t]*pp;

            //cout<<n<<"  "<<m<<"   "<<dp[n]<<endl;

        }

        //cout<<n<<"  "<<dp[n]<<endl;

    }

    for(i=0;i<M;i++) dp[(1<<N)-1]*=p;

    printf("%.12f\n",dp[(1<<N)-1]);

    return 0;

}

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

#include<cstring>

#include<cstdlib>

#include<cstring>

#include<cmath>

#define maxst 1<<20

using namespace std ;

int n , m , p , u , v ;

int r[maxst] ;

double f[maxst] ;



int main() {

	scanf("%d%d%d",&n,&m,&p) ;

	const int maxs = 1 << n;

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

		scanf("%d%d",&u,&v) ; 

		u-- ; v-- ;

		for(int j = 0 ; j < maxs ; j++) if((j&(1<<u)) && (j&(1<<v)))

		r[j]++ ;

	}

	for(int i = 1 ; i < maxs ; i++) if(i&1){

		f[i] = 1.0 ;

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

			f[i] -= f[j] * pow(p*0.01 , r[i]-r[j]-r[(~j)&i]) ;

	}

	printf("%.9f\n",f[maxs-1]) ;

	return 0 ;

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

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

using namespace std;



int n,m,p;

int a[15][15];



long double dp[1<<14];

long double tmp[1<<14][14];



long double fact[1<<14][14];







int main(void){

	cin >> n >> m >> p;

	rep(i,m){

		int u,v;

		cin >> u >> v;

		a[u-1][v-1]++;

		a[v-1][u-1]++;

	}



	rep(i,n) fact[1<<i][0]=1.0;

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

		for(int smask=(mask-1)&mask;;smask=(smask-1)&mask){

			int tmask=mask^smask;

			if(tmask>smask) break;

			rep(snum,n)rep(tnum,n) if(snum+tnum<n) fact[mask][snum+tnum+1]+=fact[smask][snum]*fact[tmask][tnum];

		}

	}

	

	// cerr << fact[3][1] << endl;

	// cerr << fact[7][2] << endl;

	// cerr << fact[15][3] << endl;



	/*

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

		fact[i]=1.0*(i+1)*i/2.0*fact[i-1]; 

		cerr << fact[i] << endl;

	}

	*/



	rep(i,n){

		rep(mask,1<<i)rep(j,i+1) tmp[mask][j]=0.0;



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

			double cur=1.0;

			rep(j,i) if(mask&(1<<j)) rep(loop,a[j][i]) cur*=1.0*p/100.0; 

			tmp[mask][0]=(1.0-cur)*dp[mask];

		}

		

		

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

			for(int smask=(mask-1)&mask;;smask=(smask-1)&mask){

				int tmask=mask^smask;

				if(tmask>smask) break;

				double cur=1.0;

				rep(j,i)rep(k,i) if((smask&(1<<j))&&(tmask&(1<<k))) rep(loop,a[j][k]) cur*=1.0*p/100.0;

				rep(snum,i+1)rep(tnum,i+1) if(snum+tnum<=i) tmp[mask][snum+tnum+1]+=cur*tmp[smask][snum]*tmp[tmask][tnum];

			}

		}



		tmp[0][0]=1.0;

		rep(mask,1<<i){

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

				// cerr << mask << " " << num << " " << tmp[mask][num] << endl;

 				dp[mask|(1<<i)]+=tmp[mask][num]/fact[(1<<(num+1))-1][num];

			}

		}



	}

	cout.precision(20);

	cout << fixed << dp[(1<<n)-1] << endl;

	// rep(mask,1<<n) cerr << mask << " " << dp[mask] << endl;

	return 0;

}

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

#define _overload(_1,_2,_3,name,...) name

#define _rep(i,n) _range(i,0,n)

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

#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define bit(x) (1<<(x))

using namespace std;



int n,m,p;

int a[15][15];



using R=long double;

R dp[1<<14];



int main(void){

	cin >> n >> m >> p;

	rep(i,m){

		int u,v;

		cin >> u >> v;

		a[u-1][v-1]++;

		a[v-1][u-1]++;

	}



	rep(mask,1,1<<n){

		dp[mask]=1.0;		

		if(__builtin_popcount(mask)==1) continue;

		int limit=bit(31-__builtin_clz(mask));

		for(int add=(mask-1)&mask;add>=limit;add=(add-1)&mask){

			int root=add^mask;

			double cur=dp[add];

			rep(i,n)rep(j,n) if(root&bit(i)) if(add&bit(j)) rep(loop,a[i][j]) cur*=1.0*p/100.0; 

			dp[mask]-=cur;	

		}

	}

	cout.precision(20);

	cout << fixed << dp[(1<<n)-1] << endl;

	return 0;

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

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

using namespace std;



int n,m,p;

int a[15][15];



long double dp[1<<14];

long double tmp[1<<14][14];



long double fact[1<<14][14];







int main(void){

	cin >> n >> m >> p;

	rep(i,m){

		int u,v;

		cin >> u >> v;

		a[u-1][v-1]++;

		a[v-1][u-1]++;

	}



	rep(i,n) fact[1<<i][0]=1.0;

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

		for(int smask=(mask-1)&mask;;smask=(smask-1)&mask){

			int tmask=mask^smask;

			if(tmask>smask) break;

			rep(snum,n)rep(tnum,n) if(snum+tnum<n) fact[mask][snum+tnum+1]+=fact[smask][snum]*fact[tmask][tnum];

		}

	}

	

	// cerr << fact[3][1] << endl;

	// cerr << fact[7][2] << endl;

	// cerr << fact[15][3] << endl;



	/*

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

		fact[i]=1.0*(i+1)*i/2.0*fact[i-1]; 

		cerr << fact[i] << endl;

	}

	*/



	rep(i,n){

		rep(mask,1<<i)rep(j,i+1) tmp[mask][j]=0.0;



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

			double cur=1.0;

			rep(j,i) if(mask&(1<<j)) rep(loop,a[j][i]) cur*=1.0*p/100.0; 

			tmp[mask][0]=(1.0-cur)*dp[mask];

		}

		

		

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

			for(int smask=(mask-1)&mask;;smask=(smask-1)&mask){

				int tmask=mask^smask;

				if(tmask>smask) break;

				double cur=1.0;

				rep(j,i)rep(k,i) if((smask&(1<<j))&&(tmask&(1<<k))) rep(loop,a[j][k]) cur*=1.0*p/100.0;

				rep(snum,i+1)rep(tnum,i+1) if(snum+tnum<=i) tmp[mask][snum+tnum+1]+=cur*tmp[smask][snum]*tmp[tmask][tnum];

			}

		}



		tmp[0][0]=1.0;

		rep(mask,1<<i){

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

				// cerr << mask << " " << num << " " << tmp[mask][num] << endl;

 				dp[mask|(1<<i)]+=tmp[mask][num]/fact[(1<<(num+1))-1][num];

			}

		}



	}

	cout.precision(20);

	cout << fixed << dp[(1<<n)-1] << endl;

	// rep(mask,1<<n) cerr << mask << " " << dp[mask] << endl;

	return 0;

}

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

#define _overload(_1,_2,_3,name,...) name

#define _rep(i,n) _range(i,0,n)

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

#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define bit(x) (1<<(x))

using namespace std;



int n,m,p;

int a[15][15];



using R=long double;

R dp[1<<14];



int main(void){

	cin >> n >> m >> p;

	rep(i,m){

		int u,v;

		cin >> u >> v;

		a[u-1][v-1]++;

		a[v-1][u-1]++;

	}



	rep(mask,1,1<<n){

		dp[mask]=1.0;		

		if(__builtin_popcount(mask)==1) continue;

		int limit=bit(31-__builtin_clz(mask));

		for(int add=(mask-1)&mask;add>=1;add=(add-1)&mask){

			int root=add^mask;

			if(add<root) break;

			double cur=dp[add];

			rep(i,n)rep(j,n) if(root&bit(i)) if(add&bit(j)) rep(loop,a[i][j]) cur*=1.0*p/100.0; 

			dp[mask]-=cur;	

		}

	}



	cout.precision(20);

	cout << fixed << dp[bit(n)-1] << endl;

	return 0;

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

#include <cstring>

#include <iostream>

#include <string>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <complex>

#include <unordered_map>

#include <unordered_set>

#include <random>

#include <cassert>

#define bitcount __builtin_popcount

#define bitctz __builtin_ctz

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;



int main()

{

	int n, m; double p;

	cin>>n>>m>>p; p/=100;

	int a[100], b[100];

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

		cin>>a[i]>>b[i]; a[i]--; b[i]--;

	}

	int ct[1<<14]={};

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

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

			if((i&(1<<a[j])) && (i&(1<<b[j]))) ct[i]++;

		}

	}

	double dp[15][1<<14]={};

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

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

		if(bitcount(i)==1) continue;

		int t=bitctz(i);

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

			if((j&(1<<t))==0) continue;

			if(j==i) continue;

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

				dp[k+1][i]+=(dp[k][i-j]*dp[1][j]*pow(p, (double)(ct[i]-ct[j]-ct[i-j])));

			}

		}

		dp[1][i]=1;

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

			dp[1][i]-=dp[k][i];

		}

	}

	printf("%.10lf\n", dp[1][(1<<n)-1]);

	return 0;

}


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

#include <cstring>

#include <iostream>

#include <string>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <complex>

#include <unordered_map>

#include <unordered_set>

#include <random>

#include <cassert>

#define bitcount __builtin_popcount

#define bitctz __builtin_ctz

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;



int main()

{

	int n, m; double p;

	cin>>n>>m>>p; p/=100;

	int a[100], b[100];

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

		cin>>a[i]>>b[i]; a[i]--; b[i]--;

	}

	int ct[1<<14]={};

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

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

			if((i&(1<<a[j])) && (i&(1<<b[j]))) ct[i]++;

		}

	}

	double dp[1<<14]={};

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

		int t=bitctz(i);

		if(i==(1<<t)) continue;

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

			if(j==i) continue;

			if((j&(1<<t))==0) continue;

			dp[i]+=((1-dp[j])*pow(p, (double)(ct[i]-ct[j]-ct[i-j])));

			

		}

	}

	printf("%.10lf\n", 1-dp[(1<<n)-1]);

	return 0;

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

#include <string>

#include <vector>

#include <cstring>

#include <climits>

#include <algorithm>

#include <map>

using namespace std;



int N, p[30], min_times;



map<int,int> rot[4] = {

    { {1, 28}, {2, 29}, {3, 30}, {15, 16}, {19, 21}, },

    { {3, 22}, {6, 25}, {9, 28}, {12, 19}, {13, 15} },

    { {7, 22}, {8, 23}, {9, 24}, {13, 18}, {10, 12} },

    { {1, 24}, {4, 27}, {7, 30}, {10, 21}, {16, 18} }

};



vector<int> group_id = {

    0, 0, 0, 0, 0, 0, 0, 0, 0,

    9, 9, 9,

    12, 12, 12,

    15, 15, 15,

    18, 18, 18,

    21, 21, 21, 21, 21, 21, 21, 21, 21

};



void rotate(int i) {

    for (auto it=rot[i].begin(); it!=rot[i].end(); ++it) {

        swap(p[it->first - 1], p[it->second - 1]);

    }

}



bool isOK() {

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

        if (p[i] != p[group_id[i]]) return false;

    }

    return true;

}



int solve(int times, int &min_times) {

    if (8 <= times || min_times <= times || isOK()) {

        min_times = min(min_times, times);

        return times;

    }

    int ret = INT_MAX;

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

        rotate(i);

        ret = min(ret, solve(times + 1, min_times));

        rotate(i);

    }

    return ret;

}



int main() {

    cin >> N;

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

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

            cin >> p[j];

        }

        min_times = INT_MAX;

        cout << solve(0, min_times) << endl;

    }

    return 0;

}

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

#include <string>

#include <vector>

#include <cstring>

#include <climits>

#include <algorithm>

#include <map>

using namespace std;



int N, p[30], min_times;



map<int,int> rot[4] = {

    { {1, 28}, {2, 29}, {3, 30}, {15, 16}, {19, 21}, },

    { {3, 22}, {6, 25}, {9, 28}, {12, 19}, {13, 15} },

    { {7, 22}, {8, 23}, {9, 24}, {13, 18}, {10, 12} },

    { {1, 24}, {4, 27}, {7, 30}, {10, 21}, {16, 18} }

};



vector<int> group_id = {

    0, 0, 0, 0, 0, 0, 0, 0, 0,

    9, 9, 9,

    12, 12, 12,

    15, 15, 15,

    18, 18, 18,

    21, 21, 21, 21, 21, 21, 21, 21, 21

};



void rotate(int i) {

    for (auto it=rot[i].begin(); it!=rot[i].end(); ++it) {

        swap(p[it->first - 1], p[it->second - 1]);

    }

}



bool isOK() {

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

        if (p[i] != p[group_id[i]]) return false;

    }

    return true;

}



int solve(int times, int &min_times) {

    if (min_times <= times || isOK()) {

        min_times = min(min_times, times);

        return times;

    } else if (times == 7) {

        return 8;

    }

    int ret = 8;

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

        rotate(i);

        ret = min(ret, solve(times + 1, min_times));

        rotate(i);

    }

    return ret;

}



int main() {

    cin >> N;

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

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

            cin >> p[j];

        }

        min_times = 8;

        cout << solve(0, min_times) << endl;

    }

    return 0;

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

#include <string>

#include <vector>

#include <cstring>

#include <climits>

#include <algorithm>

#include <map>

using namespace std;



int N, p[30], min_times;



map<int,int> rot[4] = {

    { {1, 28}, {2, 29}, {3, 30}, {15, 16}, {19, 21}, },

    { {3, 22}, {6, 25}, {9, 28}, {12, 19}, {13, 15} },

    { {7, 22}, {8, 23}, {9, 24}, {13, 18}, {10, 12} },

    { {1, 24}, {4, 27}, {7, 30}, {10, 21}, {16, 18} }

};



vector<int> group_id = {

    0, 0, 0, 0, 0, 0, 0, 0, 0,

    9, 9, 9,

    12, 12, 12,

    15, 15, 15,

    18, 18, 18,

    21, 21, 21, 21, 21, 21, 21, 21, 21

};



void rotate(int i) {

    for (auto it=rot[i].begin(); it!=rot[i].end(); ++it) {

        swap(p[it->first - 1], p[it->second - 1]);

    }

}



bool isOK() {

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

        if (p[i] != p[group_id[i]]) return false;

    }

    return true;

}



int solve(int times, int &min_times) {

    if (8 <= times || min_times <= times || isOK()) {

        min_times = min(min_times, times);

        return times;

    }

    int ret = INT_MAX;

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

        rotate(i);

        ret = min(ret, solve(times + 1, min_times));

        rotate(i);

    }

    return ret;

}



int main() {

    cin >> N;

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

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

            cin >> p[j];

        }

        min_times = INT_MAX;

        cout << solve(0, min_times) << endl;

    }

    return 0;

}

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

#include <vector>

#include <algorithm>

#include <map>

using namespace std;



int N, p[30], min_times;



map<int,int> rot[4] = {

    { {1, 28}, {2, 29}, {3, 30}, {15, 16}, {19, 21}, },

    { {3, 22}, {6, 25}, {9, 28}, {12, 19}, {13, 15} },

    { {7, 22}, {8, 23}, {9, 24}, {13, 18}, {10, 12} },

    { {1, 24}, {4, 27}, {7, 30}, {10, 21}, {16, 18} }

};



vector<int> group_id = {

    0, 0, 0, 0, 0, 0, 0, 0, 0,

    9, 9, 9,

    12, 12, 12,

    15, 15, 15,

    18, 18, 18,

    21, 21, 21, 21, 21, 21, 21, 21, 21

};



void rotate(int i) {

    for (auto it=rot[i].begin(); it!=rot[i].end(); ++it) {

        swap(p[it->first - 1], p[it->second - 1]);

    }

}



bool isOK() {

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

        if (p[i] != p[group_id[i]]) return false;

    }

    return true;

}



int solve(int times, int &min_times) {

    if (min_times <= times || isOK()) {

        min_times = min(min_times, times);

        return times;

    } else if (times == 7) {

        return 8;

    }

    int ret = 8;

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

        rotate(i);

        ret = min(ret, solve(times + 1, min_times));

        rotate(i);

    }

    return ret;

}



int main() {

    ios::sync_with_stdio(false);

    cin >> N;

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

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

            cin >> p[j];

        }

        min_times = 8;

        cout << solve(0, min_times) << endl;

    }

    return 0;

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<string>

#include<cctype>

using namespace std;

int main()

{

	int x,t;

	cin>>x>>t;

	int ans=x-t;

	if(ans>0)cout<<ans<<endl;

	else cout<<0<<endl;

	return 0;

}


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

int main()

{

    int a,b;

    scanf("%d%d",&a,&b);

    if(a>b)//还有沙子是会倒完的（不然要a干什么）

    printf("%d\n",a-b);//回车了解一下？

    else

    printf("0\n");//是0，不是空，em··· 大佬的是错的。。。

    return 0;

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

using namespace std;

int main(){

    int x,y;

    cin>>x>>y;

    if(x>y) cout<<x-y<<endl;

    else cout<<0<<endl;

    return 0;

}

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

int main()

{

    int a,b;

    scanf("%d%d",&a,&b);

    if(a>b)//还有沙子是会倒完的（不然要a干什么）

    printf("%d\n",a-b);//回车了解一下？

    else

    printf("0\n");//是0，不是空，em··· 大佬的是错的。。。

    return 0;

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

using namespace std;



int x,t;



int main()

{

	cin>>x>>t;

	if(x-t>0) cout<<x-t<<endl;

	else cout<<"0"<<endl;

	return 0;

}

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



long long n,t;



int main(void){

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

    if(n-t<=0)

        return puts("0"),0;

    printf("%lld\n",n-t);

    return 0;

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

using namespace std;

int main()

{

	int a, b, c;

	cin >> a >> b;

	c = a - b;

	if(a - b < 0)

	{

		cout << 0 << endl;

	}

	else

	{

		cout << c << endl;

	}

	return 0;

}

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

using namespace std;

int main(){int a,b;scanf("%d%d",&a,&b);if(a>b)printf("%d\n",a-b);else printf("0\n");return 0;}
// Slower C++ solution:
#include<iostream>  

using namespace std;  

int main()  

{  

    long long int x,t;  

    cin>>x>>t;  

    if(x-t==0)  

    {  

        cout<<0<<endl;  

    }  

    if(x-t>0)  

    {  

        cout<<x-t<<endl;  

    }  

    if(x-t<0)  

    {  

        cout<<0<<endl;  

    }  

    return 0;  

}  

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

int main()

{

    int x,y;

    while(~scanf("%d%d",&x,&y))

    {

        int ans;

        ans=x-y;

        if(ans>0)

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

        else

            printf("0\n");

    }

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

#define N (1<<17)

using namespace std;

typedef long long ll;



class RMQ{

public:

  ll n,dat[2*N-1];



  //?????????

  RMQ(){n=N;memset(dat,0,sizeof(dat));}

  

  //k???????????????a????????´

  void update(int k,ll a){

    k+=n-1;

    dat[k]=a;

    while(k>0){

      k=(k-1)/2;

      dat[k]=min(dat[k*2+1],dat[k*2+2]);

    }

  }



  //[a,b)???????°????????±???????

  //query(a,b,0,0,n)

  ll query(int a,int b,int k=0,int l=0,int r=N){

    if(r==-1) r=n;

    if(r<=a||b<=l)return 0;

    if(a<=l&&r<=b)return dat[k];

    else{

      ll v1=query(a,b,k*2+1,l,(l+r)/2);

      ll vr=query(a,b,k*2+2,(l+r)/2,r);

      return min(v1,vr);

    }

  }

};





ll x[N];

int main(){  

  ll n;

  cin>>n;

  RMQ rmq;

  for(int i=1;i<=n;i++) cin>>x[i];



  ll sum=n*(1+n)/2,cost=0;  

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

    ll mx=-rmq.query(1,x[i])+x[i];

    cost=max(cost,mx);

    rmq.update(x[i],-mx);

  }

  cout << sum-cost<<endl;

  return 0;

}

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

#define N (1<<17)

#define INF 0

using namespace std;

typedef long long ll;



class RMQ{

public:

  ll n,dat[2*N-1];



  //?????????

  RMQ(){

    n=N;

    for(int i=0;i<n;i++) dat[i]=INF;

  }

  

  //k???????????????a????????´

  void update(int k,ll a){

    k+=n-1;

    dat[k]=a;

    while(k>0){

      k=(k-1)/2;

      dat[k]=min(dat[k*2+1],dat[k*2+2]);

    }

  }



  //[a,b)???????°????????±??????? query(a,b,0,0,n)

  ll query(int a,int b,int k=0,int l=0,int r=N){

    if(r<=a||b<=l)return INF;

    if(a<=l&&r<=b)return dat[k];

    ll vl=query(a,b,k*2+1,l,(l+r)/2);

    ll vr=query(a,b,k*2+2,(l+r)/2,r);

    return min(vl,vr);

  }

};





int main(){  

  ll n,x[N];

  cin>>n;

  RMQ rmq;

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



  ll sum=n*(1+n)/2,ans=sum;

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

    ll mx=-rmq.query(1,x[i])+x[i];

    ans=min(ans,sum-mx);

    rmq.update(x[i],-mx);

  }

  cout <<ans<<endl;

  return 0;

}