Submission details
Task:Pair sort
Sender:aalto26dw_003
Submission time:2026-09-23 17:43:37 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.04 sdetails
#100.04 sdetails
#110.06 sdetails
#120.05 sdetails
#130.07 sdetails
#140.07 sdetails

Code

import sys 

input = sys.stdin.read().split()

n = int(input[0])
a = [int(x) for x in input[1:]]

idx = [[] for _ in range(n+1)]
for i,val in enumerate(a) :
    idx[val].append(i)
steps = []

for i in range(1,n):
    p1 = 2*i
    p2 = 2*i +1

    if a[p1] == a[p2]:
        continue

    x = a[p1]
    y = a[p2]
    
    p3 = idx[x][1] if idx[x][0] == p1 else idx[x][0]

    steps.append((p2+1,p3+1))
    a[p2], a[p3] = a[p3], a[p2]

    if idx[y][0] == p2 :
        idx[y][0] == p3 
    else : 
        idx[y][1] == p3




print(len(steps))
for s in steps : 
    print(f"{s[0]} {s[1]}")

Test details

Test 1

Verdict: ACCEPTED

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
3
4 9
6 8
8 2

Test 2

Verdict: ACCEPTED

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
3
4 9
6 8
8 2

Test 3

Verdict:

input
10
3 6 6 8 8 9 9 1 4 5 2 4 10 2 1...

correct output
9
2 17
4 17
6 17
8 17
...

user output
9
4 2
6 4
8 6
10 12
...

Test 4

Verdict:

input
10
3 6 6 8 8 9 9 1 4 5 2 4 10 2 1...

correct output
9
2 17
4 17
6 17
8 17
...

user output
9
4 2
6 4
8 6
10 12
...

Test 5

Verdict:

input
50
47 26 6 35 13 18 9 19 14 50 34...

correct output
48
2 87
4 78
6 71
8 55
...

user output
49
4 78
6 71
8 55
10 27
...

Test 6

Verdict:

input
50
47 26 6 35 13 18 9 19 14 50 34...

correct output
48
2 87
4 78
6 71
8 55
...

user output
49
4 78
6 71
8 55
10 27
...

Test 7

Verdict:

input
100
56 26 6 35 60 72 9 55 83 51 58...

correct output
97
2 77
4 108
6 141
8 55
...

user output
98
4 108
6 141
8 55
10 52
...

Test 8

Verdict:

input
100
56 26 6 35 60 72 9 55 83 51 58...

correct output
97
2 77
4 108
6 141
8 55
...

user output
98
4 108
6 141
8 55
10 52
...

Test 9

Verdict:

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
499
4 820
6 125
8 243
10 52
...

Test 10

Verdict:

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
499
4 820
6 125
8 243
10 52
...

Test 11

Verdict:

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
998
4 1534
6 816
8 1057
10 1835
...

Test 12

Verdict:

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
998
4 1534
6 816
8 1057
10 1835
...

Test 13

Verdict:

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
4998
4 9062
6 6397
8 8296
10 8203
...

Test 14

Verdict:

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
4998
4 9062
6 6397
8 8296
10 8203
...