-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11495.py
More file actions
59 lines (46 loc) · 993 Bytes
/
uva11495.py
File metadata and controls
59 lines (46 loc) · 993 Bytes
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
#!/usr/bin/env python3
def sortandcount(s1, s2, b, e):
if e - b < 2:
return 0
ct = 0
m = (b + e)//2
ct += sortandcount(s2, s1, b, m)
ct += sortandcount(s2, s1, m, e)
i = b
j = m
k = b
while i < m and j < e:
if s2[i] <= s2[j]:
s1[k] = s2[i]
i += 1
else:
s1[k] = s2[j]
ct += (m - i)
j += 1
k += 1
while i < m:
s1[k] = s2[i]
i += 1
k += 1
while j < e:
s1[k] = s2[j]
j += 1
k += 1
#print("s1 ",s1)
#print("s2 ",s2)
return ct
def inversions(s):
s1 = list(s)
s2 = list(s)
return sortandcount(s1, s2, 0, len(s))
def main():
while True:
P = list(map(int, input().split()))
if P[0] == 0:
break
if inversions(P[1:]) % 2 == 1:
print("Marcelo")
else:
print("Carlos")
if __name__ == "__main__":
main()