QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398889#6502. Disjoint Set UnionNATURAL6AC ✓730ms28084kbC++171.6kb2024-04-25 19:30:372024-04-25 19:30:39

Judging History

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

  • [2024-04-25 19:30:39]
  • 评测
  • 测评结果:AC
  • 用时:730ms
  • 内存:28084kb
  • [2024-04-25 19:30:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int qread()
{
	int a=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
	return a*f;
} 
int T,n,fa[1010],tp[1010],deg[1010],dfn[1010],pos[1010],tot;
vector<int>e[1010];
queue<int>que;
struct node
{
	int op,x,y;
};
vector<node>Ans;
inline int find(int rt){Ans.emplace_back((node){1,rt,0});return fa[rt]==rt?rt:fa[rt]=find(fa[rt]);}
inline void merge(int x,int y){Ans.emplace_back((node){2,x,y});x=find(x),y=find(y);fa[x]=y;return;}
inline void solve()
{
	n=qread();Ans.clear();memset(deg,0,(n+1)<<2);
	for(int i=1;i<=n;++i)fa[i]=qread();
	for(int i=1;i<=n;++i)tp[i]=qread();
	for(int i=1;i<=n;++i)
	{
		if(fa[i]^tp[i])find(i);
		if(fa[i]^tp[i])e[fa[i]].emplace_back(tp[i]),++deg[tp[i]];
	}
	while(!que.empty())que.pop();tot=0;
	for(int i=1;i<=n;++i)if(!deg[i])que.push(i);
	while(!que.empty())
	{
		int p=que.front();que.pop();
		pos[dfn[p]=++tot]=p;
		for(int i:e[p])if(!--deg[i])que.push(i);
	}
	for(int i=1;i<=n;++i)vector<int>().swap(e[i]);
	if(tot^n)return puts("NO"),void();
	dfn[0]=n+1;
	for(int i=1,p,lp;i<=n;++i)
	{
		p=pos[i],lp=0;
		for(int j=1;j<=n;++j)if(fa[j]==p&&fa[j]^tp[j]&&dfn[lp]>dfn[tp[j]])lp=tp[j];
		if(lp)merge(p,lp);
		for(int j=1;j<=n;++j)if(fa[j]^tp[j])find(j);
	}
	for(int i=1;i<=n;++i)if(fa[i]^tp[i])return puts("NO"),void();
	puts("YES");
	printf("%d\n",(int)Ans.size());
	for(node i:Ans)
	{
		if(i.op==1)printf("1 %d\n",i.x);
		else printf("2 %d %d\n",i.x,i.y);
	}
	return ;
}
int main()
{
	T=qread();
	while(T--)solve();
	return 0;	
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3728kb

input:

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

output:

YES
4
1 1
2 1 2
1 1
1 2
YES
22
1 2
1 3
1 4
1 3
2 3 2
1 3
1 2
1 2
1 3
1 2
1 4
1 3
1 2
1 2
1 3
1 2
2 2 1
1 2
1 1
1 3
1 2
1 1
YES
22
1 1
1 2
1 3
1 4
2 1 2
1 1
1 2
1 2
1 3
1 4
2 2 3
1 2
1 3
1 3
1 4
2 3 4
1 3
1 4
1 4
2 4 5
1 4
1 5
NO
YES
43
1 2
1 3
1 2
1 4
1 5
1 6
1 2
1 3
1 2
1 4
1 5
1 6
2 6 2
1 6
1 2
1 ...

result:

ok good! (YES count = 4, NO count = 1) (5 test cases)

Test #2:

score: 0
Accepted
time: 115ms
memory: 3840kb

input:

100000
5
1 2 1 1 1
2 2 1 1 2
5
3 2 3 4 1
3 2 3 4 1
5
1 2 3 4 3
1 4 4 1 1
5
1 2 3 5 3
1 2 2 5 2
5
5 2 3 5 5
5 2 3 5 5
5
1 2 3 4 5
5 3 3 4 5
5
1 2 3 4 5
1 4 1 4 4
5
1 2 3 1 5
1 2 3 1 2
5
1 2 3 3 1
1 3 3 3 1
5
1 2 3 4 3
2 2 4 4 4
5
1 2 2 4 5
5 2 2 4 5
5
1 2 1 4 5
5 2 5 5 5
5
1 2 3 4 5
1 2 5 5 1
5
1 4 3...

output:

YES
9
1 1
1 5
1 1
2 1 2
1 1
1 2
1 5
1 1
1 2
YES
0
YES
28
1 2
1 3
1 4
1 5
1 3
2 2 4
1 2
1 4
1 3
1 4
1 5
1 3
2 3 4
1 3
1 4
1 4
1 5
1 3
1 4
1 4
1 5
1 4
2 4 1
1 4
1 1
1 5
1 4
1 1
YES
12
1 3
1 5
1 3
1 3
1 5
1 3
2 3 2
1 3
1 2
1 5
1 3
1 2
YES
0
YES
9
1 1
1 2
2 1 5
1 1
1 5
1 2
2 2 3
1 2
1 3
YES
15
1 2
1 3
1...

result:

ok good! (YES count = 100000, NO count = 0) (100000 test cases)

Test #3:

score: 0
Accepted
time: 204ms
memory: 4044kb

input:

50000
10
1 2 3 4 5 6 7 8 6 10
1 10 3 4 5 6 7 8 6 10
10
6 2 3 4 5 6 2 5 5 10
6 6 6 6 6 6 6 6 6 10
10
1 2 3 4 7 7 7 10 9 10
9 7 3 9 9 9 9 9 9 7
10
1 2 3 7 4 2 3 8 3 10
2 2 2 2 2 2 2 2 2 2
10
1 2 3 5 5 8 2 8 9 10
2 2 3 5 10 8 2 10 9 10
10
1 8 3 3 5 6 10 8 9 10
5 5 5 5 5 5 5 5 5 5
10
8 2 7 4 5 6 8 8 9 1...

output:

YES
5
1 2
1 2
2 2 10
1 2
1 10
YES
59
1 2
1 3
1 4
1 5
1 7
1 2
1 8
1 5
1 9
1 5
1 2
1 3
1 4
1 5
1 7
1 2
1 8
1 5
1 9
1 5
2 2 6
1 2
1 6
1 3
1 4
1 5
1 7
1 2
1 6
1 8
1 5
1 9
1 5
2 3 6
1 3
1 6
1 4
1 5
1 8
1 5
1 9
1 5
2 4 6
1 4
1 6
1 5
1 8
1 5
1 9
1 5
2 5 6
1 5
1 6
1 8
1 5
1 6
1 9
1 5
1 6
YES
103
1 1
1 2
1 4...

result:

ok good! (YES count = 50000, NO count = 0) (50000 test cases)

Test #4:

score: 0
Accepted
time: 125ms
memory: 4096kb

input:

12500
20
9 2 3 4 5 6 7 8 9 10 11 9 13 14 19 19 17 18 19 20
8 2 3 6 4 6 7 18 18 10 3 8 6 4 19 4 4 4 4 20
20
6 2 3 4 6 15 7 8 9 10 11 12 13 14 15 20 17 18 19 20
12 12 2 8 12 12 7 12 9 12 11 12 13 14 12 8 8 9 8 8
20
5 2 3 4 5 20 7 8 9 10 11 10 13 14 20 16 10 18 19 9
19 19 4 4 19 3 14 8 3 4 3 4 3 14 3 1...

output:

YES
226
1 1
1 9
1 4
1 5
1 8
1 9
1 11
1 12
1 9
1 13
1 14
1 16
1 19
1 17
1 18
1 19
1 1
1 9
1 4
1 5
1 8
1 9
1 11
1 12
1 9
1 13
1 14
1 16
1 19
1 17
1 18
1 19
1 1
1 9
1 4
1 5
1 8
1 9
1 11
1 12
1 9
1 13
1 14
1 16
1 19
1 17
1 18
1 19
2 5 4
1 5
1 4
1 1
1 9
1 4
1 8
1 9
1 11
1 12
1 9
1 13
1 14
1 16
1 19
1 17
...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #5:

score: 0
Accepted
time: 146ms
memory: 3872kb

input:

12500
20
1 2 3 4 5 6 7 7 5 10 11 12 13 14 5 16 17 5 19 20
10 3 12 3 3 3 4 12 3 10 3 12 3 3 13 3 11 11 13 2
20
1 2 3 10 5 6 7 13 12 10 11 13 13 13 13 16 17 13 19 20
13 13 3 10 13 13 1 13 13 13 13 13 13 13 13 13 13 13 13 13
20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 9 3 4 17 6 7 19 9 10 1...

output:

YES
352
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 7
1 9
1 5
1 11
1 13
1 14
1 15
1 5
1 16
1 17
1 18
1 5
1 19
1 20
2 1 10
1 1
1 10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 7
1 9
1 5
1 11
1 13
1 14
1 15
1 5
1 16
1 17
1 18
1 5
1 19
1 20
2 5 11
1 5
1 11
1 2
1 3
1 4
1 5
1 11
1 6
1 7
1 8
1 7
1 9
1 5
1 11
1 11
1 13
1 14
1 15
...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #6:

score: 0
Accepted
time: 398ms
memory: 3908kb

input:

500
100
5 43 3 13 100 6 56 8 9 62 11 82 13 14 15 48 17 76 19 64 35 62 50 77 38 94 35 62 35 30 31 32 48 34 35 36 43 64 39 40 35 42 62 44 45 62 47 62 49 50 62 47 62 62 39 48 20 58 59 60 43 66 19 62 3 66 67 85 69 70 83 28 73 83 100 76 77 80 85 80 81 82 100 84 85 40 20 88 62 90 40 92 93 94 58 96 30 98 6...

output:

YES
12367
1 1
1 5
1 100
1 94
1 2
1 43
1 62
1 66
1 3
1 4
1 13
1 5
1 94
1 6
1 7
1 56
1 48
1 62
1 66
1 8
1 9
1 10
1 62
1 66
1 11
1 12
1 82
1 13
1 14
1 15
1 16
1 48
1 66
1 17
1 18
1 76
1 19
1 20
1 64
1 62
1 66
1 21
1 35
1 22
1 62
1 66
1 23
1 50
1 24
1 77
1 25
1 38
1 64
1 66
1 26
1 94
1 27
1 35
1 28
1 62...

result:

ok good! (YES count = 500, NO count = 0) (500 test cases)

Test #7:

score: 0
Accepted
time: 281ms
memory: 6296kb

input:

55
300
172 231 135 149 135 297 7 297 236 52 73 114 52 135 15 73 297 97 218 236 52 236 218 73 244 236 73 52 162 218 103 30 214 34 59 36 73 89 44 131 73 73 73 73 73 41 47 32 236 52 248 73 73 54 209 75 57 73 205 151 73 62 73 73 143 141 238 205 106 73 71 128 73 124 75 76 89 231 205 73 149 135 249 135 13...

output:

YES
159367
1 1
1 172
1 236
1 73
1 2
1 231
1 73
1 3
1 135
1 73
1 4
1 149
1 73
1 5
1 135
1 73
1 6
1 297
1 73
1 7
1 8
1 297
1 73
1 9
1 236
1 73
1 11
1 73
1 12
1 114
1 135
1 73
1 13
1 52
1 73
1 14
1 135
1 73
1 15
1 16
1 73
1 17
1 297
1 73
1 18
1 97
1 73
1 19
1 218
1 73
1 20
1 236
1 73
1 21
1 52
1 73
1 2...

result:

ok good! (YES count = 55, NO count = 0) (55 test cases)

Test #8:

score: 0
Accepted
time: 323ms
memory: 27844kb

input:

5
1000
794 193 3 4 888 279 316 8 621 679 376 254 791 550 362 706 677 133 133 279 279 57 557 471 780 471 110 557 264 317 557 927 264 908 589 193 481 38 39 941 619 473 683 340 817 780 876 548 557 193 589 648 264 471 940 528 557 710 57 57 61 142 133 481 679 142 712 264 557 264 683 468 679 204 398 754 3...

output:

YES
1627954
1 1
1 794
1 557
1 471
1 2
1 193
1 683
1 471
1 4
1 5
1 888
1 398
1 557
1 471
1 7
1 316
1 908
1 57
1 557
1 471
1 8
1 9
1 621
1 817
1 557
1 471
1 11
1 376
1 233
1 471
1 12
1 254
1 683
1 471
1 13
1 791
1 557
1 471
1 14
1 550
1 57
1 471
1 15
1 362
1 985
1 471
1 16
1 706
1 679
1 557
1 471
1 17...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #9:

score: 0
Accepted
time: 236ms
memory: 27668kb

input:

5
1000
811 448 371 731 601 6 950 8 731 811 123 688 753 282 15 802 17 282 282 20 272 818 23 24 731 1 805 67 951 753 230 182 629 15 874 36 576 38 113 272 41 811 43 455 282 595 965 836 582 855 811 76 230 50 731 885 811 595 182 969 619 62 688 576 811 944 335 1 944 230 71 42 73 328 11 951 753 10 335 944 ...

output:

YES
1480986
1 1
1 811
1 2
1 448
1 895
1 576
1 811
1 3
1 371
1 601
1 282
1 811
1 4
1 731
1 811
1 5
1 601
1 811
1 6
1 7
1 950
1 811
1 8
1 9
1 731
1 811
1 10
1 811
1 11
1 123
1 182
1 811
1 12
1 688
1 811
1 13
1 753
1 811
1 14
1 282
1 811
1 15
1 16
1 802
1 182
1 811
1 18
1 282
1 811
1 19
1 282
1 811
1 2...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #10:

score: 0
Accepted
time: 287ms
memory: 27900kb

input:

5
1000
1 696 3 4 70 98 715 8 174 10 11 12 342 530 15 878 928 191 447 20 21 878 23 436 367 4 174 28 321 666 31 911 33 34 35 526 66 38 39 868 41 440 43 710 45 988 47 48 62 50 383 612 300 569 878 56 84 58 560 60 61 401 63 64 815 647 67 68 69 70 670 72 73 74 75 846 77 784 554 80 208 82 142 84 85 590 87 ...

output:

YES
817154
1 1
1 2
1 696
1 3
1 4
1 5
1 70
1 6
1 98
1 7
1 715
1 8
1 9
1 174
1 860
1 10
1 11
1 12
1 13
1 342
1 14
1 530
1 15
1 16
1 878
1 948
1 17
1 928
1 18
1 191
1 395
1 856
1 666
1 846
1 19
1 447
1 20
1 21
1 22
1 878
1 948
1 23
1 24
1 436
1 25
1 367
1 670
1 26
1 4
1 27
1 174
1 860
1 28
1 29
1 321
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #11:

score: 0
Accepted
time: 515ms
memory: 27920kb

input:

5
1000
1 697 3 807 656 548 7 859 9 188 11 194 629 907 319 275 796 18 876 878 21 711 376 82 275 118 27 28 144 30 31 32 878 225 35 795 193 835 39 220 468 509 601 808 569 46 947 871 859 878 228 52 113 697 621 56 319 616 323 572 970 795 98 994 65 853 907 387 69 436 605 835 601 74 762 256 77 78 275 907 5...

output:

YES
1290157
1 1
1 2
1 697
1 907
1 601
1 3
1 4
1 807
1 319
1 601
1 5
1 656
1 6
1 548
1 79
1 275
1 601
1 7
1 8
1 859
1 319
1 601
1 9
1 10
1 188
1 11
1 12
1 194
1 154
1 13
1 629
1 907
1 601
1 14
1 907
1 601
1 15
1 319
1 601
1 16
1 275
1 601
1 17
1 796
1 215
1 56
1 18
1 19
1 876
1 743
1 20
1 878
1 601
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #12:

score: 0
Accepted
time: 179ms
memory: 27912kb

input:

5
1000
1 2 500 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 689 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 452 86 684 88 89 90 91 550 93 94 95 96 97 98 74...

output:

YES
532770
1 1
1 2
1 3
1 500
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 689
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #13:

score: 0
Accepted
time: 278ms
memory: 27992kb

input:

5
1000
1 2 3 4 5 6 7 69 9 10 11 12 13 14 15 16 17 18 822 423 21 22 23 24 25 26 27 28 29 30 848 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 963 48 49 50 51 52 53 54 672 56 673 58 59 60 868 62 63 64 480 66 67 68 69 941 71 834 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 515 91 92 93 94 95 96 97...

output:

YES
598960
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 69
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 822
1 20
1 423
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 848
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 963
1 49
1 48
1 49
1 50
1 51
1 52
1 53...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #14:

score: 0
Accepted
time: 483ms
memory: 27668kb

input:

5
1000
433 256 696 228 253 435 436 725 47 766 308 958 433 851 399 433 258 328 748 435 468 725 982 24 748 157 748 999 958 725 27 553 435 819 139 553 748 304 39 676 289 228 33 725 748 851 811 735 435 47 819 399 531 435 738 191 433 304 559 60 748 800 227 47 982 658 47 586 69 748 991 191 325 107 183 644...

output:

YES
1880534
1 1
1 433
1 766
1 2
1 256
1 735
1 811
1 766
1 3
1 696
1 435
1 766
1 4
1 228
1 766
1 5
1 253
1 725
1 819
1 766
1 6
1 435
1 766
1 7
1 436
1 435
1 766
1 8
1 725
1 766
1 9
1 47
1 811
1 766
1 10
1 766
1 11
1 308
1 435
1 766
1 12
1 958
1 435
1 766
1 13
1 433
1 766
1 14
1 851
1 766
1 15
1 399
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #15:

score: 0
Accepted
time: 189ms
memory: 28008kb

input:

5
1000
766 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 592 18 19 20 21 22 230 24 25 26 27 28 29 30 31 32 270 144 35 36 37 105 39 40 180 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 947 61 62 417 64 65 66 67 68 69 70 71 72 73 888 75 76 77 78 79 80 81 82 83 766 85 86 87 214 916 90 91 92 93 94 95 317...

output:

YES
594080
1 1
1 766
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 592
1 18
1 19
1 20
1 21
1 22
1 23
1 230
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 270
1 34
1 144
1 35
1 36
1 37
1 38
1 105
1 39
1 40
1 41
1 180
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #16:

score: 0
Accepted
time: 394ms
memory: 27812kb

input:

5
1000
392 897 227 735 327 707 615 226 153 102 593 398 726 696 857 894 17 823 799 322 109 714 931 260 762 823 988 827 799 949 694 916 867 123 398 747 633 367 931 916 231 89 891 44 45 538 938 175 49 376 799 762 960 696 327 327 997 477 726 799 857 714 339 398 916 231 799 68 69 894 71 696 73 255 50 395...

output:

YES
1708354
1 1
1 392
1 477
1 2
1 897
1 408
1 398
1 931
1 477
1 3
1 227
1 4
1 735
1 714
1 827
1 477
1 5
1 327
1 857
1 931
1 477
1 6
1 707
1 89
1 609
1 857
1 477
1 7
1 615
1 633
1 805
1 477
1 8
1 226
1 477
1 9
1 153
1 856
1 10
1 102
1 868
1 857
1 477
1 11
1 593
1 931
1 477
1 12
1 398
1 477
1 13
1 726...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #17:

score: 0
Accepted
time: 424ms
memory: 28084kb

input:

5
1000
1 702 632 4 5 629 7 8 9 10 713 371 13 14 15 16 17 785 19 20 21 476 23 24 584 26 54 28 29 30 31 32 33 34 35 36 768 239 39 96 809 42 43 44 45 46 47 48 208 50 51 52 53 937 55 56 57 58 59 606 25 62 255 64 65 435 67 68 69 70 70 72 69 564 75 76 615 78 79 255 564 800 537 84 85 86 564 262 89 90 91 92...

output:

YES
925461
1 1
1 2
1 702
1 3
1 632
1 4
1 5
1 6
1 629
1 854
1 7
1 8
1 9
1 12
1 371
1 15
1 16
1 17
1 18
1 785
1 19
1 20
1 21
1 22
1 476
1 834
1 678
1 23
1 24
1 25
1 584
1 26
1 27
1 54
1 937
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 768
1 692
1 38
1 239
1 962
1 39
1 40
1 96
1 41
1 809
1 42
1 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #18:

score: 0
Accepted
time: 466ms
memory: 27928kb

input:

5
1000
167 610 3 858 1 592 201 496 9 10 11 969 13 14 290 705 618 18 19 62 21 22 23 25 25 562 509 28 29 162 31 32 1 502 518 1 906 501 39 40 41 42 43 44 779 17 979 530 49 737 51 52 53 54 55 56 57 779 533 60 61 822 54 64 65 66 509 68 69 562 71 72 73 587 509 76 77 78 848 80 81 723 83 84 142 936 562 868 ...

output:

YES
1226029
1 1
1 167
1 672
1 509
1 915
1 2
1 610
1 1
1 915
1 3
1 4
1 858
1 509
1 915
1 5
1 1
1 915
1 6
1 592
1 7
1 201
1 8
1 496
1 197
1 9
1 10
1 11
1 12
1 969
1 361
1 13
1 14
1 15
1 290
1 16
1 705
1 17
1 618
1 18
1 19
1 20
1 62
1 822
1 169
1 397
1 21
1 22
1 23
1 24
1 25
1 25
1 26
1 562
1 672
1 915...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #19:

score: 0
Accepted
time: 335ms
memory: 15632kb

input:

5
1000
404 627 3 4 5 6 7 8 9 10 11 12 13 14 693 16 17 18 19 20 221 22 23 24 25 26 27 28 29 30 31 32 33 718 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 986 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 503 551 994 89 495 91 447 93 94 495 96 ...

output:

YES
541986
1 2
1 627
1 3
1 4
1 5
1 6
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 693
1 16
1 17
1 18
1 19
1 20
1 21
1 221
1 22
1 23
1 24
1 25
1 26
1 28
1 30
1 31
1 32
1 33
1 34
1 718
1 35
1 36
1 38
1 39
1 40
1 42
1 43
1 44
1 45
1 46
1 48
1 49
1 50
1 51
1 52
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 62
1 986
1...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #20:

score: 0
Accepted
time: 147ms
memory: 15628kb

input:

5
1000
1 2 3 4 5 6 7 8 9 511 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 575 27 28 29 30 31 32 33 34 35 36 37 822 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 804 62 63 64 65 66 67 477 69 70 71 72 73 74 75 76 77 78 79 80 691 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 941 9...

output:

YES
415522
1 1
1 2
1 3
1 4
1 5
1 7
1 8
1 10
1 511
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 19
1 20
1 21
1 22
1 24
1 25
1 26
1 575
1 27
1 28
1 29
1 30
1 32
1 33
1 34
1 35
1 36
1 38
1 822
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 50
1 51
1 52
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 804
1 63
1 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #21:

score: 0
Accepted
time: 175ms
memory: 3752kb

input:

50000
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 7
10
9 3 3 3 3 6 7 8 9 10
9 3 8 8 3 8 9 9 9 10
10
1 8 5 4 5 6 7 5 9 10
9 5 5 7 5 5 7 5 5 10
10
1 2 3 4 5 6 7 8 8 10
1 2 3 4 5 6 3 8 8 10
10
8 2 3 4 5 5 7 5 9 9
8 4 3 4 4 5 7 5 9 9
10
1 2 3 2 5 6 7 8 9 10
1 5 8 2 5 6 7 8 9 10
10
1 2 3 4 5 6 7 9 9 10
10 ...

output:

YES
12
1 10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
1 10
2 10 7
1 10
1 7
YES
46
1 3
1 4
1 3
1 6
1 7
1 8
1 3
1 4
1 3
1 6
1 7
1 8
1 3
1 4
1 3
1 6
1 7
1 8
2 3 8
1 3
1 8
1 4
1 3
1 8
1 6
1 7
1 8
1 6
1 7
1 8
1 6
1 7
1 8
2 6 8
1 6
1 8
1 7
1 8
2 7 9
1 7
1 9
1 8
1 8
2 8 9
1 8
1 9
YES
33
1 1
1 2
1 8
1 5
1 4
1 6
1 ...

result:

ok good! (YES count = 50000, NO count = 0) (50000 test cases)

Test #22:

score: 0
Accepted
time: 132ms
memory: 3804kb

input:

12500
20
17 2 3 4 5 6 7 4 9 10 11 12 13 14 15 10 17 3 19 20
17 2 3 4 5 6 3 4 9 10 11 12 13 14 15 10 17 3 19 20
20
1 17 3 9 12 6 7 8 9 12 12 12 13 14 15 8 9 18 8 12
7 17 3 9 12 8 7 8 1 12 12 3 3 12 15 8 9 15 8 12
20
5 2 10 4 9 6 7 3 9 10 4 12 13 14 18 16 17 18 12 10
5 14 6 4 9 6 6 10 4 6 4 12 13 14 1...

output:

YES
9
1 7
1 7
1 7
1 7
1 7
1 7
2 7 3
1 7
1 3
YES
92
1 1
1 6
1 9
1 12
1 13
1 14
1 18
1 1
1 6
1 9
1 12
1 13
1 14
1 18
1 1
1 6
1 9
1 12
1 13
1 14
1 18
1 1
1 6
1 9
1 12
1 13
1 14
1 18
2 6 8
1 6
1 8
1 1
1 9
1 12
1 13
1 14
1 18
2 9 1
1 9
1 1
1 1
1 12
1 13
1 14
1 18
1 1
1 12
1 13
1 14
1 18
1 1
1 12
1 13
1 1...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #23:

score: 0
Accepted
time: 88ms
memory: 3912kb

input:

500
100
1 2 13 89 15 6 64 8 9 56 11 12 13 82 15 16 17 18 19 20 1 22 23 24 25 26 27 28 29 30 31 32 33 34 35 21 37 23 39 40 41 42 43 44 45 46 47 48 49 82 51 52 53 54 55 56 11 58 59 3 61 62 63 64 65 66 19 68 11 70 71 10 73 74 23 76 39 78 56 80 81 82 99 23 85 86 87 93 89 90 91 92 93 94 95 96 97 98 99 10...

output:

YES
2745
1 1
1 2
1 9
1 11
1 12
1 13
1 16
1 18
1 24
1 25
1 26
1 30
1 31
1 32
1 39
1 41
1 42
1 43
1 46
1 48
1 52
1 53
1 55
1 56
1 57
1 11
1 58
1 59
1 61
1 63
1 66
1 68
1 69
1 11
1 70
1 71
1 74
1 76
1 78
1 81
1 82
1 87
1 89
1 90
1 92
1 93
1 95
1 96
1 97
1 98
1 100
2 1 87
1 1
1 87
1 2
1 9
1 11
1 12
1 13...

result:

ok good! (YES count = 500, NO count = 0) (500 test cases)

Test #24:

score: 0
Accepted
time: 142ms
memory: 5020kb

input:

55
300
73 84 3 257 5 257 111 8 265 10 74 73 279 81 277 73 17 73 19 227 124 174 23 93 25 81 81 257 29 208 31 32 37 175 74 265 37 257 125 40 176 42 171 132 277 124 248 48 49 187 51 52 53 147 55 132 277 53 124 60 194 81 277 271 65 66 44 171 211 45 277 72 73 257 257 76 79 299 133 277 73 257 132 81 271 1...

output:

YES
70488
1 1
1 73
1 3
1 4
1 257
1 73
1 5
1 8
1 9
1 265
1 10
1 13
1 279
1 17
1 19
1 20
1 227
1 81
1 73
1 22
1 174
1 23
1 24
1 93
1 79
1 133
1 132
1 73
1 26
1 81
1 73
1 29
1 31
1 32
1 35
1 74
1 257
1 73
1 38
1 257
1 73
1 40
1 42
1 44
1 132
1 73
1 48
1 49
1 51
1 53
1 55
1 56
1 132
1 73
1 57
1 277
1 73...

result:

ok good! (YES count = 55, NO count = 0) (55 test cases)

Test #25:

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

input:

5
1000
1 2 3 4 705 6 7 8 9 10 11 781 13 231 15 16 17 18 19 20 21 22 23 24 25 26 27 401 29 42 31 445 667 289 35 36 37 761 996 40 41 42 43 251 45 46 47 231 49 50 51 52 53 54 55 56 57 35 59 60 61 62 63 64 65 66 538 401 69 70 71 72 73 74 75 554 77 78 79 344 81 82 83 84 85 442 51 88 89 90 91 92 93 94 891...

output:

YES
4765
1 157
1 189
1 240
1 604
1 318
1 400
1 480
1 812
1 886
1 913
1 942
1 157
1 189
1 400
1 480
1 812
1 886
1 913
1 942
1 157
1 189
1 400
1 480
1 812
1 886
1 913
1 942
1 157
1 189
1 400
1 480
1 812
1 886
1 913
1 942
1 157
1 189
1 400
1 480
1 812
1 886
1 913
1 942
1 157
1 189
1 400
1 480
1 812
1 8...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #26:

score: 0
Accepted
time: 18ms
memory: 5116kb

input:

5
1000
736 2 3 4 5 6 7 8 9 10 11 797 823 929 15 16 17 18 19 20 264 22 23 24 52 353 27 28 29 30 839 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 944 51 52 403 872 55 56 57 58 59 60 61 62 63 64 99 66 67 68 69 70 71 72 73 938 302 186 77 78 79 80 81 82 83 84 85 86 983 86 89 90 91 46 93 94 95 96...

output:

YES
47852
1 1
1 736
1 778
1 6
1 8
1 9
1 23
1 35
1 38
1 39
1 45
1 74
1 938
1 391
1 85
1 86
1 90
1 94
1 118
1 120
1 130
1 643
1 752
1 135
1 144
1 155
1 157
1 162
1 176
1 177
1 329
1 156
1 184
1 208
1 219
1 238
1 243
1 250
1 265
1 278
1 289
1 306
1 313
1 314
1 316
1 317
1 325
1 327
1 340
1 346
1 358
1 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #27:

score: 0
Accepted
time: 96ms
memory: 15780kb

input:

5
1000
487 446 3 4 5 6 442 8 452 10 601 12 300 895 15 208 866 328 19 20 21 967 644 24 25 118 27 28 787 30 31 344 33 139 350 440 37 369 39 918 41 42 190 483 45 46 556 48 360 807 188 608 53 67 55 333 398 397 853 60 61 953 676 678 65 66 882 483 69 369 71 72 763 576 75 76 77 78 724 574 310 193 83 84 85 ...

output:

YES
101518
1 14
1 895
1 19
1 46
1 53
1 57
1 398
1 118
1 139
1 65
1 68
1 483
1 328
1 118
1 139
1 73
1 763
1 373
1 819
1 574
1 287
1 76
1 77
1 85
1 89
1 952
1 43
1 190
1 91
1 118
1 139
1 121
1 139
1 141
1 914
1 188
1 787
1 147
1 168
1 735
1 214
1 169
1 184
1 190
1 197
1 200
1 202
1 207
1 210
1 939
1 3...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #28:

score: 0
Accepted
time: 55ms
memory: 6456kb

input:

5
1000
588 923 119 77 5 6 7 8 9 10 11 12 13 477 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 987 155 153 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 369 53 54 764 56 341 305 932 430 61 663 63 462 65 66 67 68 69 70 884 72 73 74 180 76 77 78 609 80 81 82 83 739 85 86 87 400 183 90 91 92 6...

output:

YES
25893
1 11
1 26
1 44
1 97
1 124
1 134
1 141
1 153
1 159
1 170
1 181
1 211
1 226
1 235
1 248
1 250
1 288
1 345
1 349
1 354
1 374
1 376
1 400
1 410
1 435
1 460
1 521
1 535
1 540
1 546
1 571
1 726
1 856
1 622
1 637
1 662
1 667
1 679
1 723
1 743
1 856
1 869
1 879
1 896
1 910
1 911
1 919
1 937
1 947
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #29:

score: 0
Accepted
time: 140ms
memory: 9592kb

input:

5
1000
816 2 519 284 253 990 965 581 457 414 232 451 581 519 581 406 581 965 581 20 519 337 383 253 581 26 27 587 900 34 862 215 915 439 439 370 816 189 387 134 103 249 361 964 809 367 47 103 452 760 67 862 253 915 467 103 215 439 816 516 581 103 87 581 439 66 249 68 621 497 71 417 581 439 63 673 10...

output:

YES
183075
1 1
1 816
1 821
1 439
1 311
1 4
1 284
1 581
1 311
1 18
1 965
1 439
1 311
1 34
1 439
1 311
1 36
1 370
1 253
1 439
1 311
1 37
1 816
1 311
1 38
1 189
1 439
1 311
1 40
1 134
1 311
1 56
1 103
1 311
1 58
1 439
1 311
1 63
1 87
1 439
1 311
1 87
1 311
1 101
1 439
1 311
1 103
1 311
1 104
1 581
1 31...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #30:

score: 0
Accepted
time: 94ms
memory: 9420kb

input:

5
1000
816 2 235 51 617 979 7 981 979 113 604 984 51 773 790 33 750 466 14 803 556 190 349 51 733 816 190 207 828 816 885 76 47 880 850 349 767 773 120 141 500 979 27 44 883 190 816 630 869 984 773 141 154 900 773 349 349 500 786 118 750 154 516 349 30 154 883 113 733 979 197 451 816 816 816 51 815 ...

output:

YES
315267
1 2
1 10
1 113
1 773
1 11
1 604
1 30
1 816
1 773
1 14
1 773
1 19
1 14
1 773
1 30
1 773
1 31
1 885
1 154
1 773
1 36
1 349
1 773
1 42
1 979
1 773
1 44
1 45
1 883
1 773
1 51
1 773
1 57
1 349
1 773
1 60
1 118
1 733
1 51
1 773
1 65
1 30
1 773
1 66
1 154
1 773
1 68
1 113
1 773
1 70
1 979
1 773
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #31:

score: 0
Accepted
time: 133ms
memory: 15736kb

input:

5
1000
1 2 3 22 949 6 7 8 9 10 11 12 547 33 1 16 17 520 19 20 21 22 23 928 111 26 631 994 29 236 657 32 33 34 35 898 37 38 765 685 41 42 43 44 45 46 961 48 49 556 51 619 53 785 55 56 57 180 59 60 61 62 166 64 65 66 67 95 69 70 71 72 73 74 75 866 77 78 79 80 328 82 257 243 85 86 87 88 89 90 91 92 93 ...

output:

YES
112115
1 1
1 2
1 3
1 7
1 16
1 21
1 22
1 27
1 631
1 443
1 29
1 32
1 33
1 35
1 37
1 38
1 49
1 62
1 64
1 71
1 81
1 328
1 466
1 85
1 86
1 89
1 97
1 108
1 110
1 116
1 126
1 558
1 117
1 118
1 120
1 122
1 123
1 126
1 558
1 129
1 139
1 142
1 145
1 150
1 153
1 159
1 160
1 126
1 558
1 163
1 167
1 390
1 3
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #32:

score: 0
Accepted
time: 139ms
memory: 15548kb

input:

5
1000
1 2 924 4 5 6 7 8 9 10 867 919 13 8 15 850 17 18 922 20 884 543 23 824 25 47 990 28 29 30 791 32 33 34 35 208 37 38 39 491 41 870 43 274 45 46 47 410 49 50 871 52 53 54 55 540 57 58 59 60 61 62 63 94 65 66 67 68 924 70 71 72 73 74 75 76 407 78 79 980 81 82 83 84 85 86 87 514 89 90 91 92 619 9...

output:

YES
75358
1 1
1 4
1 5
1 13
1 17
1 35
1 39
1 41
1 45
1 50
1 53
1 59
1 74
1 86
1 91
1 98
1 104
1 119
1 123
1 124
1 130
1 134
1 137
1 138
1 140
1 149
1 156
1 804
1 124
1 177
1 181
1 184
1 197
1 202
1 207
1 720
1 212
1 403
1 407
1 695
1 216
1 218
1 220
1 222
1 225
1 226
1 227
1 234
1 270
1 274
1 278
1 2...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #33:

score: 0
Accepted
time: 46ms
memory: 3780kb

input:

100000
4
1 2 3 1
3 1 1 4
4
1 2 3 4
4 1 4 2
4
1 2 3 4
1 1 3 3
4
1 2 1 4
4 3 4 1
4
1 2 3 4
2 3 2 4
4
1 3 3 3
2 3 1 4
4
1 2 3 4
2 3 4 4
4
1 2 2 2
2 3 1 4
4
1 2 3 4
2 4 1 1
4
2 3 3 4
3 1 3 3
4
1 2 3 4
3 3 4 2
4
3 1 3 1
3 2 4 2
4
1 2 1 1
3 4 4 1
4
1 2 4 4
3 1 2 3
4
2 2 3 4
3 3 2 3
4
1 2 3 3
1 4 4 4
4
2 2...

output:

NO
NO
YES
9
1 2
1 4
2 2 1
1 2
1 1
1 4
2 4 3
1 4
1 3
NO
NO
NO
YES
15
1 1
1 2
1 3
2 1 2
1 1
1 2
1 2
1 3
2 2 3
1 2
1 3
1 3
2 3 4
1 3
1 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
20
1 2
1 4
1 3
1 4
1 2
1 4
1 3
1 4
2 3 4
1 3
1 4
1 2
1 4
1 4
2 4 1
1 4
1 1
1 2
1 4
1 1
NO
NO
YES
15
1 2
1 3
1 4
2 2 3
1 2
1 3
1 3...

result:

ok good! (YES count = 22427, NO count = 77573) (100000 test cases)

Test #34:

score: 0
Accepted
time: 60ms
memory: 4044kb

input:

100000
5
1 2 3 4 5
1 3 3 5 3
5
1 2 3 4 5
2 3 1 4 4
5
3 2 3 3 5
3 3 2 4 3
5
1 2 3 4 5
3 4 2 3 5
5
1 3 3 5 5
2 5 2 2 3
5
1 2 3 4 5
4 3 2 1 4
5
1 2 3 4 5
2 3 5 1 5
5
1 4 3 4 5
4 3 1 4 4
5
1 2 5 4 1
1 3 1 2 5
5
1 5 3 4 5
5 5 5 3 1
5
1 3 3 4 2
1 1 2 4 3
5
1 2 3 4 5
1 4 3 5 4
5
1 2 3 4 3
3 2 5 3 4
5
1 2 5...

output:

YES
18
1 2
1 4
1 5
1 2
1 4
1 5
2 2 3
1 2
1 3
1 4
1 5
2 4 5
1 4
1 5
1 5
2 5 3
1 5
1 3
NO
NO
NO
NO
NO
YES
22
1 1
1 2
1 3
1 4
2 4 1
1 4
1 1
1 1
1 2
1 3
2 1 2
1 1
1 2
1 2
1 3
2 2 3
1 2
1 3
1 3
2 3 5
1 3
1 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
22
1 1
1 2
1 4
1 5
2 1 4
1 1
1 4
1 2
1 4
1 5
2 2 4
1 2
1 4
1 4
1 5...

result:

ok good! (YES count = 25378, NO count = 74622) (100000 test cases)

Test #35:

score: 0
Accepted
time: 50ms
memory: 3880kb

input:

100000
5
2 2 3 4 2
1 2 1 2 2
5
1 2 3 2 5
4 1 2 5 3
5
2 2 3 2 1
2 2 5 2 3
5
1 2 3 4 1
3 1 4 5 4
5
1 2 3 4 5
2 4 1 2 3
5
1 2 3 4 5
2 3 4 1 3
5
1 2 3 4 5
2 2 1 4 2
5
1 2 4 4 5
2 3 5 3 4
5
1 5 3 5 5
5 2 4 2 2
5
4 3 3 4 5
3 1 2 2 3
5
5 5 3 5 5
4 2 3 3 4
5
1 2 3 4 5
1 4 3 3 5
5
1 4 3 4 5
2 2 1 5 5
5
1 2 3...

output:

NO
NO
NO
NO
NO
NO
YES
17
1 1
1 3
1 5
2 3 1
1 3
1 1
1 1
1 5
1 1
1 5
2 5 2
1 5
1 2
1 1
2 1 2
1 1
1 2
NO
NO
NO
NO
YES
12
1 2
1 4
1 2
1 4
2 2 4
1 2
1 4
1 4
1 4
2 4 3
1 4
1 3
NO
NO
NO
NO
NO
YES
29
1 1
1 4
1 2
1 3
1 4
1 1
1 4
1 2
1 3
1 4
2 2 4
1 2
1 4
1 1
1 4
1 3
1 4
2 3 5
1 3
1 5
1 1
1 4
1 4
2 4 5
1 4
1 ...

result:

ok good! (YES count = 17905, NO count = 82095) (100000 test cases)

Test #36:

score: 0
Accepted
time: 76ms
memory: 3792kb

input:

100000
6
1 2 3 3 5 1
3 4 1 6 5 4
6
6 2 3 4 5 6
5 1 1 5 5 4
6
1 2 3 4 3 6
4 5 1 1 3 5
6
4 2 1 4 5 6
2 3 4 1 3 1
6
1 2 3 4 5 6
4 1 3 3 1 2
6
2 6 3 3 5 6
3 2 6 6 3 4
6
4 2 3 3 5 6
4 3 6 5 5 3
6
1 2 3 4 5 6
3 2 6 3 4 2
6
1 2 3 4 5 6
6 4 5 4 4 3
6
1 2 3 4 4 5
6 4 3 5 1 5
6
1 6 3 4 1 1
1 3 5 3 2 3
6
1 2 3...

output:

NO
NO
NO
NO
YES
30
1 1
1 2
1 4
1 5
1 6
2 5 1
1 5
1 1
1 1
1 2
1 4
1 6
2 6 2
1 6
1 2
1 1
1 2
1 4
2 2 1
1 2
1 1
1 1
1 4
2 1 4
1 1
1 4
1 4
2 4 3
1 4
1 3
NO
NO
YES
30
1 1
1 3
1 4
1 5
1 6
2 1 3
1 1
1 3
1 3
1 4
1 5
1 6
2 5 4
1 5
1 4
1 3
1 4
1 6
2 4 3
1 4
1 3
1 3
1 6
2 3 6
1 3
1 6
1 6
2 6 2
1 6
1 2
YES
30
1...

result:

ok good! (YES count = 14853, NO count = 85147) (100000 test cases)

Test #37:

score: 0
Accepted
time: 75ms
memory: 3780kb

input:

100000
6
3 2 3 4 5 6
5 3 2 2 2 4
6
1 2 2 4 5 6
1 4 1 3 4 5
6
1 2 3 6 5 6
4 1 3 4 4 5
6
1 2 3 6 5 6
1 6 6 2 2 2
6
1 2 3 4 5 6
3 2 3 2 2 6
6
1 2 3 4 5 6
4 4 2 6 1 5
6
4 2 3 4 5 6
5 5 4 5 6 2
6
1 2 3 4 5 6
4 5 5 2 1 3
6
1 2 3 4 5 6
5 1 5 5 5 5
6
1 2 3 4 2 5
2 4 6 6 6 5
6
1 2 5 4 5 6
5 2 5 5 2 4
6
1 2 3...

output:

NO
NO
NO
NO
YES
15
1 1
1 4
1 5
2 1 3
1 1
1 3
1 4
1 5
2 4 2
1 4
1 2
1 5
2 5 2
1 5
1 2
NO
NO
NO
YES
30
1 1
1 2
1 3
1 4
1 6
2 2 1
1 2
1 1
1 1
1 3
1 4
1 6
2 3 5
1 3
1 5
1 1
1 4
1 6
2 4 5
1 4
1 5
1 1
1 6
2 6 5
1 6
1 5
1 1
2 1 5
1 1
1 5
NO
YES
25
1 1
1 4
1 5
1 6
2 1 5
1 1
1 5
1 4
1 5
1 6
1 4
1 5
1 6
2 6 4...

result:

ok good! (YES count = 10145, NO count = 89855) (100000 test cases)

Test #38:

score: 0
Accepted
time: 135ms
memory: 4152kb

input:

100000
7
1 2 3 3 5 6 7
2 6 1 7 2 1 7
7
1 2 3 4 5 5 7
5 2 4 7 7 4 4
7
1 2 3 4 5 6 7
5 6 2 6 3 6 1
7
1 2 2 4 5 6 2
7 1 3 5 5 2 2
7
1 4 3 4 5 6 7
6 2 7 7 5 5 3
7
1 2 3 4 5 6 7
5 3 1 2 7 7 7
7
4 2 3 4 5 6 7
4 6 1 2 3 3 4
7
1 2 3 4 5 6 7
6 5 6 3 7 2 5
7
1 2 3 4 5 6 7
2 1 6 1 4 6 2
7
1 2 3 4 5 6 7
2 3 5 3...

output:

NO
NO
YES
39
1 1
1 2
1 3
1 4
1 5
1 7
2 4 6
1 4
1 6
1 1
1 2
1 3
1 5
1 7
2 7 1
1 7
1 1
1 1
1 2
1 3
1 5
2 1 5
1 1
1 5
1 2
1 3
1 5
2 5 3
1 5
1 3
1 2
1 3
2 3 2
1 3
1 2
1 2
2 2 6
1 2
1 6
NO
NO
YES
39
1 1
1 2
1 3
1 4
1 5
1 6
2 4 2
1 4
1 2
1 1
1 2
1 3
1 5
1 6
2 6 7
1 6
1 7
1 1
1 2
1 3
1 5
2 2 3
1 2
1 3
1 1
...

result:

ok good! (YES count = 12760, NO count = 87240) (100000 test cases)

Test #39:

score: 0
Accepted
time: 133ms
memory: 4048kb

input:

100000
7
1 2 3 4 3 6 7
4 1 4 6 1 4 7
7
3 2 3 4 5 6 7
1 5 7 3 1 3 7
7
1 6 3 6 6 6 6
4 4 7 6 6 6 2
7
5 2 3 4 5 6 7
4 3 1 6 1 3 7
7
1 2 3 4 5 6 7
7 5 7 3 7 3 5
7
1 4 3 4 5 6 4
1 1 7 3 3 7 2
7
1 2 3 4 5 6 7
4 5 7 6 4 3 1
7
1 7 5 4 1 6 7
6 1 5 7 7 6 1
7
4 2 3 4 5 4 7
1 2 5 2 7 6 5
7
1 2 3 4 5 1 7
4 6 1 7...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
26
1 2
1 5
1 6
1 7
1 2
1 5
1 6
1 7
2 2 5
1 2
1 5
1 5
1 6
1 7
2 7 6
1 7
1 6
1 5
1 6
2 5 3
1 5
1 3
1 6
2 6 4
1 6
1 4
NO
NO
NO
NO
NO
YES
39
1 1
1 2
1 3
1 5
1 6
1 7
2 6 4
1 6
1 4
1 1
1 2
1 3
1 5
1 7
2 7 3
1 7
1 3
1 1
1 2
1 3
1 5
2 3 2
1 3
1 2
1 1
1 2
1...

result:

ok good! (YES count = 8596, NO count = 91404) (100000 test cases)

Test #40:

score: 0
Accepted
time: 115ms
memory: 3840kb

input:

78125
8
1 8 8 4 5 8 3 8
8 3 6 2 7 4 8 2
8
4 2 3 4 6 6 8 8
4 8 5 6 4 3 8 5
8
1 2 2 2 5 6 5 8
3 6 8 8 7 5 2 4
8
1 2 3 4 5 6 7 1
7 7 2 5 1 8 4 8
8
1 2 3 4 5 8 3 3
8 2 3 4 4 1 5 8
8
1 7 7 7 2 7 7 8
4 7 2 7 1 5 2 6
8
1 8 3 7 5 4 7 8
8 2 8 8 3 5 2 8
8
1 2 3 8 7 6 7 8
7 7 7 2 2 2 3 5
8
1 2 8 4 5 6 7 8
5 2 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
YES
40
1 1
1 4
1 6
1 7
1 8
1 1
1 4
1 6
1 7
1 8
1 1
1 4
1 6
1 7
1 8
2 4 8
1 4
1 8
1 1
1 6
1 7
1 8
2 6 7
1 6
1 7
1 1
1 7
1 8
2 8 5
1 8
1 5
1 1
1 7
2 7 1
1 7
1 1
1 1
2 1 5
1 1
1 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 4011, NO count = 74114) (78125 test cases)

Test #41:

score: 0
Accepted
time: 71ms
memory: 4148kb

input:

61728
9
1 2 4 4 9 6 6 8 9
4 1 4 7 2 9 1 7 2
9
1 2 1 4 5 3 7 8 8
9 1 5 5 6 8 4 2 6
9
1 1 9 1 5 1 7 1 9
4 2 1 7 5 2 5 8 5
9
1 2 3 4 5 6 7 4 9
9 7 4 8 6 4 9 6 2
9
3 6 4 4 5 7 7 3 6
1 7 4 7 2 4 6 7 9
9
1 5 9 2 5 3 7 2 9
1 7 7 4 3 9 8 3 1
9
3 2 3 8 5 6 7 8 9
7 6 1 8 5 6 9 5 4
9
1 2 3 3 5 8 5 8 9
5 8 7 1 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
43
1 1
1 2
1 5
1 6
1 7
1 9
2 1 5
1 1
1 5
1 2
1 5
1 6
1 7
1 9
2 2 8
1 2
1 8
1 5
1 6
1 7
1 9
1 5
1 6
1 7
1 9
2 6 7
1 6
1 7
1 5
1 7
1 9
2 5 9
1 5
1 9
1 7
1 9
2 7 4
1 7
1 4
1 9
2 9 8
1 9
1 8
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok good! (YES count = 2842, NO count = 58886) (61728 test cases)

Test #42:

score: 0
Accepted
time: 64ms
memory: 3848kb

input:

41322
11
1 9 3 3 3 9 7 3 3 10 3
8 5 5 8 1 8 7 7 8 1 3
11
1 2 3 4 5 9 7 8 9 9 11
6 6 9 1 8 1 8 3 10 10 9
11
1 2 1 4 1 1 7 6 4 2 1
6 4 3 6 7 2 8 2 11 1 3
11
1 2 3 4 5 7 5 8 5 10 10
4 3 3 3 6 3 8 3 8 11 6
11
6 6 2 4 6 6 2 6 9 10 11
7 5 6 3 1 8 10 9 4 11 10
11
1 2 3 4 5 6 7 8 9 1 1
4 11 3 10 1 10 8 2 3 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
79
1 1
1 2
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 1 5
1 1
1 5
1 2
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 2 7
1 2
1 7
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 8 4
1 8
1 4
1 4
1 5
1 6
1 7
1 9
1 10
2 9 7
1 9
1 7
1 4
1 5
1 6
1 7...

result:

ok good! (YES count = 1240, NO count = 40082) (41322 test cases)

Test #43:

score: 0
Accepted
time: 70ms
memory: 3880kb

input:

50000
10
1 3 5 4 5 6 7 3 6 5
2 8 7 10 7 4 10 8 4 10
10
1 10 4 4 5 2 10 2 9 10
1 5 8 7 1 4 5 9 2 8
10
1 2 3 4 5 6 10 8 9 10
1 6 5 7 7 8 2 5 9 7
10
9 2 4 8 5 2 3 8 8 3
6 2 7 10 6 10 2 9 3 7
10
6 2 5 4 5 6 6 1 5 6
4 9 6 7 8 10 2 1 5 6
10
1 2 5 4 1 6 10 8 9 10
9 1 9 7 2 9 2 6 4 8
10
1 2 3 4 5 6 7 8 9 10...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
63
1 1
1 2
1 3
1 4
1 6
1 7
1 8
1 10
2 1 6
1 1
1 6
1 2
1 3
1 4
1 6
1 7
1 8
1 10
2 2 9
1 2
1 9
1 3
1 4
1 6
1 7
1 8
1 10
2 4 3
1 4
1 3
1 3
1 6
1 7
1 8
1 10
2 8 10
1 8
1 10
1 3
...

result:

ok good! (YES count = 1641, NO count = 48359) (50000 test cases)

Test #44:

score: 0
Accepted
time: 61ms
memory: 3744kb

input:

34722
12
1 2 10 8 5 8 7 8 8 8 9 9
1 8 7 8 2 8 1 4 9 2 7 12
12
1 2 6 4 5 1 7 8 9 8 11 12
5 9 7 5 1 5 7 11 8 11 3 6
12
1 2 3 4 5 2 7 8 9 10 5 12
11 5 1 1 11 9 6 10 2 8 5 2
12
1 2 1 4 11 6 7 11 1 10 11 12
4 9 10 6 11 8 8 10 5 1 5 11
12
1 1 11 9 5 1 7 8 9 11 11 12
5 8 8 12 7 6 7 11 6 5 8 9
12
1 7 4 7 7 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
108
1 1
1 2
1 3
1 4
1 5
1 6
1 9
1 8
1 8
1 9
1 8
1 10
1 11
1 12
2 4 1
1 4
1 1
1 1
1 2
1 3
1 5
1 8
1 9
1 8
1 10
1 11
1 12
2 5 3
1 5
1 3
1 1
1 2
1 3
1 8
1 9
1 8
1 10
1 11
1 12
1 1
1 2
1 3
1 8
1 9
1...

result:

ok good! (YES count = 768, NO count = 33954) (34722 test cases)

Test #45:

score: 0
Accepted
time: 50ms
memory: 3892kb

input:

12500
20
1 2 3 4 6 13 7 13 9 13 11 12 13 14 13 9 17 18 19 13
20 15 9 3 4 7 5 6 10 7 18 4 14 8 6 9 15 6 8 12
20
9 10 10 4 9 8 17 8 9 10 11 9 13 17 17 16 10 10 10 10
15 16 13 13 18 4 6 15 20 11 19 12 2 4 20 20 19 17 11 7
20
15 15 3 4 5 4 7 8 9 2 11 18 2 15 15 2 8 18 19 15
2 17 2 11 9 15 16 14 18 19 5 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 77, NO count = 12423) (12500 test cases)

