QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345880#2729. Flop SortingOccDreamer25 ✓35ms7316kbC++142.6kb2024-03-07 16:36:462024-03-07 16:36:48

Judging History

This is the latest submission verdict.

  • [2024-03-07 16:36:48]
  • Judged
  • Verdict: 25
  • Time: 35ms
  • Memory: 7316kb
  • [2024-03-07 16:36:46]
  • Submitted

answer

//code by Emissary
#include<bits/stdc++.h>

#define fi first
#define se second
#define vc vector
#define db double
#define ll long long
#define mk make_pair
#define pb push_back
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(int x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(int x){write(x), putchar(32);}
	inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;

const int MAXN = 5e5+5;

int n;
int a[MAXN], b[MAXN], c[MAXN];

vc<PI> ans[2];

inline void rev(int l, int r, int t){
	for(int i=l, j=r;i<j;++i, --j) ans[t].pb(mk(i,j)), swap(a[i],a[j]);
	return ;
}

inline void Merge(int l, int r, int t){
	int mid=(l+r)>>1, pos=l;
	int len=mid-l+1; vc<int> num;
	while(pos<r && a[pos]<a[pos+1]) ++pos;
	if(pos==r) return ;
	for(int i=l;i<=r;++i) num.pb(a[i]);
	sort(num.begin(),num.end()); int std_=num[len-1], L=n+1, R=0, vl=n+1, vr=0;
	for(int i=l;i<=pos;++i){
		if(a[i]>std_){
			L=i; vl=min(vl,i); vr=max(vr,pos);
			rev(i,pos,t);
			break;
		}
	}
	for(int i=r;i>pos;--i){
		if(a[i]<=std_){
			R=i; vr=max(vr,i); vl=min(vl,pos+1);
			rev(pos+1,i,t);
			break;
		}
	}
	if(vl<=vr) rev(vl,vr,t);
	Merge(l,mid,t); Merge(mid+1,r,t);
	return ;
}

inline void MergeSort(int l, int r, int t){
	if(l==r) return ;
	int mid=(l+r)>>1;
	MergeSort(l,mid,t); MergeSort(mid+1,r,t);
	Merge(l,r,t);
}

inline void op(int l, int r){
	int maxn=-1, maxpos, minn=n+1, minpos;
	for(int i=l;i<=r;++i) if(b[i]>maxn) maxn=b[i], maxpos=i;
	for(int i=l;i<=r;++i) if(b[i]<minn) minn=b[i], minpos=i;
	swap(b[minpos],b[maxpos]);
}

signed main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read(), b[i]=a[i];
	MergeSort(1,n,0);
	for(int i=1;i<=n;++i) a[i]=read(), c[i]=a[i];
	MergeSort(1,n,1);
	eprint(ans[0].size()+ans[1].size());
	for(auto i:ans[0]) sprint(i.fi), eprint(i.se), op(i.fi,i.se);
	reverse(ans[1].begin(),ans[1].end());
	for(auto i:ans[1]) sprint(i.fi), eprint(i.se), op(i.fi,i.se);
	return 0;
}





































































Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3600kb

input:

2
1 2
2 1

output:

1
1 2

result:

ok correct answer!

Test #2:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

100
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 76 75 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
63 2...

output:

861
75 76
98 99
99 100
96 98
95 99
97 99
95 96
89 91
90 91
90 92
91 92
93 94
92 95
91 96
94 95
93 96
91 92
85 86
84 87
83 88
86 88
83 85
80 82
81 82
77 79
76 80
78 79
77 80
80 82
79 83
78 84
77 85
82 83
81 84
80 85
77 79
85 87
84 88
83 89
82 90
81 91
80 92
87 89
86 90
85 91
84 92
81 82
80 83
64 66
6...

result:

ok correct answer!

Test #3:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

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

output:

946
6 7
4 5
2 3
2 4
8 9
9 10
8 9
12 13
9 10
11 12
9 12
10 11
9 10
8 10
12 13
11 12
6 7
8 9
6 9
7 8
4 5
4 6
3 4
6 7
5 6
14 15
15 16
14 15
17 18
18 19
20 21
21 22
20 21
23 24
24 25
23 24
21 22
23 24
21 24
22 23
20 21
17 19
20 22
17 22
18 21
19 20
16 17
15 16
17 18
21 22
23 24
21 24
22 23
20 21
24 25
2...

result:

ok correct answer!

Test #4:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

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

output:

1741
1 2
1 2
3 4
1 4
2 3
5 6
6 7
5 6
3 4
5 6
3 6
4 5
2 3
3 4
8 9
9 10
11 12
12 13
10 11
11 12
5 7
8 10
5 10
6 9
7 8
4 5
2 3
2 4
1 2
10 11
9 10
8 9
12 13
11 13
18 19
17 18
15 16
17 18
15 18
16 17
15 16
14 16
24 25
23 24
22 23
21 22
24 25
23 25
18 19
20 21
18 21
19 20
17 18
20 21
22 24
20 24
21 23
24 ...

result:

ok correct answer!

Test #5:

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

input:

2
1 2
2 1

output:

1
1 2

result:

ok correct answer!

Test #6:

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

input:

2
1 2
2 1

output:

1
1 2

result:

ok correct answer!

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 10
Accepted
time: 9ms
memory: 3900kb

input:

2048
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 101...

output:

61623
131 132
132 133
134 135
133 135
135 136
136 137
138 141
139 140
137 141
138 140
142 143
141 143
143 144
144 145
146 153
147 152
148 151
149 150
145 153
146 152
147 151
148 150
154 157
155 156
153 157
154 156
158 159
157 159
159 160
160 161
162 177
163 176
164 175
165 174
166 173
167 172
168 17...

result:

ok correct answer!

Test #8:

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

input:

2048
1056 1019 49 2042 1100 323 409 1849 974 957 1355 1207 564 1922 441 1124 665 879 276 637 481 578 1252 1401 1268 1384 1478 13 1485 82 1753 339 1108 1845 1762 1751 950 689 1935 988 272 901 707 1993 675 1248 961 1901 1307 731 1570 262 1488 1012 1058 893 220 465 534 837 1644 1005 1878 513 1502 703 1...

output:

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

result:

ok correct answer!

Test #9:

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

input:

2048
1 2 3 5 8 12 13 15 17 20 25 26 27 30 31 35 39 40 41 42 46 49 54 55 58 59 61 64 67 69 71 73 75 76 79 82 84 85 86 87 90 91 94 96 99 100 101 102 105 110 113 116 120 123 124 127 128 132 133 143 145 149 154 156 158 159 160 161 163 164 169 170 172 174 175 178 182 186 188 190 193 194 198 199 201 204 2...

output:

71030
1025 1026
1027 1028
1025 1026
1027 1028
1025 1028
1026 1027
1029 1030
1031 1032
1029 1030
1031 1032
1029 1032
1030 1031
1025 1028
1026 1027
1029 1032
1030 1031
1025 1032
1026 1031
1027 1030
1028 1029
1033 1034
1035 1036
1033 1034
1035 1036
1033 1036
1034 1035
1037 1038
1039 1040
1037 1038
1039...

result:

ok correct answer!

Test #10:

score: 0
Accepted
time: 3ms
memory: 3928kb

input:

2048
274 1169 1233 1420 165 1883 469 394 712 535 430 1138 1993 1850 1037 1083 532 1415 276 1508 345 1632 245 115 939 698 639 791 2046 943 654 147 1783 903 878 798 1072 1400 1839 1866 847 1999 739 569 110 705 302 221 248 1805 741 749 464 646 1476 1842 1706 845 839 1133 396 1906 732 1372 624 714 1378 ...

output:

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

result:

ok correct answer!

Test #11:

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

