QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#501043#9159. 登山Flamire#0 1973ms493976kbC++203.8kb2024-08-02 11:38:542024-08-02 11:38:55

Judging History

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

  • [2024-08-02 11:38:55]
  • 评测
  • 测评结果:0
  • 用时:1973ms
  • 内存:493976kb
  • [2024-08-02 11:38:54]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
#define s1 first
#define s2 second
#define N 100011
#define M N*100
using namespace std;
int t,n;const int p=998244353;
vector<int> G[N];
vector<pii> E[M];
vector<int> anc;
int sz;
int lc[M],rc[M],sum[M];
void insert(int u,int v,int w){/*printf("%d %d %d\n",u,v,w);*/if(w)E[v].push_back({u,w});}
void pushup(int x){sum[x]=sum[lc[x]]+sum[rc[x]];}
int merge(int x,int y,int L,int R)
{//printf("merge(%d,%d,[%d,%d])\n",x,y,L,R);
	if(!x||!y)return x^y;
	if(L==R){int z=++sz;lc[z]=rc[z]=0;sum[z]=sum[x]+sum[y];insert(z,n+anc[L],sum[z]);return z;}
	int z=++sz;lc[z]=rc[z]=sum[z]=0;
	lc[z]=merge(lc[x],lc[y],L,L+R>>1);if(lc[z])insert(z,lc[z],1);
	rc[z]=merge(rc[x],rc[y],(L+R>>1)+1,R);if(rc[z])insert(z,rc[z],1);
	pushup(z);return z;
}
int query(int l,int r,int L,int R,int x)
{
	if(!x)return 0;
	if(l<=L&&R<=r)return sum[x];int ans=0;
	if(l<=L+R>>1)ans+=query(l,r,L,L+R>>1,lc[x]);if(r>L+R>>1)ans+=query(l,r,(L+R>>1)+1,R,rc[x]);return ans;
}
void add(int k,int v,int L,int R,int x,int &c)
{
	if(k<L||k>R||!v)return;
	c=++sz;lc[c]=lc[x];rc[c]=rc[x];sum[c]=sum[x];//printf("add(%d,%d,[%d,%d],%d,%d)\n",k,v,L,R,x,c);
	if(L==R){sum[c]+=v;insert(c,n+anc[L],sum[c]);return;}
	if(k<=L+R>>1)add(k,v,L,L+R>>1,lc[x],lc[c]);
	else add(k,v,(L+R>>1)+1,R,rc[x],rc[c]);
	if(lc[c])insert(c,lc[c],1);
	if(rc[c])insert(c,rc[c],1);
	pushup(c);
}
int prune(int x,int k,int L,int R)
{//printf("prune(%d,%d,[%d,%d])\n",x,k,L,R);
	if(k<L)return 0;
	if(k>=R)return x;
	if(!x||L==R)return x;
	int z=++sz;lc[z]=rc[z]=0;
	if(k<=L+R>>1)lc[z]=prune(lc[x],k,L,L+R>>1);
	else lc[z]=lc[x],rc[z]=prune(rc[x],k,(L+R>>1)+1,R);pushup(z);
	return z;
}
void print(int u,int x,int L,int R)
{
	if(!x)return;
	if(L==R){printf("node %d to anc %d w:%d\n",u,anc[L],sum[x]);return;}
	print(u,rc[x],(L+R>>1)+1,R);
	print(u,lc[x],L,L+R>>1);
}
int l[N],r[N],h[N],fa[N],dep[N],rt[N];
void dfs(int u,int F)
{//printf("=============dfs(%d,%d)\n",u,F);
	anc.push_back(u);
	dep[u]=dep[F]+1;
	if(F)insert(n+u,n+F,1);//,printf("%d %d %d\n",n+F,n+u,1);
	insert(n+u,u,1);
	for(int v:G[u])if(v^F)
	{
		dfs(v,u);//printf("merge %d->%d\n",v,u);
		rt[u]=merge(rt[u],rt[v],0,n);
		// printf("rt[%d]:%d\n",u,rt[u]);
	}
	// print(u,rt[u],0,n);
	int sp=query(dep[u]-h[u],n,0,n,rt[u]);//printf("sp:%d\n",sp);
	rt[u]=prune(rt[u],dep[u]-h[u]-1,0,n);
	add(dep[u]-h[u]-1,sp,0,n,rt[u],rt[u]);
	int L=dep[u]-r[u],R=min(dep[u]-l[u],dep[u]-h[u]-1);
	// printf("u:%d able dep:[%d,%d] sp:%d rt:%d\n",u,L,R,sp,rt[u]);
	// printf("after merge:\n");
	// print(u,rt[u],0,n);
	if(L<=R)
	{
		add(L-1,-1,0,n,rt[u],rt[u]);
		add(R,1,0,n,rt[u],rt[u]);
	}
	if(!rt[u])rt[u]=++sz,lc[rt[u]]=rc[rt[u]]=sum[rt[u]]=0;
	insert(u,rt[u],1);
	// print(u,rt[u],0,n);
	// printf("final root of %d: %d\n",u,rt[u]);
	anc.pop_back();
}
int in[M],f[M];
queue<int> q;
int main()
{
	scanf("%*d%d",&t);while(t--)
	{//printf("==============================================================================================\n");
		scanf("%d",&n);
		for(int i=1;i<=n;++i)G[i].clear(),rt[i]=0;
		for(int i=0;i<=sz;++i)E[i].clear(),in[i]=0,f[i]=0;sz=2*n;
		dep[0]=-1;
		for(int i=2;i<=n;++i)
		{
			scanf("%d%d%d%d",fa+i,l+i,r+i,h+i);G[fa[i]].push_back(i);
		}
		dfs(1,0);
		for(int i=1;i<=sz;++i)for(auto [v,w]:E[i])++in[v];
		while(!q.empty())q.pop();
		for(int i=1;i<=sz;++i)if(!in[i])q.push(i);
		f[1]=1;
		while(!q.empty())
		{
			int u=q.front();q.pop();//printf("====u:%d f:%d\n",u,f[u]);
			for(auto [v,w]:E[u])
			{
				// printf("%d<-%d %d\n",u,v,w);
				f[v]=(f[v]+1ll*w*f[u])%p;
				if(!--in[v])q.push(v);
			}
		}
		// printf("f:");for(int i=1;i<=sz;++i)printf("%d ",f[i]);putchar(10);
		for(int i=2;i<=n;++i)printf("%d ",(f[i]%p+p)%p);putchar(10);
		// printf("sz:%d\n",sz);
	}
	fclose(stdin);fclose(stdout);return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests

Pretest #1:

score: 5
Accepted
time: 9ms
memory: 9940kb

input:

1
4
6
1 1 1 0
1 1 1 0
3 1 2 1
3 2 2 0
4 2 3 1
6
1 1 1 0
2 1 2 0
2 1 2 0
1 1 1 0
4 1 2 2
6
1 1 1 0
1 1 1 0
3 1 2 1
4 2 2 0
3 1 1 0
6
1 1 1 0
1 1 1 0
3 1 1 0
4 2 3 1
2 1 2 0

output:

1 4 2 1 5 
3 4 4 1 0 
1 2 1 2 2 
2 2 5 3 3 

result:

ok 20 numbers

Pretest #2:

score: 0
Wrong Answer
time: 12ms
memory: 14600kb

input:

2
4
300
1 1 1 0
2 1 2 1
3 1 3 1
1 1 1 0
3 1 3 0
4 2 2 3
7 1 2 0
8 2 2 2
7 1 3 4
7 3 4 4
11 1 6 1
12 1 3 5
10 2 5 5
13 1 5 4
13 4 7 2
15 8 8 8
16 8 9 4
15 1 9 6
18 4 5 6
19 3 8 8
18 5 10 2
19 3 7 5
23 5 7 6
22 6 8 10
23 4 7 3
24 1 4 6
24 8 12 9
28 7 11 8
26 1 9 7
28 1 3 1
29 2 5 0
32 1 6 4
30 5 12 7
...

output:

19 18 35 1 38 0 35 0 0 15 334 261 0 525 165 0 93 490 0 0 88 557 378 0 754 0 378 550 144 935 5966 2975 124 1928 1188 1875 37 265 1188 3734 19 0 211 0 19 1120 34015 13731 44783 28479 17587 4843 10820 7310 0 26004 12732 7398 393 2684 0 21404 14801 1188 7787 12473 0 16743 40956 150757 163880 9 0 403 189...

result:

wrong answer 6th numbers differ - expected: '15', found: '0'

Pretest #3:

score: 0
Wrong Answer
time: 4ms
memory: 10972kb

input:

3
4
300
1 1 1 0
2 1 2 1
3 3 3 0
2 1 2 1
3 1 3 1
3 1 3 0
4 1 4 1
6 4 4 2
9 3 5 1
7 3 4 2
10 2 5 4
12 1 5 2
11 1 3 2
12 3 6 6
13 6 6 3
13 3 8 0
14 3 5 0
16 3 5 5
16 6 9 5
20 2 7 3
20 3 7 9
21 7 9 2
23 3 4 8
21 4 9 6
24 11 12 2
25 3 4 1
27 7 13 5
26 1 8 3
29 2 4 6
29 6 15 14
29 5 5 10
32 6 10 11
30 1 9...

output:

20 18 40 1 233 80 39 212 229 41 190 5094 56 0 4147 713 118 0 4129 5124 0 3313 0 947 2137 9179 903 21496 0 1 0 0 2811 52233 37263 45751 10105 25021 45440 3214 0 0 82668 44365 27652 38 0 243556 23912 1787 59835 13400 22226 13513 0 3370 21807 0 24275 36199 27308 740 0 0 26444 0 942 256 1322 78677 23633...

result:

wrong answer 23rd numbers differ - expected: '2850', found: '0'

Pretest #4:

score: 0
Wrong Answer
time: 63ms
memory: 27856kb

input:

4
4
5000
1 1 1 0
1 1 1 0
1 1 1 0
4 1 2 0
5 2 3 2
5 1 3 1
6 2 3 2
6 2 3 1
8 3 5 4
8 4 5 3
11 2 4 4
11 1 3 3
11 5 6 3
12 1 1 6
15 1 5 3
15 1 6 6
17 5 6 5
17 6 8 4
18 7 9 3
19 1 10 3
19 2 4 7
20 1 9 3
23 8 11 7
22 2 5 4
23 7 8 1
24 1 9 8
26 9 11 7
28 8 10 13
29 1 11 3
30 9 9 14
31 11 15 4
32 8 16 8
31 ...

output:

1 1 28 83 25 29 108 111 1 79 0 0 29 21 133 133 533 381 1206 324 0 1091 352 0 423 108 236 20 3555 384 2821 2526 2114 0 0 1427 7220 3489 0 1211 18905 0 26576 0 25062 28 17632 0 4234 9909 0 17904 18095 82897 982 13263 124202 208 25358 24881 114267 164506 110168 3855 9660 3967 1818 0 0 206645 51638 9982...

result:

wrong answer 11th numbers differ - expected: '21', found: '0'

Pretest #5:

score: 0
Wrong Answer
time: 69ms
memory: 34288kb

input:

5
4
5000
1 1 1 0
1 1 1 0
1 1 1 0
2 1 2 0
3 1 1 1
4 1 1 0
6 1 3 2
7 1 3 1
8 2 2 0
8 1 3 2
11 3 5 1
10 1 5 4
13 1 2 4
12 3 4 3
15 3 5 2
15 2 6 2
15 1 3 3
16 7 7 3
19 1 7 4
18 2 3 4
20 1 10 5
21 2 3 8
21 4 9 6
22 7 9 3
24 2 6 8
25 1 3 4
25 3 4 1
26 3 4 3
29 5 11 9
28 8 11 12
29 7 9 11
32 5 12 5
32 11 1...

output:

2 35 2 3 0 5 34 3 1 277 242 1 0 206 1315 346 0 1004 969 0 658 0 100 311 64 0 1973 64 35 0 29 794 1559 0 1523 0 0 1487 0 3443 1648 70 34 725 725 1099 9246 463 0 9086 7022 548 7728 14535 3239 1001 4066 3545 10126 6482 0 4416 7894 7405 795 18271 15035 3030 794 36 2824 64 3024 157 7099 3280 2875 1348 58...

result:

wrong answer 5th numbers differ - expected: '34', found: '0'

Pretest #6:

score: 0
Time Limit Exceeded

input:

6
4
100000
1 1 1 0
2 1 1 0
3 1 1 0
4 2 2 0
5 1 1 0
6 2 2 0
7 6 6 0
8 3 3 0
9 6 6 0
10 8 8 0
11 6 6 0
12 12 12 0
13 11 11 0
14 2 2 0
15 2 2 0
16 2 2 0
17 9 9 0
18 1 1 0
19 4 4 0
20 18 18 0
21 13 13 0
22 20 20 0
23 3 3 0
24 21 21 0
25 8 8 0
26 11 11 0
27 11 11 0
28 3 3 0
29 21 21 0
30 1 1 0
31 27 27 0...

output:

7 90 1343 13340 200010 2186770 17480820 279693113 800242414 420706509 214087588 358274752 946289212 530647994 955227776 663050301 438245147 621009062 780623708 80919478 728275212 743623748 978006196 735181462 256088384 612217572 335562169 696082683 110948988 53450390 637356472 107616671 988788196 54...

result:


Pretest #7:

score: 0
Time Limit Exceeded

input:

7
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
3 1 1 0
1 1 1 0
3 1 1 0
7 1 1 0
6 1 1 0
9 2 2 0
6 1 1 0
6 1 1 0
7 2 2 0
9 2 2 0
11 1 1 0
11 2 2 0
14 4 4 0
12 1 1 0
16 3 3 0
15 1 1 0
17 3 3 0
20 5 5 0
18 4 4 0
20 2 2 0
19 2 2 0
22 5 5 0
22 2 2 0
22 3 3 0
23 5 5 0
27 7 7 0
26 6 6 0
27 5 5 0
31 1 1 0
33 9 9 0
34 2 ...

output:

1 1 1 1 31 2 2 94 31 1298 33 1 0 41443 62 95 35 93 1490650 94 49108564 2 41443 62 31502098 1491949 41443 1 1 882058713 1298 808538694 31503398 808538694 808538695 53283330 1298 31502098 1 31502098 319947267 916183216 360370658 1534689 1298 41443 916141773 41443 518136386 1298 972986764 32 692353085 ...

result:


Pretest #8:

score: 0
Wrong Answer
time: 1959ms
memory: 493976kb

input:

8
4
100000
1 1 1 0
2 2 2 0
3 3 3 0
4 4 4 2
5 2 2 1
6 6 6 0
7 2 2 0
8 7 7 3
9 4 4 3
10 1 1 4
11 3 3 0
12 8 8 11
13 13 13 7
14 5 5 10
15 8 8 11
16 14 14 5
17 9 9 2
18 17 17 7
19 3 3 1
20 1 1 9
21 14 14 5
22 5 5 17
23 8 8 14
24 8 8 9
25 24 24 7
26 24 24 7
27 17 17 8
28 27 27 27
29 26 26 6
30 17 17 14
3...

output:

12 23 22 21 42 20 61 19 49 0 26 7 77 0 0 998244288 133 998244265 998244288 0 102 0 0 0 41 29 6 6 998244113 77 0 998244306 0 998244306 41 0 0 0 65 0 16 81 0 0 0 69 998244313 48 0 169 67 0 67 67 0 19 0 0 28 0 0 998244271 6 0 0 0 0 0 0 0 0 0 0 0 0 0 32 16 16 0 272 333 266 266 0 133 133 0 133 69 0 0 0 0...

result:

wrong answer 6th numbers differ - expected: '62', found: '20'

Pretest #9:

score: 0
Wrong Answer
time: 1878ms
memory: 473696kb

input:

9
4
100000
1 1 1 0
2 2 2 0
2 1 1 1
2 2 2 1
1 1 1 0
6 1 1 1
3 1 1 0
6 1 1 0
7 1 1 2
6 2 2 0
8 3 3 2
9 1 1 1
9 1 1 0
12 5 5 2
14 1 1 3
13 4 4 3
13 1 1 3
14 3 3 3
17 5 5 2
19 1 1 0
18 3 3 3
22 3 3 5
23 1 1 0
21 5 5 3
22 4 4 4
23 7 7 2
24 6 6 3
25 2 2 1
29 6 6 7
29 8 8 3
31 8 8 7
32 6 6 5
31 5 5 7
31 2 ...

output:

4 6 0 1 23 0 11 44 0 1 5 0 62 1 0 2 0 18 1 220 0 0 44 202 0 1 44 399 0 179 23 18 0 399 0 0 0 155 0 261 0 701 220 0 660 816 23 417 269 0 148 0 225 0 85 0 0 601 62 399 816 0 0 0 40 220 2116 0 0 0 0 2115 18 650 0 0 1875 502 2136 417 0 0 1476 0 0 62 18 1015 62 345 0 1320 0 660 0 283 0 491 0 0 4473 0 213...

result:

wrong answer 12th numbers differ - expected: '3', found: '0'

Pretest #10:

score: 0
Time Limit Exceeded

input:

10
4
100000
1 1 1 0
2 2 2 0
3 3 3 0
4 2 2 0
5 2 4 0
6 1 3 0
7 2 4 0
8 3 8 0
9 1 6 0
10 4 6 0
11 2 9 0
12 2 3 0
13 1 13 0
14 4 12 0
15 1 9 0
16 7 13 0
17 10 17 0
18 17 17 0
19 10 11 0
20 2 13 0
21 9 11 0
22 15 18 0
23 9 22 0
24 4 6 0
25 21 22 0
26 9 16 0
27 18 27 0
28 4 16 0
29 13 24 0
30 1 5 0
31 5 ...

output:

27 1160 73079 5773240 508043960 401903691 408194108 913457210 404309453 850776989 162033550 491800762 693950334 88591672 90581013 261837127 124549390 607776285 954584563 426982262 910735533 125508942 301425049 369545791 349157696 256736908 276834134 449249498 408190411 362993320 980271019 745442146 ...

result:


Pretest #11:

score: 0
Time Limit Exceeded

input:

11
4
100000
1 1 1 0
1 1 1 0
2 1 2 0
1 1 1 0
2 1 2 0
6 1 3 0
5 1 2 0
7 2 3 0
6 2 2 0
8 1 3 0
9 2 3 0
9 3 5 0
10 2 4 0
13 2 4 0
12 4 6 0
13 1 6 0
16 1 4 0
18 6 7 0
18 2 4 0
20 1 6 0
21 2 9 0
20 1 3 0
23 1 4 0
22 1 8 0
24 10 10 0
23 3 5 0
24 3 11 0
26 8 11 0
27 1 9 0
30 2 11 0
28 12 12 0
32 4 8 0
32 9 ...

output:

41 1 42 3 3401 407995 8 65275757 41 12 30977333 131377791 3443 65687153 608294415 197064986 558803128 3442 391883539 973952531 292262895 548293486 864139803 925368887 65687235 614731260 251165603 65687194 646118904 822181649 995485114 956758427 65275757 656989819 750355997 665993179 321752162 199743...

result:


Pretest #12:

score: 0
Time Limit Exceeded

input:

12
4
100000
1 1 1 0
1 1 1 0
3 1 2 0
3 1 2 0
4 1 1 0
4 1 3 0
6 2 4 0
7 2 4 0
9 1 4 0
8 1 3 0
11 3 3 0
11 5 6 0
12 1 2 0
14 3 3 0
13 2 7 0
16 2 3 0
17 2 4 0
17 7 9 0
17 3 8 0
20 2 6 0
21 10 11 0
21 6 11 0
21 7 9 0
23 3 4 0
24 5 11 0
26 6 9 0
26 5 7 0
27 12 13 0
29 10 10 0
28 1 3 0
31 13 15 0
32 7 13 0...

output:

1 44 3430 45 363401 10424 49055705 17373 31271 763087444 528293936 364247389 57980118 763087444 558370737 701077016 687461217 3475 530193136 875194506 45 812510025 587072521 233025799 902397684 501363487 984008256 763090918 763087444 553932106 460519388 415423761 485110453 526953701 435687917 459461...

result:


Pretest #13:

score: 0
Time Limit Exceeded

input:

13
4
100000
1 1 1 0
2 1 2 0
3 2 2 2
4 2 4 1
5 1 2 4
6 4 6 2
7 1 6 4
8 6 6 5
9 5 8 8
10 6 6 1
11 8 11 5
12 8 11 1
13 4 8 6
14 4 7 1
15 11 15 5
16 1 1 10
17 6 9 7
18 8 16 2
19 2 9 10
20 6 20 7
21 12 14 11
22 9 14 14
23 6 7 22
24 12 14 11
25 20 20 21
26 10 20 0
27 19 26 8
28 21 23 12
29 4 13 23
30 15 2...

output:

28 55 26 109 25 246 162 79 24 1161 1052 1188 970 2125 699 480 1822 2880 993 4442 286 0 21 3699 298 9538 1352 622 0 189 1481 1505 15694 21491 0 834 4018 0 968 14473 725 23023 12855 16039 0 25480 2908 54244 1211 2458 139706 113568 998215367 47785 0 998220973 43652 52789 619 69546 8518 22779 244 26375 ...

result:


Pretest #14:

score: 0
Time Limit Exceeded

input:

14
4
100000
1 1 1 0
2 1 1 1
1 1 1 0
2 1 2 1
4 2 2 1
5 2 2 1
7 1 4 1
8 2 5 3
8 5 5 3
10 2 3 5
11 1 6 5
10 1 4 5
12 5 8 1
12 3 6 5
13 3 6 2
15 2 5 8
17 6 7 6
18 6 8 5
17 10 10 1
18 4 5 5
20 4 11 7
22 8 9 4
23 9 13 12
24 9 13 10
24 6 8 7
26 3 13 13
26 11 14 11
28 11 11 2
27 9 16 8
30 6 12 0
31 13 17 16...

output:

38 0 2 37 1 150 149 39 34 33 109 0 226 69 374 32 300 333 407 0 406 329 30 225 629 371 225 34 2558 1345 255 1576 551 1826 576 0 0 2943 15663 243 8769 1739 1414 6727 178 963 737 0 2057 0 20297 30947 1785 13198 28743 11375 1 17441 174 39 24 5516 67199 48627 84824 4377 550 914 64321 14082 5825 67743 327...

result:


Pretest #15:

score: 0
Time Limit Exceeded

input:

15
4
100000
1 1 1 0
1 1 1 0
3 1 1 1
3 2 2 0
4 1 2 0
5 1 1 2
2 1 2 0
3 1 2 0
7 3 3 1
9 3 3 1
8 1 2 1
10 1 5 1
8 2 3 0
9 1 2 1
11 3 3 3
14 1 2 2
15 1 3 1
15 2 4 0
15 1 4 3
17 3 4 2
19 5 5 2
21 4 6 4
21 6 6 2
24 2 4 6
24 3 7 4
22 3 4 0
23 1 5 5
23 5 6 6
26 2 8 3
30 5 9 8
27 4 6 1
27 3 7 2
31 6 8 7
32 5...

output:

8 69 0 2 69 1 63 1791 141 1 8 73 46 1720 0 37 1860 60684 1 226 58823 9 146 0 145 61839 0 0 156 1 12531 174327 63 8951 66055 64195 110062 119507 3581 108201 1720 0 0 102970 44147 1037880 3580 507881 247967 119507 64264 0 329427 38565 0 3580 0 123018 974961 21482 0 1860 209989 2503246 0 3581 4730434 2...

result:


Pretest #16:

score: 0
Time Limit Exceeded

input:

16
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
4 1 1 1
1 1 1 0
2 1 2 0
7 2 3 2
3 2 2 0
6 2 2 0
8 2 3 0
11 1 5 1
11 2 5 3
11 3 3 4
14 2 6 2
14 2 3 0
12 2 3 0
12 4 5 0
16 3 7 1
19 3 7 2
18 3 4 2
21 2 4 0
22 1 3 0
21 1 6 6
21 4 5 3
21 1 7 4
23 1 10 2
26 1 6 4
23 9 10 0
25 7 8 1
25 3 9 2
27 9 11 3
29 4 11 7
33 2 6...

output:

55 2 1 0 2 109 53 1 1 2332 2110 56 2 218 7486 2385 749 5101 2551 13335 38458 71725 0 5359 270 18909 2385 274 424 5409 165 218 749 0 260 0 0 18579 4059 43 129458 0 257418 0 129950 42 124267 0 30020 94436 24829 7942 61763 5409 0 39 12874 164 24707 14084 82541 26899 4604 66347 46135 290674 23898 169418...

result:


Pretest #17:

score: 0
Time Limit Exceeded

input:

17
4
100000
1 1 1 0
2 2 2 0
1 1 1 0
1 1 1 0
5 1 2 1
5 1 2 1
6 2 2 2
7 1 1 0
8 1 1 3
8 3 4 2
6 1 3 2
9 2 4 1
8 4 4 0
11 1 4 2
10 3 3 1
11 2 5 0
14 2 3 0
17 4 4 2
14 3 4 4
17 1 4 2
19 2 6 6
17 1 1 5
18 1 5 3
23 3 7 2
22 2 3 7
24 4 6 3
23 1 7 4
23 7 7 5
27 5 6 2
26 6 9 5
28 1 7 4
30 1 9 5
29 2 6 6
29 4...

output:

2 1 1 54 51 2 49 59 0 209 1 57 468 105 51 351 467 52 0 100 0 44 367 364 1 409 211 852 255 155 154 155 54 5015 154 0 4739 819 9514 2036 1610 1185 106 525 1728 5346 54 0 154 4588 1065 560 4109 0 11001 23517 2447 0 714 663 0 10864 660 0 12080 60655 0 258 10459 0 18421 38361 11890 0 0 11835 12395 59306 ...

result:


Pretest #18:

score: 0
Time Limit Exceeded

input:

18
4
100000
1 1 1 0
2 1 2 1
2 1 2 0
2 1 2 0
3 3 3 1
5 1 3 1
4 2 3 2
7 1 3 1
8 2 4 0
9 1 4 1
8 2 3 3
12 2 5 3
9 2 3 2
11 1 1 1
11 2 4 1
14 1 6 2
15 7 7 0
17 2 4 4
18 6 7 1
17 2 6 6
17 5 5 1
20 2 5 7
22 1 7 3
23 6 10 7
25 4 4 6
25 8 11 7
26 2 10 3
26 6 7 6
27 12 12 2
28 1 1 0
29 8 11 11
32 3 9 12
30 2...

output:

60 2 64 1193 1 1132 3 10615 125 6733 1 61 4893 0 12940 5964 2023 0 2022 0 1192 769 13000 5541 13586 4712 23718 6733 19674 23718 0 646 0 19673 0 115978 21696 62476 95172 1132 0 2022 61 64438 6733 44705 1254 26001 9948 0 8695 0 26466 15487 302923 6733 12940 30087 19311 8390 114241 0 13001 85751 19734 ...

result:


Pretest #19:

score: 0
Time Limit Exceeded

input:

19
4
100000
1 1 1 0
1 1 1 0
2 1 1 1
4 1 3 1
1 1 1 0
6 2 2 1
5 2 2 1
6 1 1 0
5 2 3 1
9 1 3 0
10 1 5 3
11 2 4 1
10 2 5 2
13 1 2 2
15 1 3 0
16 1 3 1
16 3 4 6
14 6 6 0
18 6 6 1
19 1 7 2
21 6 6 4
20 9 9 3
21 1 4 5
22 4 8 7
24 2 9 8
26 7 8 0
25 1 2 8
28 1 9 8
26 2 5 3
30 2 2 1
27 9 9 3
30 4 9 2
29 3 7 8
3...

output:

38 1 37 873 5 1 37 18 982 48 39 24 868 0 96 24 0 716 19 2646 712 1 0 675 3 947 637 859 18170 3 37 19232 6060 151 7113 13110 36370 16231 8722 66351 19325 6872 9675 114089 56241 6005 7109 6163 445 12315 6599 4843 6122 67988 4670 7744 9044 704 21503 3514 53966 0 5617 13319 16959 637 1931 12025 0 0 5386...

result:


Pretest #20:

score: 0
Time Limit Exceeded

input:

20
4
100000
1 1 1 0
2 1 1 0
3 1 3 2
4 4 4 1
5 1 5 0
6 1 6 3
4 2 2 1
3 3 3 2
8 1 1 3
7 2 5 0
10 1 3 4
11 1 7 5
9 1 1 3
14 1 3 1
12 4 6 4
16 1 4 7
15 2 4 4
17 2 7 1
19 6 9 6
18 4 6 2
18 2 7 4
18 2 4 3
22 1 7 0
19 3 9 6
20 4 7 7
26 5 10 9
27 2 7 10
27 3 10 6
29 8 9 10
26 7 8 5
31 3 9 1
31 5 13 5
32 10 ...

output:

52 103 49 571 1190 414 200 2 0 2068 97 155 1 262 200 45 157 2896 2043 157 311 2 888 204 1839 103 0 595 0 4318 5688 2768 52 249 2046 155 2156 4286 13484 9297 1007 103 0 200 53 6053 105 155 41 654 1114 3643 346 4132 1839 362 6053 694 0 0 0 0 757 14221 25792 13187 5738 757 0 0 554 297 14611 0 19650 0 4...

result:



Final Tests

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 9944kb

input:

1
4
6
1 1 1 0
2 1 2 0
3 2 3 0
3 2 2 2
5 4 4 3
6
1 1 1 0
1 1 1 0
3 1 1 1
3 1 1 0
4 2 3 1
6
1 1 1 0
2 1 2 1
2 1 2 0
2 2 2 0
2 1 2 0
6
1 1 1 0
2 1 1 1
1 1 1 0
4 1 2 1
5 1 2 2

output:

4 11 5 0 1 
1 2 1 2 3 
5 1 6 1 6 
1 0 2 1 0 

result:

wrong answer 4th numbers differ - expected: '1', found: '0'

Test #2:

score: 0
Wrong Answer
time: 11ms
memory: 10652kb

input:

2
4
300
1 1 1 0
2 1 1 0
1 1 1 0
4 1 2 1
2 2 2 0
6 1 2 1
3 1 3 0
4 1 2 1
6 1 1 1
10 2 3 0
6 2 3 2
11 2 4 0
11 4 5 2
14 4 4 5
10 1 3 2
12 3 4 0
12 2 4 1
15 7 7 5
17 3 4 1
16 4 4 0
21 2 2 5
20 2 4 2
20 2 2 1
23 3 5 1
20 3 4 0
22 4 5 0
26 5 7 1
28 1 8 1
27 2 6 6
26 1 5 2
30 1 3 6
28 1 1 4
28 2 7 6
34 2 ...

output:

34 69 3 1 236 34 104 1 173 305 28 443 36 0 69 629 271 1 2089 35 1 528 629 893 1621 444 3481 4638 35 893 271 0 193 298 0 444 1 388 0 0 8612 3674 928 89 3974 236 3016 12942 0 0 0 8311 5295 20 290 0 28 45772 9241 21696 12722 118646 4638 9645 43050 5763 21280 56684 6927 2746 49571 477 4367 0 5999 43930 ...

result:

wrong answer 10th numbers differ - expected: '749', found: '305'

Test #3:

score: 0
Wrong Answer
time: 11ms
memory: 10712kb

input:

3
4
300
1 1 1 0
2 1 2 0
3 1 3 0
4 1 3 2
4 1 4 2
3 1 2 0
5 1 5 0
4 1 2 3
4 1 4 3
5 1 2 2
8 5 6 3
10 1 3 2
9 4 5 3
13 4 6 1
10 1 4 3
12 4 5 5
13 1 2 1
13 2 3 4
18 6 7 6
17 6 8 3
19 1 3 3
21 9 9 4
22 2 4 5
21 5 7 4
22 1 5 1
23 3 9 3
24 1 1 6
25 1 2 7
28 1 8 6
30 1 11 2
30 4 9 0
32 2 10 3
30 6 8 8
32 6 ...

output:

25 249 447 129 26 274 929 1 16 0 78 1288 26 275 25 52 17 763 1 1951 3700 851 0 825 2514 1857 3253 0 6382 15766 16840 6463 823 3914 2067 9277 585 8365 37126 30175 2789 274 274 18912 49723 0 33599 0 2789 223068 0 34674 116594 0 0 6759 1288 40054 121091 50251 517602 124286 998239091 3914 30938 30389 20...

result:

wrong answer 23rd numbers differ - expected: '3253', found: '0'

Test #4:

score: 0
Wrong Answer
time: 54ms
memory: 28204kb

input:

4
4
5000
1 1 1 0
2 1 2 1
1 1 1 0
4 1 1 0
1 1 1 0
3 2 3 2
6 1 2 1
5 1 2 0
8 3 3 1
10 1 3 2
8 2 2 0
11 1 5 4
11 3 5 3
13 4 5 3
12 3 3 1
16 1 5 1
13 4 5 5
18 1 5 5
17 1 6 5
17 1 5 4
20 5 7 4
19 1 1 7
23 1 8 3
23 4 6 4
23 8 9 7
24 3 4 2
27 3 6 3
28 5 8 9
26 1 4 4
27 3 10 8
28 8 11 9
31 4 6 3
31 10 10 2
...

output:

3 2 1 2 41 1 40 3 118 117 207 34 42 81 166 332 0 0 2 41 82 33 3462 235 42 3112 155 0 0 2957 121 33 6338 2177 40 1875 6298 309 11370 16053 0 18169 22551 1249 5762 0 13925 4394 5762 0 0 0 5487 548 0 548 73 8982 0 40 158 0 0 5137 0 13925 0 29192 8995 2957 160 0 2 81453 309 351 14741 7233 6916 550 62116...

result:

wrong answer 17th numbers differ - expected: '33', found: '0'

Test #5:

score: 0
Wrong Answer
time: 59ms
memory: 30336kb

input:

5
4
5000
1 1 1 0
2 2 2 1
3 1 2 2
1 1 1 0
3 1 1 0
4 2 2 3
5 1 1 1
8 3 3 1
8 2 3 2
6 4 4 3
10 2 4 2
10 2 4 2
12 4 5 3
11 2 3 4
11 5 5 1
14 1 3 5
16 1 1 2
15 1 3 0
17 1 4 2
18 3 7 3
21 5 8 6
18 6 7 2
22 1 5 5
24 4 7 4
21 5 7 7
24 2 9 0
26 9 9 2
24 5 9 9
29 8 11 2
30 3 7 4
30 8 9 6
31 5 10 6
30 3 5 4
34...

output:

34 33 0 6 65 0 0 1 4 32 14 7 7 0 132 0 0 97 18 229 95 35 223 229 0 620 1 26 998244333 1739 557 1378 614 132 1149 784 324 0 887 296 0 1784 0 0 24 935 573 0 362 621 614 297 194 0 34 1811 324 6467 229 5648 869 0 319 2673 547 0 13332 2377 1167 90 0 3692 2632 296 1739 2626 12628 3200 324 3102 0 15392 182...

result:

wrong answer 7th numbers differ - expected: '5', found: '0'

Test #6:

score: 0
Time Limit Exceeded

input:

6
4
100000
1 1 1 0
2 2 2 0
3 2 2 0
4 2 2 0
5 3 3 0
6 3 3 0
7 6 6 0
8 3 3 0
9 5 5 0
10 2 2 0
11 4 4 0
12 6 6 0
13 8 8 0
14 6 6 0
15 2 2 0
16 2 2 0
17 17 17 0
18 5 5 0
19 15 15 0
20 2 2 0
21 14 14 0
22 17 17 0
23 10 10 0
24 23 23 0
25 10 10 0
26 17 17 0
27 23 23 0
28 21 21 0
29 29 29 0
30 7 7 0
31 21 ...

output:

13 116 1159 11577 150385 1654119 16540031 198480359 787928493 734581969 103223677 120676063 963754385 618704320 378636756 206516872 241703175 693677871 68103114 817225791 671888130 60162705 601476665 456558188 30918290 836035627 422508580 961059777 721412290 780076554 866081801 542037914 961741065 6...

result:


Test #7:

score: 0
Time Limit Exceeded

input:

7
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
1 1 1 0
5 2 2 0
5 2 2 0
7 1 1 0
8 1 1 0
6 1 1 0
7 3 3 0
9 3 3 0
12 2 2 0
10 2 2 0
13 1 1 0
13 4 4 0
13 7 7 0
15 1 1 0
15 7 7 0
16 7 7 0
19 1 1 0
18 8 8 0
19 2 2 0
23 1 1 0
23 5 5 0
24 8 8 0
23 6 6 0
27 3 3 0
28 4 4 0
26 12 12 0
29 6 6 0
30 1 1 0
31 12 12 0
30 9 9 0...

output:

1 1 1 21 1 376 9022 162020 2 1 3879458 77588784 1 475771479 9043 1 475771500 836010287 21 836010287 21 723456114 723627157 3879458 171043 462547233 193433576 974019581 162021 821331611 162021 376 162020 686601685 418942555 31199510 217891022 462547233 836010287 944144826 217891022 575663750 44315401...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

8
4
100000
1 1 1 0
2 2 2 0
3 2 2 1
4 2 2 2
5 3 3 0
6 6 6 2
7 1 1 6
8 8 8 2
9 1 1 6
10 2 2 3
11 4 4 2
12 6 6 5
13 2 2 11
14 1 1 6
15 7 7 4
16 7 7 3
17 14 14 15
18 12 12 12
19 17 17 3
20 20 20 11
21 5 5 7
22 12 12 3
23 14 14 10
24 3 3 1
25 23 23 10
26 5 5 18
27 5 5 25
28 18 18 1
29 2 2 14
30 23 23 3
3...

output:

7 13 12 5 18 5 4 25 0 5 9 5 0 24 49 24 24 0 50 37 0 41 36 36 36 0 0 44 0 39 35 0 0 0 28 21 14 14 0 0 0 0 0 0 0 18 0 44 44 9 0 2 0 2 0 0 0 0 150 143 99 92 64 0 83 59 44 0 42 42 42 0 998244249 0 0 0 42 0 0 998243668 998243668 998243668 998243644 998243630 44 0 0 0 0 0 0 0 66 66 66 0 0 90 0 123 31 0 17...

result:


Test #9:

score: 0
Wrong Answer
time: 1973ms
memory: 486052kb

input:

9
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
3 1 1 0
4 2 2 1
6 2 2 2
6 1 1 2
8 3 3 2
9 1 1 4
8 4 4 0
9 4 4 0
12 6 6 3
13 3 3 4
13 6 6 3
15 5 5 0
15 2 2 7
15 4 4 2
17 5 5 2
18 5 5 0
18 4 4 6
19 2 2 8
22 8 8 9
23 3 3 10
24 6 6 12
25 7 7 13
24 1 1 11
27 3 3 7
27 12 12 2
28 4 4 0
30 3 3 9
31 15 15 15
32 1 1 7
31 ...

output:

1 1 15 1 14 0 13 57 0 1 42 27 0 39 13 11 114 83 57 0 0 0 0 0 0 26 0 14 0 0 0 0 0 0 15 0 0 68 0 0 0 0 11 11 0 22 0 0 0 0 0 0 998244348 0 0 39 0 0 0 0 0 0 0 137 110 0 0 110 0 0 0 0 0 110 95 0 57 0 0 11 0 27 0 11 0 0 155 0 116 39 0 116 0 0 0 110 0 0 0 172 172 110 0 0 0 0 0 115 15 0 300 0 998244299 0 0 ...

result:

wrong answer 21st numbers differ - expected: '26', found: '0'

Test #10:

score: 0
Time Limit Exceeded

input:

10
4
100000
1 1 1 0
2 1 1 0
3 3 3 0
4 3 4 0
5 3 5 0
6 1 4 0
7 5 5 0
8 5 7 0
9 3 6 0
10 6 10 0
11 1 2 0
12 8 11 0
13 4 12 0
14 2 12 0
15 7 10 0
16 6 8 0
17 13 15 0
18 8 9 0
19 2 6 0
20 8 14 0
21 3 18 0
22 11 18 0
23 5 11 0
24 6 12 0
25 3 24 0
26 13 23 0
27 3 8 0
28 14 22 0
29 4 26 0
30 1 5 0
31 13 17...

output:

16 527 25807 1883910 167667973 634982620 705207129 488881034 887725160 151025554 347960978 855383206 80305903 380559379 538908054 777587576 260990688 523673420 353610155 624705377 700258326 228676702 200177699 984634103 68249951 263072670 517709689 650106087 34684922 592160972 944601706 376074738 79...

result:


Test #11:

score: 0
Time Limit Exceeded

input:

11
4
100000
1 1 1 0
2 1 2 0
3 1 2 0
3 1 2 0
5 3 4 0
5 1 3 0
5 2 3 0
8 1 3 0
9 2 5 0
10 3 5 0
11 4 6 0
10 1 3 0
11 6 8 0
13 4 8 0
13 2 7 0
14 1 3 0
17 3 8 0
17 5 7 0
19 10 11 0
19 1 2 0
20 5 12 0
22 12 12 0
22 8 10 0
23 6 14 0
23 2 8 0
25 2 9 0
27 6 9 0
26 9 15 0
29 3 10 0
30 9 9 0
30 12 13 0
32 14 1...

output:

37 2478 2515 242769 38 245284 32040440 39124800 942462595 336524633 32285687 63297973 516597219 32285725 15628766 418384838 352153362 613054463 541763722 33194948 718423411 374189456 71408009 685412541 334965261 356495372 886316800 521955760 368374612 350953225 587492770 498900953 709154717 10323060...

result:


Test #12:

score: 0
Time Limit Exceeded

input:

12
4
100000
1 1 1 0
2 1 2 0
3 2 3 0
4 1 3 0
2 1 1 0
4 2 2 0
3 1 2 0
8 1 4 0
8 1 3 0
5 2 5 0
9 1 4 0
10 3 5 0
11 1 6 0
11 3 6 0
11 3 3 0
14 2 6 0
17 3 7 0
14 2 4 0
14 4 6 0
18 2 8 0
18 6 9 0
21 8 10 0
22 5 5 0
20 6 8 0
22 1 4 0
24 3 9 0
26 3 8 0
25 3 3 0
24 6 7 0
25 5 9 0
27 2 9 0
32 4 6 0
32 9 11 0
...

output:

69 7796 1278127 262008169 69 7796 39327 94385 55058 777304836 141577 7866 482180153 1285993 1278127 465685418 825856966 42346779 575383498 990228081 154169563 7866 833831197 726620149 749228357 498747852 817824963 482180153 41068652 41084244 474778269 447467594 402643074 564999930 7866 41076378 8460...

result:


Test #13:

score: 0
Time Limit Exceeded

input:

13
4
100000
1 1 1 0
2 1 2 1
3 1 2 2
4 1 3 2
5 1 5 4
6 1 4 4
7 6 6 1
8 3 7 5
9 3 4 4
10 5 6 2
11 6 9 4
12 5 11 9
13 1 3 4
14 6 10 10
15 4 6 8
16 3 8 6
17 1 9 3
18 3 13 8
19 3 11 10
20 2 4 11
21 12 13 0
22 13 17 20
23 9 17 1
24 10 11 16
25 22 25 9
26 5 9 4
27 12 27 26
28 13 13 22
29 8 23 1
30 21 23 19...

output:

25 24 23 48 23 122 194 169 239 285 214 96 0 0 192 1948 2135 1132 385 216 455 47 1413 0 94 4344 21 779 13720 5938 4397 13663 4449 21932 12546 0 3304 998244224 13361 9623 3267 0 619 5213 13695 91490 3824 13367 35448 2821 234146 232709 150074 176916 173649 224286 224070 1744 29858 0 18990 13179 519873 ...

result:


Test #14:

score: 0
Time Limit Exceeded

input:

14
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
4 1 2 1
1 1 1 0
5 1 1 2
6 1 1 0
6 2 2 1
5 2 3 2
5 1 2 1
7 2 2 1
8 1 2 1
11 2 4 1
11 4 4 2
15 2 4 0
13 1 3 3
15 1 3 3
18 2 4 4
16 2 5 5
16 4 4 0
18 6 6 4
22 4 4 5
18 2 5 5
20 5 6 5
24 1 6 4
25 5 6 2
22 3 4 1
28 3 7 0
25 2 4 4
29 1 6 4
27 3 8 0
28 5 5 7
30 2 3 1
33 ...

output:

1 1 68 67 2 0 4 1 1 337 67 2 136 200 539 0 0 0 0 67 131 0 0 136 135 1682 1808 1209 0 537 66 62 136 187 0 5404 1885 61 668 2673 1 67 864 61 0 2686 2409 0 331 0 8196 8962 5533 8264 32330 131 0 268 672 28352 0 2543 8126 53093 537 604 0 8717 12317 102748 8669 6949 0 404 3014 89571 1199 385 74415 44903 1...

result:


Test #15:

score: 0
Time Limit Exceeded

input:

15
4
100000
1 1 1 0
1 1 1 0
2 1 2 0
1 1 1 0
4 1 3 1
3 2 2 1
5 1 2 0
5 2 2 1
7 2 3 1
9 1 2 0
9 2 3 0
8 1 2 1
9 1 2 0
10 3 3 2
11 2 3 1
13 2 3 3
15 3 5 4
14 4 4 2
16 2 4 0
20 4 5 5
18 1 6 4
21 2 5 6
19 4 5 4
23 3 7 4
23 3 5 0
25 3 3 8
26 4 8 8
26 3 7 6
28 6 9 5
26 6 9 2
29 8 9 7
29 6 10 1
31 4 4 5
34 ...

output:

3 5 8 46 4 4 93 44 13 310 47 46 92 7 220 0 2 2 440 0 6 40 1 400 3608 0 0 269 620 1748 90 665 0 621 354 0 44 0 993 0 4931 6981 7010 6017 0 3373 1291 9444 5770 5836 0 4709 851 764 3648 4640 3540 47 30220 13991 15052 18252 11223 0 6457 0 1010 5246 0 538 59640 0 67180 47 14961 2 0 5396 43251 10354 20556...

result:


Test #16:

score: 0
Time Limit Exceeded

input:

16
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
1 1 1 0
5 2 2 1
5 1 1 0
5 1 2 1
4 1 2 0
7 1 2 2
6 1 2 0
7 2 3 0
12 1 4 0
11 1 1 2
13 1 4 0
14 3 3 4
12 1 4 0
16 2 2 1
18 1 7 5
19 6 6 5
20 4 5 1
17 2 5 4
22 1 3 4
23 1 3 3
21 5 5 9
22 3 4 3
24 1 7 3
23 2 5 1
27 2 5 4
25 2 8 7
29 6 7 3
27 5 9 6
30 10 11 6
30 1 2 3
...

output:

1 1 2 60 3 355 1 3 0 65 1360 3551 0 5326 2 1828 62 62 4 3 52 351 12001 1 355 24797 3595 20363 322 19393 831 998244352 0 3603 89801 4487 198 330 263 48 3127 20923 0 0 121859 109194 13962 12352 60752 9819 4208 37201 61167 46695 2433 0 205716 89849 36798 0 96474 76554 16268 255816 46756 61 81610 47809 ...

result:


Test #17:

score: 0
Time Limit Exceeded

input:

17
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
2 1 1 0
2 1 2 1
4 1 1 0
3 1 2 1
7 2 3 0
8 3 3 0
6 1 3 0
9 2 3 0
8 1 3 1
9 3 4 2
11 3 4 3
13 2 3 0
12 4 5 4
16 1 2 1
15 1 2 2
19 2 5 5
16 3 5 4
19 1 4 5
21 3 4 5
23 3 5 0
21 1 6 1
23 3 3 2
25 1 2 2
26 1 3 0
26 5 6 6
27 2 4 3
28 1 5 8
31 2 3 5
29 3 7 1
32 7 10 10
32...

output:

4 54 4 4 3 19 53 10 1 9 24 159 5 1 316 1 159 0 0 50 0 0 528 899 364 0 462 0 316 48 0 578 1 262 898 108 1507 1111 0 1214 874 790 1459 1160 1404 1398 1720 54 0 262 524 1404 632 3376 528 2297 1860 478 212 1452 1161 44 212 633 0 3222 5436 1459 212 3164 2348 1576 0 0 1908 5715 10365 159 1661 43 4415 633 ...

result:


Test #18:

score: 0
Time Limit Exceeded

input:

18
4
100000
1 1 1 0
1 1 1 0
3 1 2 1
2 1 2 0
2 2 2 0
5 1 3 1
6 1 1 1
6 2 3 2
6 1 3 2
9 1 4 1
10 2 3 1
12 1 3 0
10 1 4 2
11 2 5 0
12 4 5 1
14 2 4 1
15 5 6 2
16 4 5 5
18 3 3 5
18 1 6 4
18 3 4 4
21 2 4 3
21 4 7 4
23 7 9 3
23 1 5 3
25 3 5 3
26 5 6 2
25 1 7 4
29 3 4 6
30 4 11 2
29 1 3 3
29 1 5 6
32 9 12 0...

output:

47 2 1 96 44 48 0 40 3 2679 183 230 95 2627 48 94 2495 0 0 2447 0 37572 131 40043 10612 5122 5306 37324 2810 47951 39005 0 171 66026 47 39 18075 84 125227 12546 275399 0 45141 27320 0 14220 2811 1 253038 16715 89388 7570 1441 1 8064 1394 87995 227539 0 1149686 2811 230389 1639348 230258 42514 998119...

result:


Test #19:

score: 0
Time Limit Exceeded

input:

19
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
2 1 2 1
2 2 2 0
3 1 1 1
4 1 1 0
8 1 3 0
7 2 2 0
8 2 2 2
8 1 1 1
11 2 4 3
13 1 3 2
13 1 3 1
12 1 2 0
15 2 5 1
16 4 5 0
18 4 5 3
17 2 4 0
19 3 6 5
21 4 8 2
21 2 6 4
23 7 8 6
22 1 4 3
22 1 3 2
24 1 8 1
25 5 5 1
26 3 3 2
26 1 10 5
30 8 9 0
29 3 5 2
29 3 6 0
31 4 7 10
...

output:

3 1 43 1 1 0 515 559 1 0 427 1 515 1073 1884 560 942 898 1074 340 9674 2015 1073 1884 7614 7021 942 3758 3978 1108 10912 11854 164 2 28792 25939 558 4787 559 34661 33 2870 1 8345 34330 26865 0 0 13064 898 43 0 898 21266 10283 0 0 0 173992 59346 52399 23097 106078 26438 17548 113827 52568 5956 0 1038...

result:


Test #20:

score: 0
Time Limit Exceeded

input:

20
4
100000
1 1 1 0
1 1 1 0
1 1 1 0
3 1 2 1
5 1 1 0
4 1 2 1
5 1 1 2
8 4 4 0
8 1 2 3
10 3 4 0
11 5 5 3
10 3 4 2
11 2 3 3
12 1 7 6
14 1 2 1
15 5 8 3
15 1 2 6
17 5 8 4
17 3 4 0
18 7 9 6
20 1 10 2
21 1 4 9
22 1 9 9
23 3 8 6
25 3 7 8
24 2 7 6
27 1 9 8
27 12 12 8
29 3 11 3
30 2 6 4
31 6 14 8
30 6 8 3
33 8...

output:

1 44 2 43 43 1 0 1 41 172 85 87 0 41 172 690 45 128 602 88 772 0 345 41 0 976 41 763 8518 1756 382 4359 690 2336 979 998244090 998242473 2913 1879 1116 1925 0 1418 0 0 0 0 0 20781 14228 5864 0 2252 4446 168 0 338 0 1653 30055 47912 0 24062 22132 0 0 2389 84 40339 0 1333 19788 116 8518 15510 42002 0 ...

result: