-
Notifications
You must be signed in to change notification settings - Fork 0
/
1510K.py
72 lines (59 loc) · 1.08 KB
/
1510K.py
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
#######puzzleVerma#######
import sys
import math
mod = 10**9+7
LI=lambda:[int(k) for k in input().split()]
input = lambda: sys.stdin.readline().rstrip()
IN=lambda:int(input())
S=lambda:input()
n=IN()
li=LI()
def swap1 (A):
for i in range(len(A)//2):
b = A[2*i]
A[2*i] = A[2*i+1]
A[2*i+1] = b
return A
def swap2 (A):
n = len(A)//2
for i in range(n):
b = A[n+i]
A[n+i] = A[i]
A[i] = b
return A
def is_sorted(A):
for i in range (len(A)):
if (A[i]!=i+1):
return False
return True
if is_sorted(li):
print(0)
sys.exit()
ans1=0
ans2=0
li1=li.copy()
li2=li.copy()
while(not (is_sorted(li1)) and (not is_sorted(li2))):
swap1(li1)
ans1+=1
if is_sorted(li1):
print(ans1)
break
swap2(li1)
ans1+=1
if is_sorted(li1):
print(ans1)
break
swap2(li2)
ans2+=1
if is_sorted(li2):
print(ans2)
break
swap1(li2)
ans2+=1
if is_sorted(li2):
print(ans2)
break
if ans1>n:
print(-1)
break