input:

2048
2048 1024 1536 512 1792 768 1280 256 1920 896 1408 384 1664 640 1152 128 1984 960 1472 448 1728 704 1216 192 1856 832 1344 320 1600 576 1088 64 2016 992 1504 480 1760 736 1248 224 1888 864 1376 352 1632 608 1120 96 1952 928 1440 416 1696 672 1184 160 1824 800 1312 288 1568 544 1056 32 2032 1008...

output:

124533
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
...

result:

ok correct answer!

Test #12:

score: 0
Accepted
time: 13ms
memory: 4548kb

input:

2048
2048 1024 1536 512 1792 768 1280 256 1920 896 1408 384 1664 640 1152 128 1984 960 1472 448 1728 704 1216 192 1856 832 1344 320 1600 576 1088 64 2016 992 1504 480 1760 736 1248 224 1888 864 1376 352 1632 608 1120 96 1952 928 1440 416 1696 672 1184 160 1824 800 1312 288 1568 544 1056 32 2032 1008...

output:

114067
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
...

result:

ok correct answer!

Test #13:

score: 0
Accepted
time: 11ms
memory: 3868kb

input:

2048
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 ...

output:

78094
76 77
78 79
77 79
79 80
80 81
82 89
83 88
84 87
85 86
81 89
82 88
83 87
84 86
90 93
91 92
89 93
90 92
94 95
93 95
95 96
96 97
98 113
99 112
100 111
101 110
102 109
103 108
104 107
105 106
97 113
98 112
99 111
100 110
101 109
102 108
103 107
104 106
114 121
115 120
116 119
117 118
113 121
114 1...

result:

ok correct answer!

Test #14:

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

input:

2048
2048 1024 1536 512 1792 768 1280 256 1920 896 1408 384 1664 640 1152 128 1984 960 1472 448 1728 704 1216 192 1856 832 1344 320 1600 576 1088 64 2016 992 1504 480 1760 736 1248 224 1888 864 1376 352 1632 608 1120 96 1952 928 1440 416 1696 672 1184 160 1824 800 1312 288 1568 544 1056 32 2032 1008...

output:

95488
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
1...

result:

ok correct answer!

Test #15:

score: 0
Accepted
time: 10ms
memory: 4444kb

input:

2035
232 604 108 1681 1329 1518 1018 968 1764 178 940 932 615 911 618 1855 871 1410 1667 750 1367 100 641 807 1099 387 1278 821 494 1233 1062 1713 1293 1105 1601 1421 540 544 1695 620 310 756 1322 2030 1292 1721 1450 378 1849 370 1395 155 1069 405 1819 908 90 1422 1178 959 1351 1332 194 1816 2017 12...

output:

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

result:

ok correct answer!

Test #16:

score: 0
Accepted
time: 10ms
memory: 4564kb

input:

2037
1963 1717 326 418 803 764 1966 1581 741 1258 1940 1651 1352 940 1317 372 1334 1576 654 1242 1450 1502 347 352 881 1344 332 1086 1385 1816 1795 1608 1428 1786 1182 1681 1667 561 353 984 1275 614 1589 188 732 1224 763 99 1044 1220 1365 1633 1423 58 755 1776 1595 28 238 1900 366 1489 577 1623 92 1...

output:

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

result:

ok correct answer!

Test #17:

score: 0
Accepted
time: 13ms
memory: 4428kb

input:

2047
1237 1466 1161 1855 1955 5 1208 1634 452 1585 182 134 252 880 1150 1826 1204 1379 189 1671 1422 673 1977 247 831 1217 1301 330 1828 96 1025 91 1136 1338 2001 2046 1072 370 610 2014 1669 644 718 1937 1529 1145 1899 597 694 1885 670 1644 95 128 498 1995 1893 297 576 1633 137 565 859 1944 1304 169...

output:

103188
2 3
1 2
5 6
6 7
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
11 12
9 10
11 12
9 12
10 11
12 13
11 12
14 15
13 15
3 8
4 7
5 6
9 14
10 13
11 12
3 14
4 13
5 12
6 11
7 10
8 9
3 5
2 5
3 4
6 7
5 7
7 8
12 14
12 15
13 14
14 15
14 16
18 19
17 18
21 22
23 24
22 23
21 22
19 20
21 22
19 22
20 21
18 19
19 20
22 23...

result:

ok correct answer!

Test #18:

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

input:

2048
1283 1643 1012 1661 111 1616 1513 1354 53 1540 1602 1081 992 336 98 1595 1938 1098 946 1926 224 1002 345 825 63 870 1331 952 1535 1269 1690 360 895 691 1197 424 1581 1090 1380 1804 1738 238 934 803 955 1923 860 939 1422 1962 1421 654 827 2005 120 1700 587 1570 486 971 2047 1827 184 115 1006 908...

output:

103345
2 3
1 2
7 8
6 7
7 8
3 4
5 6
3 6
4 5
2 3
1 2
5 6
7 8
5 8
6 7
11 12
10 11
13 14
14 15
13 14
10 12
13 15
10 15
11 14
12 13
15 16
4 8
5 7
9 13
10 12
4 13
5 12
6 11
7 10
8 9
2 3
4 6
2 6
3 5
2 3
1 3
6 7
5 6
7 8
11 13
14 15
11 15
12 14
14 15
14 16
13 14
17 18
18 19
17 18
19 20
22 23
23 24
18 20
21 2...

result:

ok correct answer!

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #19:

score: 10
Accepted
time: 22ms
memory: 4408kb

input:

4096
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 3815 90 91 92 93 94 95 96 97 98 99 100 1...

output:

144821
89 90
90 91
91 92
92 93
94 95
93 95
95 96
96 97
98 113
99 112
100 111
101 110
102 109
103 108
104 107
105 106
97 113
98 112
99 111
100 110
101 109
102 108
103 107
104 106
114 121
115 120
116 119
117 118
113 121
114 120
115 119
116 118
122 125
123 124
121 125
122 124
126 127
125 127
127 128
18...

result:

ok correct answer!

Test #20:

score: 0
Accepted
time: 21ms
memory: 4456kb

input:

4096
360 3709 3751 3190 3157 4040 3985 3628 3104 1368 241 1983 1283 687 1969 2370 3736 2670 2732 955 373 2279 3919 3448 2616 3838 2385 3177 3210 3145 2186 1617 297 53 1540 2259 3150 2094 3068 1623 908 3344 1311 201 1746 548 2578 535 1528 2981 3192 1468 495 1308 504 2426 2836 681 843 1564 782 3179 66...

output:

143361
3 4
2 3
7 8
6 7
7 8
3 4
5 6
3 6
4 5
2 3
9 10
10 11
9 10
11 12
13 14
11 12
13 14
11 14
12 13
10 11
11 12
14 15
13 14
15 16
2 8
3 7
4 6
9 15
10 14
11 13
2 15
3 14
4 13
5 12
6 11
7 10
8 9
2 4
2 4
1 2
12 15
13 14
12 16
13 15
10 11
10 12
9 10
17 18
19 20
18 19
17 18
19 20
23 24
19 20
21 22
19 22
2...

result:

ok correct answer!

Test #21:

score: 0
Accepted
time: 30ms
memory: 4452kb

input:

4096
1 5 6 7 8 10 12 13 17 20 21 22 24 25 29 30 31 32 36 37 38 41 42 45 46 49 50 51 52 54 59 66 67 69 70 72 75 78 79 82 84 85 86 89 91 92 93 98 99 100 101 102 107 108 115 117 118 119 121 122 123 124 125 127 129 130 133 136 139 140 141 142 145 146 147 148 150 151 153 154 155 157 158 159 160 166 167 1...

output:

