107932024-04-13 14:06:2342Szimmetrikus sorozatpython3Accepted 100/100625ms102468 KiB
from sys import stdin
input=stdin.readline

def main():
    N = int(input())
    T = [int(x) for x in input().split()]
    graph={}
    for i in range(N//2):
        j=N-1-i
        if T[i] != T[j]:
            try: graph[T[i]].add(T[j])
            except: graph[T[i]]={T[j]}
            try: graph[T[j]].add(T[i])
            except: graph[T[j]]={T[i]}
    comp=[]
    while graph:
        x,cur = graph.popitem()
        c={x}
        #print(x,cur)
        while cur:
            v=cur.pop()
            new=graph.pop(v)
            c.add(v)
            for v in new:
                if v not in c:
                    cur.add(v)
        comp.append(c.copy())
    #print(comp)
    #print(graph)
    print(sum([len(c)-1 for c in comp]))
    for c in comp:
        lista=list(c)
        lista.sort()
        for i in range(1,len(lista)):
            print(lista[i],lista[0])
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted17ms11376 KiB
2Accepted224ms60204 KiB
subtask29/9
3Accepted18ms12108 KiB
4Accepted18ms12416 KiB
5Accepted18ms12492 KiB
6Accepted18ms12644 KiB
7Accepted18ms12880 KiB
subtask314/14
8Accepted17ms12856 KiB
9Accepted17ms12672 KiB
10Accepted17ms12776 KiB
11Accepted17ms12828 KiB
12Accepted17ms12812 KiB
13Accepted17ms13156 KiB
subtask425/25
14Accepted18ms13324 KiB
15Accepted19ms13928 KiB
16Accepted23ms14756 KiB
17Accepted24ms14940 KiB
18Accepted21ms15084 KiB
19Accepted21ms14512 KiB
20Accepted21ms14560 KiB
21Accepted18ms14000 KiB
subtask522/22
22Accepted351ms88904 KiB
23Accepted372ms88592 KiB
24Accepted374ms88608 KiB
25Accepted351ms88696 KiB
26Accepted351ms89172 KiB
27Accepted377ms89604 KiB
28Accepted377ms89796 KiB
29Accepted351ms88824 KiB
30Accepted351ms88596 KiB
31Accepted377ms95436 KiB
32Accepted374ms95448 KiB
33Accepted349ms88740 KiB
34Accepted389ms88928 KiB
35Accepted391ms97844 KiB
36Accepted419ms98136 KiB
37Accepted388ms89432 KiB
subtask630/30
38Accepted17ms14384 KiB
39Accepted224ms62848 KiB
40Accepted18ms12108 KiB
41Accepted18ms12416 KiB
42Accepted18ms12492 KiB
43Accepted18ms12644 KiB
44Accepted18ms12880 KiB
45Accepted17ms12856 KiB
46Accepted17ms12672 KiB
47Accepted17ms12776 KiB
48Accepted17ms12828 KiB
49Accepted17ms12812 KiB
50Accepted17ms13156 KiB
51Accepted18ms13324 KiB
52Accepted19ms13928 KiB
53Accepted23ms14756 KiB
54Accepted24ms14940 KiB
55Accepted21ms15084 KiB
56Accepted21ms14512 KiB
57Accepted21ms14560 KiB
58Accepted18ms14000 KiB
59Accepted351ms88904 KiB
60Accepted372ms88592 KiB
61Accepted374ms88608 KiB
62Accepted351ms88696 KiB
63Accepted351ms89172 KiB
64Accepted377ms89604 KiB
65Accepted377ms89796 KiB
66Accepted351ms88824 KiB
67Accepted351ms88596 KiB
68Accepted377ms95436 KiB
69Accepted374ms95448 KiB
70Accepted349ms88740 KiB
71Accepted389ms88928 KiB
72Accepted391ms97844 KiB
73Accepted419ms98136 KiB
74Accepted388ms89432 KiB
75Accepted538ms102200 KiB
76Accepted352ms87612 KiB
77Accepted181ms57736 KiB
78Accepted356ms87692 KiB
79Accepted279ms62912 KiB
80Accepted104ms57964 KiB
81Accepted112ms58236 KiB
82Accepted107ms58180 KiB
83Accepted625ms102468 KiB
84Accepted174ms58336 KiB
85Accepted261ms63184 KiB
86Accepted108ms58216 KiB
87Accepted108ms58172 KiB
88Accepted111ms58124 KiB
89Accepted108ms58160 KiB