QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454702#8821. NightmarePhantomThresholdRE 939ms19544kbC++177.5kb2024-06-25 10:26:312024-06-25 10:26:32

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 10:26:32]
  • 评测
  • 测评结果:RE
  • 用时:939ms
  • 内存:19544kb
  • [2024-06-25 10:26:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n,mod;

inline ll ksm(ll a,ll x){
	ll ret=1;
	for (;x;x>>=1,a=a*a%mod) if (x&1) ret=ret*a%mod;
	return ret;	
}
inline ll inv(ll a){return ksm(a,mod-2);}

inline void add(ll &A,ll B){A+=B;if (A>=mod) A-=mod;}
inline void sub(ll &A,ll B){A-=B;if (A<0) A+=mod;}

struct matrix{
	ll m[505][505];
	matrix(){
		memset(m,0,sizeof(m));
	}
	void diag(){
		for (int i=1;i<=n+1;i++){
			for (int j=1;j<=n+1;j++){
				m[i][j]=(i==j);	
			}
		}
	}
	friend matrix operator * (const matrix &A,const matrix &B){
		matrix C;
		for (int i=1;i<=n+1;i++){
			for (int k=1;k<=n+1;k++){
				for (int j=1;j<=n+1;j++) (C.m[i][j]+=A.m[i][k]*B.m[k][j])%=mod;
			}
		}
		return C;
	}
	void add_row(int x,int y,ll k){
		for (int i=1;i<=n+1;i++) (m[y][i]+=m[x][i]*k)%=mod;
	}
	void add_col(int x,int y,ll k){
		for (int i=1;i<=n+1;i++) (m[i][y]+=m[i][x]*k)%=mod;
	}
	void swap_row(int x,int y){
		for (int i=1;i<=n+1;i++) swap(m[y][i],m[x][i]);
	}
	void swap_col(int x,int y){
		for (int i=1;i<=n+1;i++) swap(m[i][y],m[i][x]);
	}
	void mul_row(int x,ll k){
		for (int i=1;i<=n+1;i++) m[x][i]=m[x][i]*k%mod;
	}
	void mul_col(int x,ll k){
		for (int i=1;i<=n+1;i++) m[i][x]=m[i][x]*k%mod;
	}
	matrix turn(){
		matrix ans;
		for (int i=1;i<=n+1;i++){
			for (int j=1;j<=n+1;j++){
				ans.m[i][j]=m[j][i];
			}
		}
		return ans;
	}
	void display(){
		for (int i=1;i<=n+1;i++){
			for (int j=1;j<=n+1;j++){
				cerr << m[i][j] << " ";	
			}
			cerr << endl;
		}
	}
};

matrix G,oriG;
matrix P,Pbase;
matrix PTP;

const int maxn=1000000;
ll sq[maxn+50];
ll g=1,ig=1;
ll gx,gy;

void getg(){
	for (;g<mod;g++){
		bool flag=1;
		for (int i=1;i<mod-1;i++) if (ksm(g,i)==1){flag=0;break;}
		if (flag){
			ig=inv(g);
			for (ll i=0;i<mod;i++){
				ll j2=(g-i*i%mod+mod)%mod;
				if (sq[j2]!=-1){
					gx=i;
					gy=sq[j2];
					break;
				}
			}
			return;
		}
	}
}

int main(){
	cin >> n >> mod;
	for (int i=0;i<mod;i++) sq[i]=-1;
	for (int i=0;i<=mod/2;i++) sq[i*i%mod]=i;
	
	getg();
	
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			cin >> oriG.m[i][j];
			G.m[i][j]=oriG.m[i][j];
		}
	}
	P.diag();
	int rk=0;
	for (int i=1;i<=n;i++){
		
//		cerr << "-------stage1---------" << endl;
//		cerr << "----i : " << i << endl;
		
		if (G.m[i][i]==0){
			int pos=0;
			for (int j=i+1;j<=n;j++){
				if (G.m[j][j]!=0){
					pos=j;
					break;
				}
			}
			if (pos!=0){
				P.swap_col(i,pos);
				G.swap_row(i,pos);
				G.swap_col(i,pos);
			}	
		}
		
		if (G.m[i][i]!=0){
			ll iv=inv(G.m[i][i]);
			for (int j=i+1;j<=n;j++){
				ll coef=iv*G.m[j][i]%mod;
				P.add_col(j,i,coef);
				G.add_row(i,j,mod-coef);
				G.add_col(i,j,mod-coef);	
			}
			ll sqiv=sq[iv];
			if (sqiv==-1) sqiv=sq[iv*g%mod];
			P.mul_col(i,inv(sqiv));
			G.mul_row(i,sqiv);
			G.mul_col(i,sqiv);
		}
		else if (i<n){
			{
				int pos=0;
				for (int j=i+1;j<=n;j++) if (G.m[j][i]!=0){pos=j;break;}
				if (pos!=0){
					P.swap_col(i+1,pos);
					G.swap_row(i+1,pos);
					G.swap_col(i+1,pos);
				}
			}
			if (G.m[i+1][i]==0) continue;
			ll iv=inv(G.m[i+1][i]);
			for (int j=i+2;j<=n;j++){
				ll coef=iv*G.m[j][i]%mod;
				P.add_col(j,i+1,coef);
				G.add_row(i+1,j,mod-coef);
				G.add_col(i+1,j,mod-coef);	
			}
			for (int j=i+2;j<=n;j++){
				ll coef=iv*G.m[j][i+1]%mod;
				P.add_col(j,i,coef);
				G.add_row(i,j,mod-coef);
				G.add_col(i,j,mod-coef);	
			}
			
			if (mod!=2){
				ll i2=inv(2);
				P.add_col(i,i+1,mod-1);
				G.add_row(i+1,i,1);
				G.add_col(i+1,i,1);
				
				P.add_col(i+1,i,i2);
				G.add_row(i,i+1,mod-i2);
				G.add_col(i,i+1,mod-i2);
				
//				{
//					cerr << "mid--" << endl;
//					cerr << "G : " << endl;
//					G.display();
//					cerr << "P : " << endl;
//					P.display();
//					cerr << "PGPT : " << endl;
//					matrix tmp=P*G*P.turn();
//					tmp.display();
//				}
				
				ll sqiv=sq[inv(G.m[i][i])];
				if (sqiv==-1) sqiv=sq[inv(G.m[i][i])*g%mod];
				P.mul_col(i,inv(sqiv));
				G.mul_row(i,sqiv);
				G.mul_col(i,sqiv);
				
				sqiv=sq[inv(G.m[i+1][i+1])];
				if (sqiv==-1) sqiv=sq[inv(G.m[i+1][i+1])*g%mod];
				P.mul_col(i+1,inv(sqiv));
				G.mul_row(i+1,sqiv);
				G.mul_col(i+1,sqiv);
			}
			i++;
		}
//		{
//			cerr << "res--" << endl;
//			cerr << "G : " << endl;
//			G.display();
//			cerr << "P : " << endl;
//			P.display();
//			cerr << "PGPT : " << endl;
//			matrix tmp=P*G*P.turn();
//			tmp.display();
//		}
	}
	
	if (mod!=2){
		int rk1=0;
		for (int i=1;i<=n;i++) if (G.m[i][i]==g){
			rk1++;
			P.swap_col(i,rk1);
			G.swap_row(i,rk1);
			G.swap_col(i,rk1);	
		}
		rk=rk1;
		for (int i=rk1+1;i<=n;i++) if (G.m[i][i]==1){
			rk++;
			P.swap_col(i,rk);
			G.swap_row(i,rk);
			G.swap_col(i,rk);	
		}
		
//		cerr << "g,rk1,rk : " << g << " " << rk1 << " " << rk << endl;
//		cerr << "gx,gy : " << gx << " " << gy << endl;
//		{
//			cerr << "-------stage2---------" << endl;
//			cerr << "G : " << endl;
//			G.display();
//			cerr << "P : " << endl;
//			P.display();
//			cerr << "PGPT : " << endl;
//			matrix tmp=P*G*P.turn();
//			tmp.display();
//		}
		
		if (rk1%2==1){
			rk++;
			for (int i=1;i<=n+1;i++) P.m[i][rk]=0;
		}
		for (int i=1;i<=rk1;i+=2){
			if (i!=rk1){
				for (int j=1;j<=n;j++){
					ll tmpA=(P.m[j][i]*gx+P.m[j][i+1]*(mod-gy))%mod;
					ll tmpB=(P.m[j][i]*gy+P.m[j][i+1]*gx)%mod;
					P.m[j][i]=tmpA;
					P.m[j][i+1]=tmpB;
				}
				G.m[i][i]=G.m[i+1][i+1]=1;
			}
			else{
				for (int j=1;j<=n;j++){
					ll tmpA=(P.m[j][i]*gx+P.m[j][rk]*(mod-gy))%mod;
					ll tmpB=(P.m[j][i]*gy+P.m[j][rk]*gx)%mod;
					P.m[j][i]=tmpA;
					P.m[j][rk]=tmpB;
				}
				G.m[i][i]=1;
			}
//			{
//				cerr << "-------stage3---------" << endl;
//				cerr << "----i : " << i << endl;
//				cerr << "G : " << endl;
//				G.display();
//				cerr << "P : " << endl;
//				P.display();
//				cerr << "PGPT : " << endl;
//				matrix tmp=P*G*P.turn();
//				tmp.display();
//			}
		}
	}
	else{
		int rk1=0;
		for (int i=1;i<n;i++) if (G.m[i][i]==0 && G.m[i+1][i]==1){
			rk1+=2;
			P.swap_col(i,rk1-1);
			G.swap_row(i,rk1-1);
			G.swap_col(i,rk1-1);
			P.swap_col(i+1,rk1);
			G.swap_row(i+1,rk1);
			G.swap_col(i+1,rk1);	
		}
		rk=rk1;
		for (int i=rk1+1;i<=n;i++) if (G.m[i][i]==1){
			rk++;
			P.swap_col(i,rk);
			G.swap_row(i,rk);
			G.swap_col(i,rk);	
		}
//		assert(!(rk1==rk && rk==n));
		
//		cerr << "-----------------" << endl;
//		cerr << "G : " << endl;
//		G.display();
//		cerr << "P : " << endl;
//		P.display();
//		cerr << "PGPT : " << endl;
//		matrix tmp=P*G*P.turn();
//		tmp.display();
		
		rk=max(rk,rk1+1);
		if (G.m[rk][rk]==0){
			for (int i=1;i<=n+1;i++) P.m[i][rk]=0;
		}
		for (int i=1;i<=rk1;i+=2){
			for (int j=1;j<=n;j++){
				ll A=P.m[j][i];
				ll B=P.m[j][i+1];
				ll C=P.m[j][rk];
				
				P.m[j][i]=(A+C)%mod;
				P.m[j][i+1]=(A+B+C)%mod;
				P.m[j][rk]=(B+C)%mod;
			}
			G.swap_row(i+1,i);
		}
	}
	
	for (int i=1;i<=n;i++){
		for (int j=rk+1;j<=n+1;j++){
			P.m[i][j]=0;
		}
	}
	for (int i=1;i<=n+1;i++) P.m[n+1][i]=0;
	
	cout << rk << "\n";
	for (int i=1;i<=n;i++){
		for (int j=1;j<=rk;j++){
			cout << P.m[i][j] << " \n"[j==rk];
		}
	}
	