167413
2049 2050
2051 2052
2049 2050
2051 2052
2049 2052
2050 2051
2053 2054
2055 2056
2053 2054
2055 2056
2053 2056
2054 2055
2049 2052
2050 2051
2053 2056
2054 2055
2049 2056
2050 2055
2051 2054
2052 2053
2057 2058
2059 2060
2057 2058
2059 2060
2057 2060
2058 2059
2061 2062
2063 2064
2061 2062
206...

result:

ok correct answer!

Test #22:

score: 0
Accepted
time: 21ms
memory: 4876kb

input:

4096
514 1174 2556 2207 1278 1582 2624 242 2206 1420 1367 2049 1734 1461 3646 1049 3320 1134 1443 1685 2247 1351 1611 4050 268 1646 1924 1453 3135 1500 1925 3956 2098 3385 1717 1895 667 1291 287 4092 4032 2693 908 3650 1093 797 760 630 723 2681 1010 1508 146 2899 3897 917 863 248 720 2340 202 3074 2...

output:

167007
3 4
7 8
6 7
5 6
3 4
5 6
3 6
4 5
2 3
1 2
6 7
5 6
9 10
10 11
9 10
11 12
13 14
15 16
14 15
13 14
11 12
13 14
11 14
12 13
10 11
9 10
14 15
13 14
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
4 5
3 4
10 12
13 15
10 15
11 14
12 13
17 18
18 19
19 20
21 22
22 23
19 20
21 22
19 22
20 21
18 19
22 23
27 28
26 2...

result:

ok correct answer!

Test #23:

score: 0
Accepted
time: 35ms
memory: 7316kb

input:

4096
4096 2048 3072 1024 3584 1536 2560 512 3840 1792 2816 768 3328 1280 2304 256 3968 1920 2944 896 3456 1408 2432 384 3712 1664 2688 640 3200 1152 2176 128 4032 1984 3008 960 3520 1472 2496 448 3776 1728 2752 704 3264 1216 2240 192 3904 1856 2880 832 3392 1344 2368 320 3648 1600 2624 576 3136 1088...

output:

296831
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
...

result:

ok correct answer!

Test #24:

score: 0
Accepted
time: 35ms
memory: 6328kb

input:

4096
4096 2048 3072 1024 3584 1536 2560 512 3840 1792 2816 768 3328 1280 2304 256 3968 1920 2944 896 3456 1408 2432 384 3712 1664 2688 640 3200 1152 2176 128 4032 1984 3008 960 3520 1472 2496 448 3776 1728 2752 704 3264 1216 2240 192 3904 1856 2880 832 3392 1344 2368 320 3648 1600 2624 576 3136 1088...

output:

273262
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
...

result:

ok correct answer!

Test #25:

score: 0
Accepted
time: 30ms
memory: 5544kb

input:

4096
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 ...

output:

179444
251 252
250 251
249 250
248 249
244 247
245 246
244 248
245 247
242 243
242 244
241 242
240 241
232 239
233 238
234 237
235 236
232 240
233 239
234 238
235 237
228 231
229 230
228 232
229 231
226 227
226 228
225 226
224 225
208 223
209 222
210 221
211 220
212 219
213 218
214 217
215 216
208 2...

result:

ok correct answer!

Test #26:

score: 0
Accepted
time: 33ms
memory: 5908kb

input:

4096
4096 2048 3072 1024 3584 1536 2560 512 3840 1792 2816 768 3328 1280 2304 256 3968 1920 2944 896 3456 1408 2432 384 3712 1664 2688 640 3200 1152 2176 128 4032 1984 3008 960 3520 1472 2496 448 3776 1728 2752 704 3264 1216 2240 192 3904 1856 2880 832 3392 1344 2368 320 3648 1600 2624 576 3136 1088...

output:

