QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344878#1061. 染色Lynkcat100 ✓119ms19240kbC++207.1kb2024-03-05 17:14:592024-03-05 17:15:00

Judging History

This is the latest submission verdict.

  • [2024-03-05 17:15:00]
  • Judged
  • Verdict: 100
  • Time: 119ms
  • Memory: 19240kb
  • [2024-03-05 17:14:59]
  • Submitted

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
const int N=100005,mod=1000000009;
int n,m,c[3][N];
int dp[N][5];
inline ll quickPower(ll x,ll y)
{
	ll res=1;
	while (y)
	{
		if (y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
namespace seg
{
	int tr[N<<2],tag[N<<2],tad[N<<2];
	void ptag(int k,int x)
	{
		if (x==1) return;
		tr[k]=tr[k]*x%mod;
		tad[k]=tad[k]*x%mod;
		tag[k]=tag[k]*x%mod;
	}
	void padd(int k,int l,int r,int x)
	{
		tr[k]=(tr[k]+x*(r-l+1)%mod)%mod;
		tad[k]=(tad[k]+x)%mod;
	}
	void pushdown(int k,int l,int r)
	{
		ptag(k<<1,tag[k]);
		ptag(k<<1|1,tag[k]);
		int mid=l+(r-l)/2;
		padd(k<<1,l,mid,tad[k]);
		padd(k<<1|1,mid+1,r,tad[k]);
		tag[k]=1;
		tad[k]=0;
	}
	void pushup(int k)
	{
		tr[k]=(tr[k<<1]+tr[k<<1|1])%mod;
	}
	void build(int k,int l,int r)
	{
		tag[k]=1;
		tad[k]=0;
		tr[k]=0;
		if (l==r) return;
		int mid=l+(r-l)/2;
		build(k<<1,l,mid);
		build(k<<1|1,mid+1,r);
	}
	void add(int k,int l,int r,int L,int R,int x)
	{
		if (L<=l&&r<=R) 
		{
			padd(k,l,r,x);
			return;
		}
		int mid=l+(r-l)/2;
		pushdown(k,l,r);
		if (L<=mid) add(k<<1,l,mid,L,R,x);
		if (R>mid) add(k<<1|1,mid+1,r,L,R,x);
		pushup(k);
		// cout<<"fuck "<<l<<" "<<r<<" "<<tr[k]<<endl;.
	}
	void add(int k,int l,int r,int L,int x)
	{
		if (l==r)
		{
			padd(k,l,r,x);
			return;
		}
		int mid=l+(r-l)/2;
		pushdown(k,l,r);
		if (L<=mid) add(k<<1,l,mid,L,x);
		else add(k<<1|1,mid+1,r,L,x);
		pushup(k);
	}
	void mul(int k,int l,int r,int L,int R,int x)
	{
		if (L<=l&&r<=R)
		{
			ptag(k,x);
			return;
		}
		int mid=l+(r-l)/2;
		pushdown(k,l,r);
		if (L<=mid) mul(k<<1,l,mid,L,R,x);
		if (R>mid) mul(k<<1|1,mid+1,r,L,R,x);
		pushup(k);
	}
	void mul(int k,int l,int r,int L,int x)
	{
		if (l==r)
		{
			ptag(k,x);
			return;
		}
		int mid=l+(r-l)/2;
		pushdown(k,l,r);
		if (L<=mid) mul(k<<1,l,mid,L,x);
		else mul(k<<1|1,mid+1,r,L,x);
		pushup(k);
	}
	int query(int k,int l,int r,int L)
	{
		if (l==r) return tr[k];
		int mid=l+(r-l)/2;
		pushdown(k,l,r);
		if (L<=mid) return query(k<<1,l,mid,L);
		return query(k<<1|1,mid+1,r,L);
	}
}
void BellaKira()
{
	cin>>n>>m;
	for (int i=1;i<=2;i++)
		for (int j=n;j>=1;j--)
			cin>>c[i][j];
	//0 ab cd
	//1 ab ad
	//2 ab ab
	//3 ab ca
	//4 ab ba
	dp[1][2]=1;
	for (int i=2;i<=n;i++)
	{
		dp[i][0]=(
			dp[i-1][0]*((m-4)*(m-5)%mod+2*(m-4)%mod+1)%mod+
			dp[i-1][1]*(m-3)%mod*(m-3)%mod*2%mod+
			dp[i-1][2]*(m-2)%mod*(m-3)%mod+
			dp[i-1][3]*(m-3)%mod*(m-3)%mod*2%mod+
			dp[i-1][4]*(m-2)%mod*(m-3)%mod)%mod;
		dp[i][1]=(
			dp[i-1][0]*(m-3)%mod+
			dp[i-1][1]*(m-2)%mod+
			dp[i-1][3]*(m-2)%mod+
			dp[i-1][3]*(m-3)%mod+
			dp[i-1][4]*(m-2)%mod)%mod;
		dp[i][2]=(
			dp[i-1][0]+
			dp[i-1][3]*2%mod+
			dp[i-1][4])%mod;
		dp[i][3]=(
			dp[i-1][0]*(m-3)%mod+
			dp[i-1][1]*(m-2)%mod+
			dp[i-1][1]*(m-3)%mod+
			dp[i-1][2]*(m-2)%mod+
			dp[i-1][3]*(m-2)%mod)%mod;
		dp[i][4]=(
			dp[i-1][0]+
			dp[i-1][1]*2%mod+
			dp[i-1][2])%mod;
	}
	int rt=0,lst=-1;
	seg::build(1,1,m);
	for (int j=1;j<=n;j++)
	{
		if (c[1][j]==0&&c[2][j]==0)
		{
			continue;
		}
		if(lst==-1)
		{
			rt++;
			lst=j;
			if (c[1][j])
			{
				if (!c[2][j]) 
				{
					for (int i=1;i<=m;i++)
						if (i!=c[1][j]) seg::add(1,1,m,i,1);
				} else 
				{
					for (int i=c[2][j];i<=c[2][j];i++)
						if (i!=c[1][j]) seg::add(1,1,m,i,1);
				}
			} else
			{
				for (int i=1;i<=m;i++)
					if (i!=c[2][j]) seg::add(1,1,m,i,1);
			}
			continue;
		}
		//0 ab cd
		//1 ab ad
		//2 ab ab
		//3 ab ca
		//4 ab ba
		int x=(c[1][lst]>0);
		int y=(c[1][j]>0);
		if (x==y)
		{
			int o=1;
			if (c[o][lst]==0) o++;
			if (c[o][lst]==c[o][j])
			{
				int mul=(dp[j-lst+1][2]-dp[j-lst+1][1]*quickPower(m-2,mod-2)%mod+mod)%mod;
				int s=seg::tr[1];
				seg::mul(1,1,m,1,m,mul);
				seg::add(1,1,m,1,m,s*dp[j-lst+1][1]%mod*quickPower(m-2,mod-2)%mod);
				seg::mul(1,1,m,c[o][j],0);
			} else
			{
				int x=c[o][lst],y=c[o][j];
				int s=seg::tr[1],ss=seg::query(1,1,m,y);
				s=(s-ss+mod)%mod;
				//ab cd && ab cb
				{
					int mul=(dp[j-lst+1][1]*quickPower(m-2,mod-2)%mod
						-dp[j-lst+1][0]*quickPower(m-2,mod-2)%mod*quickPower(m-3,mod-2)%mod+mod)%mod;
					int coef=s*dp[j-lst+1][0]%mod*quickPower(m-2,mod-2)%mod*quickPower(m-3,mod-2)%mod;
					seg::mul(1,1,m,1,m,mul);
					seg::add(1,1,m,1,m,coef);
					seg::mul(1,1,m,y,0);
					seg::mul(1,1,m,x,0);
				}
				//ab ca
				{
					int coef=s*dp[j-lst+1][3]%mod*quickPower(m-2,mod-2)%mod;
					seg::add(1,1,m,x,coef);
				}
				//ac cd
				{
					int coef=ss*dp[j-lst+1][3]%mod*quickPower(m-2,mod-2)%mod;
					seg::add(1,1,m,1,m,coef);
					seg::add(1,1,m,y,mod-coef);
					seg::add(1,1,m,x,mod-coef);
				}
				//ac ca
				{
					int coef=ss*dp[j-lst+1][4]%mod;
					seg::add(1,1,m,x,coef);
				}
			}
			if (o==1&&c[2][j])
			{
				int p=c[2][j];
				int s=seg::query(1,1,m,p);
				seg::mul(1,1,m,1,m,0);
				seg::add(1,1,m,p,p,s);
			}
		} else
		{
			int o=1;
			if (c[o][lst]==0) o++;
			if (c[o][lst]==c[3-o][j])
			{
				int mul=(dp[j-lst+1][4]-dp[j-lst+1][3]*quickPower(m-2,mod-2)%mod+mod)%mod;
				int s=seg::tr[1];
				seg::mul(1,1,m,1,m,mul);
				seg::add(1,1,m,1,m,s*dp[j-lst+1][3]%mod*quickPower(m-2,mod-2)%mod);
				seg::mul(1,1,m,y,0);
			} else
			{
				int x=c[o][lst],y=c[3-o][j];
				int s=seg::tr[1],ss=seg::query(1,1,m,y);
				s=(s-ss+mod)%mod;
				//ab cd && ab bd
				{
					int mul=(dp[j-lst+1][3]*quickPower(m-2,mod-2)%mod
						-dp[j-lst+1][0]*quickPower(m-2,mod-2)%mod*quickPower(m-3,mod-2)%mod+mod)%mod;
					int coef=s*dp[j-lst+1][0]%mod*quickPower(m-2,mod-2)%mod*quickPower(m-3,mod-2)%mod;
					seg::mul(1,1,m,1,m,mul);
					seg::add(1,1,m,1,m,coef);
					seg::mul(1,1,m,x,0);
					seg::mul(1,1,m,y,0);
				}
				//ab ad
				{
					seg::add(1,1,m,x,s*dp[j-lst+1][1]%mod*quickPower(m-2,mod-2)%mod);
				}
				//ad cd
				{
					int coef=ss*dp[j-lst+1][1]%mod*quickPower(m-2,mod-2)%mod;
					seg::add(1,1,m,1,m,coef);
					seg::add(1,1,m,x,mod-coef);
					seg::add(1,1,m,y,mod-coef);
				}
				//ad ad
				{
					int coef=ss*dp[j-lst+1][2]%mod;
					seg::add(1,1,m,x,coef);
				}
			}
			if (o==2&&c[2][j])
			{
				int p=c[2][j];
				int s=seg::query(1,1,m,p);
				seg::mul(1,1,m,1,m,0);
				seg::add(1,1,m,p,p,s);
			}
		}
		rt+=j-lst;
		lst=j;
	}
	int op=0;
	for (int i=0;i<5;i++) op=(op+dp[n-rt][i])%mod;
	for (int i=1;i<2;i++) op=(op+dp[n-rt][i])%mod;
	for (int i=3;i<4;i++) op=(op+dp[n-rt][i])%mod;
	if (rt==0) cout<<op*m%mod*(m-1)%mod<<'\n';
	else
	{
		op=0;
		for (int i=0;i<5;i++) op=(op+dp[n-rt+1][i])%mod;
		for (int i=1;i<2;i++) op=(op+dp[n-rt+1][i])%mod;
		for (int i=3;i<4;i++) op=(op+dp[n-rt+1][i])%mod;
		cout<<seg::tr[1]*op%mod<<'\n';
	}
}
signed main()
{
	IOS;
	cin.tie(0);
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}
/*
a
b
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 44
Accepted

Test #1:

score: 44
Accepted
time: 9ms
memory: 12264kb

input:

10000 9973
2926 0 0 0 2176 0 0 0 0 0 0 0 0 0 0 0 0 5892 0 0 107 0 0 0 0 0 0 0 6953 0 0 0 0 0 2120 4802 0 0 0 0 0 0 0 0 0 0 0 6476 0 0 847 0 0 0 0 0 0 0 0 0 3336 0 0 0 0 0 0 0 0 0 0 0 0 5279 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8435 0 0 0 0 0 0 0 0 0 2960 0 1565 0 0 0 742 0 1897 0 0 0 0 0 0 0 0 0 665 0 0 0 62...

output:

517694800

result:

ok single line: '517694800'

Test #2:

score: 0
Accepted
time: 6ms
memory: 12224kb

input:

10000 9967
3971 4199 4265 2901 0 0 7989 0 0 0 0 0 0 0 0 6112 0 0 0 0 0 0 0 0 2780 0 0 0 0 0 0 0 0 1818 0 0 0 0 0 0 0 0 0 0 4248 9857 0 0 0 0 4221 0 0 0 0 0 0 0 0 583 0 0 0 8748 4101 0 0 4735 0 0 0 0 0 1439 2549 0 0 0 0 0 0 0 7561 0 0 7522 0 0 0 0 8292 0 0 0 0 0 1149 0 0 0 5840 0 0 0 0 0 0 0 0 0 0 59...

output:

660134576

result:

ok single line: '660134576'

Test #3:

score: 0
Accepted
time: 8ms
memory: 10248kb

input:

10000 9949
2583 0 0 0 0 0 0 290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6489 0 0 0 7942 0 752 0 4993 0 0 0 0 0 0 0 0 0 0 0 0 4801 0 3582 0 0 0 0 9263 0 0 0 1086 0 0 0 0 0 0 0 0 0 0 0 0 0 8738 0 0 0 0 0 0 0 0 0 0 0 0 729 0 0 0 8085 0 7422 0 0 0 0 9462 0 0 0 0 0 0 0 6328 37 0 0 0 0 0 0 0 9...

output:

379398650

result:

ok single line: '379398650'

Test #4:

score: 0
Accepted
time: 9ms
memory: 12184kb

input:

10000 9941
1321 0 0 0 0 0 2682 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6517 0 0 0 0 0 5016 0 0 0 0 8111 0 0 0 0 6278 0 0 0 0 0 0 0 0 0 0 0 0 6113 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7472 0 9178 0 0 0 0 0 0 0 0 1742 0 7710 0 0 0 0 0 0 6760 200 0 0 0 0 8773 0 0 0 0 0 0 0 0 0 0 0 1300 0 0 0 0 0 2903 0 ...

output:

336132186

result:

ok single line: '336132186'

Test #5:

score: 0
Accepted
time: 9ms
memory: 12196kb

input:

10000 9931
2153 0 0 0 0 0 4461 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4225 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6072 0 0 0 0 0 8259 0 0 0 0 0 0 0 0 0 0 0 0 9341 0 0 0 9417 0 7681 3178 9725 0 0 0 0 0 0 0 0 0 5016 0 0 9282 0 0 0 8054 0 0 0 0 2156 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1943 0 0 5978 2492 0 0 0 97...

output:

779579773

result:

ok single line: '779579773'

Test #6:

score: 0
Accepted
time: 6ms
memory: 16068kb

input:

10000 9929
5447 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5069 0 9494 0 0 0 0 9413 0 0 7771 0 0 0 0 0 0 0 0 189 9434 0 0 0 0 0 0 0 0 0 0 0 2606 0 0 0 0 0 0 0 0 0 0 0 0 3575 0 803 7312 8185 0 0 0 0 0 0 7496 0 0 0 0 0 0 0 0 0 6976 1013 0 0 0 0 3623 7520 0 0 0 4603 0 6479 0 0 0 0 0 0 0 0 0 0 0 0 9152 0...

output:

463819841

result:

ok single line: '463819841'

Test #7:

score: 0
Accepted
time: 9ms
memory: 14016kb

input:

10000 9923
904 1819 0 0 0 0 0 0 0 0 0 0 0 0 3348 0 0 0 0 8856 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3855 0 0 0 0 0 0 0 5462 2713 0 0 0 0 0 0 0 0 5869 0 0 0 0 0 3992 0 0 0 0 0 0 0 0 0 0 3664 0 0 0 0 0 4234 0 0 0 0 0 0 1005 0 0 0 6784 0 2397 0 0 0 3119 0 0 0 5067 0 9095 4324 5097 0 0 0 0 0 0 0 0 0 0 0 1...

output:

37692735

result:

ok single line: '37692735'

Test #8:

score: 0
Accepted
time: 4ms
memory: 12192kb

input:

10000 9907
862 0 0 0 0 0 0 0 0 0 0 2363 4649 0 0 0 0 0 139 0 0 0 0 0 0 0 0 0 0 0 0 7768 8937 0 0 0 0 4055 0 0 0 0 1274 0 0 0 0 0 0 0 0 0 0 0 0 0 8418 0 0 0 0 0 0 0 0 0 0 0 0 9264 0 0 0 0 0 0 3391 0 925 0 0 0 0 0 0 0 0 0 0 0 0 0 9184 0 0 0 2485 0 2516 0 1621 0 0 0 704 0 0 0 0 0 0 0 2976 0 0 0 0 0 0 0...

output:

351922656

result:

ok single line: '351922656'

Test #9:

score: 0
Accepted
time: 9ms
memory: 14128kb

input:

10000 9901
9545 0 0 0 0 0 1147 9738 0 0 0 0 0 0 151 0 0 7629 0 0 0 0 1497 0 0 0 0 0 0 0 0 0 0 4547 0 0 0 0 0 8062 0 0 0 0 0 0 0 0 0 0 7209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9296 0 0 7832 0 0 0 7929 4254 0 0 0 0 9378 0 0 0 4234 0 0 0 0 0 0 0 0 0 0 2673 0 0 0 4862 0 0 0 0 0 0 0 0 0 799...

output:

683001523

result:

ok single line: '683001523'

Test #10:

score: 0
Accepted
time: 9ms
memory: 12132kb

input:

10000 9887
3001 0 0 0 0 122 0 0 0 0 0 0 0 0 0 0 0 0 0 9843 0 0 0 1723 0 6717 0 0 0 0 0 0 0 0 0 1493 0 0 0 0 0 0 0 0 2208 0 0 4879 0 0 0 7191 82 0 0 0 0 0 0 0 0 0 6192 0 0 0 0 9867 0 0 0 0 0 0 5657 0 0 0 0 0 0 0 0 0 1229 4256 0 0 188 0 0 0 0 0 0 0 6766 7290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6193 0 0 0 83...

output:

906121765

result:

ok single line: '906121765'

Test #11:

score: 0
Accepted
time: 6ms
memory: 12088kb

input:

10000 9883
8140 0 0 0 0 0 0 0 0 0 0 1329 0 0 0 4768 0 4925 108 0 0 0 0 0 0 0 0 9604 0 5870 4255 0 0 0 0 0 0 0 0 0 0 0 1807 0 0 0 0 5089 0 0 0 248 1892 0 0 0 0 0 0 3940 0 0 0 0 617 0 5924 0 0 0 0 0 0 0 0 6136 0 0 0 0 0 0 2211 4740 0 0 0 0 0 0 0 0 0 1770 0 0 0 0 0 0 5321 0 0 0 1131 0 0 2026 0 8214 173...

output:

861710884

result:

ok single line: '861710884'

Subtask #2:

score: 32
Accepted

Dependency #1:

100%
Accepted

Test #12:

score: 32
Accepted
time: 8ms
memory: 14176kb

input:

10000 9973
1553 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4736 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5331 2364 0 0 0 9824 0 0 0 6056 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6868 0 0 7045 0 0 0 0 0 0 0 0 0 0 0 0 0 1531 0 0 4240 0 0 0 5287 0 0 0 0 0 0 7852 0 0 0 945...

output:

962033160

result:

ok single line: '962033160'

Test #13:

score: 0
Accepted
time: 12ms
memory: 12196kb

input:

10000 9967
0 0 0 0 0 0 0 0 0 0 0 9703 6206 0 171 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9330 2459 0 0 0 2135 3538 0 0 0 0 0 0 0 0 7649 0 0 1867 0 0 0 0 0 0 0 0 0 0 0 0 1116 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6494 2360 0 8811 0 1883 0 0 0 0 0 0 8462 0 0 0 0 0 0 3651 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2167 0 0 0 7371 ...

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 8ms
memory: 14348kb

input:

10000 9949
9132 0 0 0 0 0 0 0 0 817 0 0 0 0 0 0 9919 0 0 0 0 0 9585 6939 0 0 0 0 0 0 0 0 1298 0 7603 0 0 0 0 0 0 0 9070 2311 0 0 0 0 0 0 0 0 0 0 2235 0 8165 0 0 0 0 0 9930 0 0 0 0 0 8638 0 0 0 0 0 0 0 0 0 0 0 2260 6115 0 0 0 1098 0 4510 9753 0 0 1051 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7216 0 0 0 1322 0 744...

output:

447371303

result:

ok single line: '447371303'

Test #15:

score: 0
Accepted
time: 8ms
memory: 16228kb

input:

10000 9941
7366 0 5716 0 0 0 3313 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5032 0 0 0 9798 5273 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7219 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7601 0 5829 0 0 0 0 0 0 8965 0 1976 0 0 3206 0 0 0 0 671 0 0 6007 0 0 0 0 0 1387 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 532 0...

output:

261688908

result:

ok single line: '261688908'

Test #16:

score: 0
Accepted
time: 9ms
memory: 12136kb

input:

10000 9931
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 781 7289 3296 0 0 0 0 0 0 0 9404 0 0 5023 0 0 0 0 0 0 0 8172 0 0 5000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6920 0 0 0 0 5838 0 0 0 0 0 0 0 0 0 5885 0 9544 0 0 0 0 7872 0 0 0 0 0 1679 0 0 0 0 0 0 0 0 0 0 0 106 0 0 0 0 0 0 8737 0 5810 0 0 9649 0 0 0 0 48...

output:

874520150

result:

ok single line: '874520150'

Test #17:

score: 0
Accepted
time: 8ms
memory: 12292kb

input:

10000 9929
493 0 0 6598 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6957 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7714 0 9750 4820 0 0 0 8986 0 0 0 2028 8552 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2597 0 0 0 0 0 0 0 0 0 0 0 0 0 4825 0 0 0 0 2170 0 1920 0 0 0 0 4666 0 0 0 0 0 0 ...

output:

603051728

result:

ok single line: '603051728'

Test #18:

score: 0
Accepted
time: 7ms
memory: 12240kb

input:

10000 9923
4913 0 0 9854 0 0 1005 0 8129 0 0 0 0 0 0 0 0 0 0 7603 0 0 0 905 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8808 0 0 0 0 6992 0 7080 3659 0 0 0 0 5751 0 0 0 0 0 0 0 0 1909 0 0 0 0 2734 0 0 0 0 0 0 0 0 3275 0 0 0 0 0 0 0 0 8357 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 272 0 0 0 0 0 0 3...

output:

629438343

result:

ok single line: '629438343'

Test #19:

score: 0
Accepted
time: 7ms
memory: 12088kb

input:

10000 9907
0 0 0 0 0 0 0 0 5990 0 0 0 0 0 0 0 0 0 0 0 5447 0 0 0 0 0 0 7249 0 0 0 0 1765 0 4833 0 0 0 0 4903 0 0 0 0 0 0 0 0 0 8088 0 3322 0 0 0 0 0 0 7429 0 0 0 0 0 0 0 0 0 0 0 0 0 0 267 0 0 1356 0 0 1503 0 0 7970 0 0 0 6280 0 0 0 0 0 0 0 0 0 0 0 2887 0 0 0 5546 0 0 495 0 0 0 0 0 0 0 0 7033 0 0 0 0...

output:

941054716

result:

ok single line: '941054716'

Subtask #3:

score: 12
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #20:

score: 12
Accepted
time: 9ms
memory: 14332kb

input:

10000 9973
3686 0 0 0 3249 0 0 5133 0 0 0 0 2398 0 0 0 0 0 0 0 0 0 9880 0 0 0 0 0 0 0 0 9308 0 0 0 0 0 0 0 0 3993 0 0 0 0 0 0 0 0 6815 0 0 0 0 0 0 0 0 0 0 0 4954 5602 0 0 1729 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3673 0 5350 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7890 0 0 0 0 0 0 4035 0 0 0 0 0 0 0 0 0 ...

output:

520486781

result:

ok single line: '520486781'

Test #21:

score: 0
Accepted
time: 8ms
memory: 16180kb

input:

10000 9967
0 0 0 0 0 3540 935 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1314 0 9498 0 0 0 0 0 0 726 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6172 0 0 379 0 0 1547 1662 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 801 0 0 0 2046 0 0 0 0 0 0 0 0 3809 0 0 0 0 0 459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

284497295

result:

ok single line: '284497295'

Test #22:

score: 0
Accepted
time: 12ms
memory: 16292kb

input:

10000 9949
9744 8940 0 0 0 0 0 0 0 0 4050 0 0 0 0 0 4227 0 0 0 0 0 0 0 0 0 4661 0 0 8476 0 0 0 0 0 0 0 4126 0 0 0 0 0 0 0 0 1578 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6673 0 6720 0 0 0 0 0 0 0 0 0 0 0 5794 0 0 0 0 0 0 0 0 3066 0 6066 0 0 0 0 261 0 0 0 0 0 3419 0 0 0 8772 0 0 0 0 0 3478...

output:

903227414

result:

ok single line: '903227414'

Subtask #4:

score: 8
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #23:

score: 8
Accepted
time: 8ms
memory: 14192kb

input:

10000 9973
0 8619 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3627 0 0 5840 3918 0 0 0 0 0 1319 0 0 0 0 0 0 0 0 8317 0 0 0 0 0 0 3524 1297 0 0 0 4673 864 0 0 0 0 5895 0 0 0 0 0 0 0 0 0 0 0 0 4390 0 0 6610 5986 421 0 0 9554 0 0 0 0 0 0 0 0 0 959 9253 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4154 0 0 0 0 0 0 0...

output:

68617449

result:

ok single line: '68617449'

Test #24:

score: 0
Accepted
time: 12ms
memory: 12136kb

input:

10000 9967
0 0 0 0 3774 6437 0 0 0 7697 0 0 1002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7923 0 0 0 0 0 0 0 0 0 0 0 0 0 8332 0 8498 0 0 0 0 0 5784 0 0 0 0 0 0 0 9633 0 0 0 2936 0 0 0 0 0 0 0 0 6963 0 0 0 0 0 5986 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6017 0 3087 0 3972 0 0 0 0 0 0 7016 0 2393 0 0 6953 0 0 0 0 0 0 0 0...

output:

828095256

result:

ok single line: '828095256'

Subtask #5:

score: 4
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 4
Accepted
time: 119ms
memory: 19240kb

input:

100000 99817
0 0 0 0 0 0 0 0 32114 0 94022 0 74011 0 0 0 0 0 0 72729 43943 0 0 53641 0 0 93458 0 0 83410 0 0 0 0 36768 0 0 48557 0 0 0 56366 0 0 0 31003 0 0 0 0 0 0 0 0 0 4222 0 0 50438 0 0 0 0 0 0 0 0 0 64001 0 0 0 0 0 0 0 0 0 0 0 5186 0 0 14559 0 0 0 0 0 0 61305 0 55342 0 60870 65953 0 0 0 0 30398...

output:

82362512

result:

ok single line: '82362512'