//	cerr << "------check---------" << endl;
	PTP=P*P.turn();
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (PTP.m[i][j]!=oriG.m[i][j]){
				assert(0);	
			}
		}
	}
//	PTP.display();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 19428kb

input:

2 2
1 1
1 1

output:

1
1
1

result:

ok accepted

Test #2:

score: 0
Accepted
time: 0ms
memory: 18452kb

input:

3 5
4 4 3
4 4 3
3 3 2

output:

2
3 0
3 0
1 1

result:

ok accepted

Test #3:

score: 0
Accepted
time: 926ms
memory: 19344kb

input:

500 2
1 0 1 1 1 1 1 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #5:

score: 0
Accepted
time: 939ms
memory: 17708kb

input:

500 2
0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 ...

output:

494
1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #6:

score: 0
Accepted
time: 922ms
memory: 18536kb

input:

500 2
0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #8:

score: 0
Accepted
time: 939ms
memory: 19216kb

input:

500 2
0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 0 0 ...

output:

497
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #9:

score: 0
Accepted
time: 932ms
memory: 18828kb

input:

500 2
0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 1 0 1 1 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 1 0 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result:

ok accepted

Test #11:

score: 0
Accepted
time: 919ms
memory: 19544kb

input:

500 2
0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 0 0 1 1 1 1 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 ...

output:

435
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #12:

score: 0
Accepted
time: 926ms
memory: 17688kb

input:

500 2
0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 0 0 1 0 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 ...

output:

455
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #13:

score: 0
Accepted
time: 936ms
memory: 18876kb

input:

500 2
0 1 1 0 0 0 1 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 1 ...

output:

493
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #14:

score: 0
Accepted
time: 930ms
memory: 18140kb

input:

500 2
0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #16:

score: 0
Accepted
time: 926ms
memory: 18596kb

input:

500 2
0 0 1 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 0 1 1 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 ...

output:

449
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #17:

score: 0
Accepted
time: 934ms
memory: 19168kb

input:

500 2
0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 1 0 0 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 1 0 0 1 1 ...

output:

451
0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok accepted

Test #18:

score: -100
Runtime Error

input:

500 586939
348375 543104 2613 525830 529938 63001 57038 406207 446773 47968 73017 238901 268124 473469 570747 217880 286012 142821 179125 504343 438813 105553 332560 137383 123166 585260 335875 279206 541274 318826 12120 49682 487559 275080 491437 102596 71097 184988 184272 439469 251082 388754 2144...

output:


result: