Submission details
Task:Sorting books
Sender:aalto26dw_008
Submission time:2026-09-24 00:41:52 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.05 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.04 sdetails
#100.04 sdetails
#110.04 sdetails
#120.04 sdetails
#130.04 sdetails
#140.04 sdetails
#150.04 sdetails
#160.04 sdetails
#170.04 sdetails
#180.04 sdetails
#190.04 sdetails
#200.04 sdetails
#210.04 sdetails
#220.04 sdetails
#230.04 sdetails
#240.04 sdetails
#250.04 sdetails
#260.04 sdetails
#270.04 sdetails
#280.04 sdetails
#290.04 sdetails
#300.04 sdetails
#310.04 sdetails
#320.04 sdetails
#330.04 sdetails
#340.04 sdetails
#350.04 sdetails
#360.04 sdetails
#370.04 sdetails
#380.04 sdetails
#390.04 sdetails
#400.04 sdetails
#410.05 sdetails
#420.05 sdetails
#430.05 sdetails
#440.05 sdetails
#450.05 sdetails
#460.05 sdetails
#470.05 sdetails
#480.05 sdetails
#490.05 sdetails
#500.05 sdetails
#510.09 sdetails
#520.09 sdetails
#530.09 sdetails
#540.09 sdetails
#550.09 sdetails
#560.09 sdetails
#570.09 sdetails
#580.09 sdetails
#590.09 sdetails
#600.09 sdetails
#610.00 sdetails
#620.00 sdetails
#630.00 sdetails
#640.00 sdetails
#650.00 sdetails
#660.00 sdetails
#670.00 sdetails
#680.00 sdetails
#690.00 sdetails
#700.00 sdetails
#710.59 sdetails

Code

def main() -> None:

    def merge(arr: list[int]) -> tuple[list[int], int]:
        print("called with", arr)

        if len(arr) <= 1:
            return (arr, 0)

        n = len(arr)
        r, vr = merge(arr[: n // 2])
        l, vl = merge(arr[n // 2 :])

        resp = []
        count = 0

        ir = 0
        il = 0

        while ir < len(r) and il < len(l):
            if r[ir] <= l[il]:
                resp.append(r[ir])
                ir += 1
            else:
                resp.append(l[il])
                il += 1
                count += len(r) - ir

        while ir < len(r):
            resp.append(r[ir])
            ir += 1

        while il < len(l):
            resp.append(l[il])
            il += 1

        print("returning", resp, vr + vl + count)
        return (resp, vr + vl + count)

    _ = int(input())
    a = list(map(int, input().split()))

    print(merge(a)[1])


main()

Test details

Test 1

Verdict:

input
1
1 

correct output
0

user output
called with [1]
0

Test 2

Verdict:

input
2
3 7 

correct output
0

user output
called with [3, 7]
called with [3]
called with [7]
returning [3, 7] 0
0

Test 3

Verdict:

input
2
3 6 

correct output
0

user output
called with [3, 6]
called with [3]
called with [6]
returning [3, 6] 0
0

Test 4

Verdict:

input
2
3 8 

correct output
0

user output
called with [3, 8]
called with [3]
called with [8]
returning [3, 8] 0
0

Test 5

Verdict:

input
3
1 2 10 

correct output
0

user output
called with [1, 2, 10]
called with [1]
called with [2, 10]
called with [2]
called with [10]
...

Test 6

Verdict:

input
3
3 7 10 

correct output
0

user output
called with [3, 7, 10]
called with [3]
called with [7, 10]
called with [7]
called with [10]
...

Test 7

Verdict:

input
3
3 6 8 

correct output
0

user output
called with [3, 6, 8]
called with [3]
called with [6, 8]
called with [6]
called with [8]
...

Test 8

Verdict:

input
4
5 5 4 10 

correct output
2

user output
called with [5, 5, 4, 10]
called with [5, 5]
called with [5]
called with [5]
returning [5, 5] 0
...

Test 9

Verdict:

input
4
4 5 5 5 

correct output
0

user output
called with [4, 5, 5, 5]
called with [4, 5]
called with [4]
called with [5]
returning [4, 5] 0
...

Test 10

Verdict:

input
4
7 10 7 1 

correct output
4

user output
called with [7, 10, 7, 1]
called with [7, 10]
called with [7]
called with [10]
returning [7, 10] 0
...

Test 11

Verdict:

input
5
6 6 8 9 7 

correct output
2

user output
called with [6, 6, 8, 9, 7]
called with [6, 6]
called with [6]
called with [6]
returning [6, 6] 0
...

Test 12

Verdict:

input
5
5 10 8 10 1 

correct output
5

user output
called with [5, 10, 8, 10, 1]
called with [5, 10]
called with [5]
called with [10]
returning [5, 10] 0
...

Test 13

Verdict:

input
5
5 2 1 10 6 

correct output
4

user output
called with [5, 2, 1, 10, 6]
called with [5, 2]
called with [5]
called with [2]
returning [2, 5] 1
...

Test 14

Verdict:

input
5
6 1 8 9 3 

correct output
4

user output
called with [6, 1, 8, 9, 3]
called with [6, 1]
called with [6]
called with [1]
returning [1, 6] 1
...

Test 15

Verdict:

input
5
10 10 6 2 10 

correct output
5

user output
called with [10, 10, 6, 2, 10]
called with [10, 10]
called with [10]
called with [10]
returning [10, 10] 0
...

Test 16

Verdict:

input
5
3 1 9 9 3 

correct output
3

user output
called with [3, 1, 9, 9, 3]
called with [3, 1]
called with [3]
called with [1]
returning [1, 3] 1
...

Test 17

Verdict:

input
5
9 10 4 3 9 

correct output
6

user output
called with [9, 10, 4, 3, 9]
called with [9, 10]
called with [9]
called with [10]
returning [9, 10] 0
...

Test 18

Verdict:

input
5
1 3 8 4 5 

correct output
2

user output
called with [1, 3, 8, 4, 5]
called with [1, 3]
called with [1]
called with [3]
returning [1, 3] 0
...

Test 19

Verdict:

input
5
9 1 10 3 9 

correct output
4

user output
called with [9, 1, 10, 3, 9]
called with [9, 1]
called with [9]
called with [1]
returning [1, 9] 1
...

Test 20

Verdict:

input
5
1 4 6 5 5 

correct output
2

user output
called with [1, 4, 6, 5, 5]
called with [1, 4]
called with [1]
called with [4]
returning [1, 4] 0
...

Test 21

Verdict:

input
10
6 6 8 9 7 9 6 9 5 7 

correct output
18

user output
called with [6, 6, 8, 9, 7, 9,...

Test 22

Verdict:

input
10
5 10 8 10 1 2 4 10 2 3 

correct output
25

user output
called with [5, 10, 8, 10, 1, ...

Test 23

Verdict:

input
10
5 2 1 10 6 10 5 5 5 4 

correct output
20

user output
called with [5, 2, 1, 10, 6, 1...

Test 24

Verdict:

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

correct output
18

user output
called with [6, 1, 8, 9, 3, 2,...

Test 25

Verdict:

input
10
10 10 6 2 10 9 8 7 7 6 

correct output
29

user output
called with [10, 10, 6, 2, 10,...

Test 26

Verdict:

input
10
3 1 9 9 3 4 10 10 5 1 

correct output
17

user output
called with [3, 1, 9, 9, 3, 4,...

Test 27

Verdict:

input
10
9 10 4 3 9 1 1 4 2 10 

correct output
25

user output
called with [9, 10, 4, 3, 9, 1...

Test 28

Verdict:

input
10
1 3 8 4 5 10 8 5 10 4 

correct output
12

user output
called with [1, 3, 8, 4, 5, 10...

Test 29

Verdict:

input
10
9 1 10 3 9 4 6 9 3 5 

correct output
22

user output
called with [9, 1, 10, 3, 9, 4...

Test 30

Verdict:

input
10
1 4 6 5 5 1 2 4 2 1 

correct output
25

user output
called with [1, 4, 6, 5, 5, 1,...

Test 31

Verdict:

input
100
589284012 636562060 767928734 ...

correct output
2843

user output
called with [589284012, 636562...

Test 32

Verdict:

input
100
447773962 773442532 122816 137...

correct output
2446

user output
called with [447773962, 773442...

Test 33

Verdict:

input
100
468145963 198730372 27838076 5...

correct output
2158

user output
called with [468145963, 198730...

Test 34

Verdict:

input
100
591414747 75940263 760367935 9...

correct output
2298

user output
called with [591414747, 759402...

Test 35

Verdict:

input
100
967034924 587586158 185430194 ...

correct output
2580

user output
called with [967034924, 587586...

Test 36

Verdict:

input
100
238363353 59249204 934941692 8...

correct output
2578

user output
called with [238363353, 592492...

Test 37

Verdict:

input
100
958701283 356460601 224848374 ...

correct output
2417

user output
called with [958701283, 356460...

Test 38

Verdict:

input
100
81935404 244103474 837431431 3...

correct output
2315

user output
called with [81935404, 2441034...

Test 39

Verdict:

input
100
937837681 11934038 257096283 9...

correct output
2692

user output
called with [937837681, 119340...

Test 40

Verdict:

input
100
11139168 391337048 538883744 5...

correct output
2302

user output
called with [11139168, 3913370...

Test 41

Verdict:

input
200
589284012 636562060 767928734 ...

correct output
10624

user output
called with [589284012, 636562...

Test 42

Verdict:

input
200
447773962 773442532 122816 137...

correct output
9384

user output
called with [447773962, 773442...

Test 43

Verdict:

input
200
468145963 198730372 27838076 5...

correct output
8760

user output
called with [468145963, 198730...

Test 44

Verdict:

input
200
591414747 75940263 760367935 9...

correct output
8939

user output
called with [591414747, 759402...

Test 45

Verdict:

input
200
967034924 587586158 185430194 ...

correct output
9905

user output
called with [967034924, 587586...

Test 46

Verdict:

input
200
238363353 59249204 934941692 8...

correct output
9851

user output
called with [238363353, 592492...

Test 47

Verdict:

input
200
958701283 356460601 224848374 ...

correct output
10551

user output
called with [958701283, 356460...

Test 48

Verdict:

input
200
81935404 244103474 837431431 3...

correct output
9163

user output
called with [81935404, 2441034...

Test 49

Verdict:

input
200
937837681 11934038 257096283 9...

correct output
9346

user output
called with [937837681, 119340...

Test 50

Verdict:

input
200
11139168 391337048 538883744 5...

correct output
9982

user output
called with [11139168, 3913370...

Test 51

Verdict:

input
1000
589284012 636562060 767928734 ...

correct output
256701

user output
called with [589284012, 636562...

Test 52

Verdict:

input
1000
447773962 773442532 122816 137...

correct output
243505

user output
called with [447773962, 773442...

Test 53

Verdict:

input
1000
468145963 198730372 27838076 5...

correct output
252964

user output
called with [468145963, 198730...

Test 54

Verdict:

input
1000
591414747 75940263 760367935 9...

correct output
246581

user output
called with [591414747, 759402...

Test 55

Verdict:

input
1000
967034924 587586158 185430194 ...

correct output
241203

user output
called with [967034924, 587586...

Test 56

Verdict:

input
1000
238363353 59249204 934941692 8...

correct output
251093

user output
called with [238363353, 592492...

Test 57

Verdict:

input
1000
958701283 356460601 224848374 ...

correct output
256962

user output
called with [958701283, 356460...

Test 58

Verdict:

input
1000
81935404 244103474 837431431 3...

correct output
250165

user output
called with [81935404, 2441034...

Test 59

Verdict:

input
1000
937837681 11934038 257096283 9...

correct output
246466

user output
called with [937837681, 119340...

Test 60

Verdict:

input
1000
11139168 391337048 538883744 5...

correct output
249076

user output
called with [11139168, 3913370...

Test 61

Verdict:

input
200000
589284012 636562060 767928734 ...

correct output
9983154934

user output
(empty)

Test 62

Verdict:

input
200000
447773962 773442532 122816 137...

correct output
9998885834

user output
(empty)

Test 63

Verdict:

input
200000
468145963 198730372 27838076 5...

correct output
9995310844

user output
(empty)

Test 64

Verdict:

input
200000
591414747 75940263 760367935 9...

correct output
10000936270

user output
(empty)

Test 65

Verdict:

input
200000
967034924 587586158 185430194 ...

correct output
10002145347

user output
(empty)

Test 66

Verdict:

input
200000
238363353 59249204 934941692 8...

correct output
9989708150

user output
(empty)

Test 67

Verdict:

input
200000
958701283 356460601 224848374 ...

correct output
9997845631

user output
(empty)

Test 68

Verdict:

input
200000
81935404 244103474 837431431 3...

correct output
10016175198

user output
(empty)

Test 69

Verdict:

input
200000
937837681 11934038 257096283 9...

correct output
9983428867

user output
(empty)

Test 70

Verdict:

input
200000
11139168 391337048 538883744 5...

correct output
9971613818

user output
(empty)

Test 71

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
0

user output
called with [1, 1, 1, 1, 1, 1,...