218978
1 2
3 4
2 3
1 2
3 4
5 6
7 8
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
9 10
11 12
10 11
9 10
11 12
13 14
15 16
14 15
13 14
15 16
11 12
13 14
11 14
12 13
10 11
9 10
11 12
14 15
13 14
15 16
5 8
6 7
9 12
10 11
5 12
6 11
7 10
8 9
3 4
5 6
3 6
4 5
2 3
1 2
3 4
6 7
5 6
7 8
11 12
13 14
11 14
...

result:

ok correct answer!

Test #27:

score: 0
Accepted
time: 30ms
memory: 5860kb

input:

4083
2516 341 2006 237 3273 517 15 529 1890 3290 3380 3330 3085 1115 2010 2645 2828 3818 2375 2936 531 3725 2799 893 896 450 1526 2704 2382 4065 892 1954 268 1142 3186 1348 1340 1550 2318 1934 979 2282 2005 2692 959 1885 1315 1178 3819 2599 1661 563 2741 2688 3815 2002 2878 3301 3253 1920 4038 260 9...

output:

247972
1 2
3 4
2 3
1 2
3 4
5 6
6 7
5 6
7 8
3 4
5 6
3 6
4 5
2 3
1 2
6 7
5 6
11 12
13 14
14 15
15 16
10 12
13 15
10 15
11 14
12 13
9 10
14 15
14 16
13 14
7 8
9 10
7 10
8 9
5 6
5 6
6 7
7 8
11 13
10 13
11 12
9 10
18 19
17 18
19 20
23 24
22 23
23 24
18 20
21 23
18 23
19 22
20 21
18 19
17 19
23 24
25 26
2...

result:

ok correct answer!

Test #28:

score: 0
Accepted
time: 34ms
memory: 5820kb

input:

4085
2991 2833 2759 1930 202 3134 1983 2198 2226 3594 3916 405 3285 3335 2460 1773 78 3527 2827 1865 456 3711 836 1223 686 2905 605 256 2170 3115 2781 594 2758 1144 2079 3474 995 1528 3411 683 3894 3579 240 3369 3945 808 89 2306 719 135 547 2047 3344 2110 1844 2056 1249 2246 2191 1684 3794 2587 3252...

output:

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

result:

ok correct answer!

Test #29:

score: 0
Accepted
time: 31ms
memory: 5708kb

input:

4095
1260 3048 1648 2595 3467 2724 3418 3396 329 3187 3166 2501 1492 522 399 2627 168 3664 3817 2047 26 3220 2961 598 2936 2222 3973 3753 493 1225 2559 674 2547 2086 2484 3225 957 4090 2943 444 1401 1693 3473 3144 1733 2326 2403 3114 2212 3189 3314 386 3850 475 2663 2050 1653 494 2857 2581 3222 3184...

output:

249798
2 3
3 4
5 6
7 8
6 7
7 8
4 5
11 12
10 11
11 12
13 14
14 15
13 14
10 12
13 15
10 15
11 14
12 13
14 15
14 16
4 8
5 7
9 13
10 12
4 13
5 12
6 11
7 10
8 9
2 3
4 6
2 6
3 5
2 3
1 3
3 4
6 7
5 6
7 8
11 13
14 15
11 15
12 14
10 11
9 10
14 15
14 16
13 14
19 20
18 19
23 24
22 23
23 24
19 20
21 22
19 22
20 ...

result:

ok correct answer!

Test #30:

score: 0
Accepted
time: 34ms
memory: 5696kb

input:

4096
2835 1747 1101 930 3802 1980 308 3842 3608 1255 3276 3940 1355 398 3266 118 3920 2613 2042 2011 3065 1078 3787 3250 2868 3272 3966 2911 1147 1941 1675 895 484 3653 1776 1732 2356 798 2025 2461 341 1026 2491 762 3379 2161 2039 1008 3815 95 824 3277 769 2347 4065 641 3567 3791 3827 3180 607 3298 ...

output:

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

result:

ok correct answer!

Extra Test:

score: 0
Extra Test Passed