Test #46:

score: 0
Accepted
time: 37ms
memory: 3912kb

input:

2000
50
1 49 25 25 25 9 7 25 27 10 45 40 37 14 24 46 17 18 19 45 40 24 34 34 34 26 46 34 40 24 32 32 34 34 34 40 45 38 45 24 27 42 40 27 45 46 47 36 36 48
45 45 40 35 20 29 50 12 24 4 22 19 27 21 46 17 7 14 13 18 2 17 5 42 7 35 46 21 41 20 48 12 3 47 29 20 8 37 20 43 12 28 47 25 17 38 25 7 21 28
50
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 1, NO count = 1999) (2000 test cases)

Test #47:

score: 0
Accepted
time: 50ms
memory: 4040kb

input:

500
100
29 18 29 55 29 67 29 8 55 10 45 55 55 14 26 29 17 55 60 76 60 55 19 80 55 29 29 67 55 60 9 45 33 34 55 60 18 38 29 67 29 45 27 9 55 26 55 74 74 29 60 26 18 45 55 60 45 26 59 55 55 62 9 64 55 66 55 68 55 11 45 55 82 55 26 9 60 18 79 11 60 26 74 84 76 53 87 9 9 16 11 55 55 60 29 55 45 73 29 60...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 0, NO count = 500) (500 test cases)

Test #48:

score: 0
Accepted
time: 730ms
memory: 27852kb

input:

5
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

YES
1624747
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)