-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path430B.py
29 lines (22 loc) · 784 Bytes
/
430B.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
# @author Matheus Alves dos Santos
n_balls, n_colors, new_ball = map(int, input().split())
balls = list(map(int, input().split()))
answer = 0
for i in range(n_balls):
copy = balls[:]
copy.insert(i, new_ball)
while (len(copy) > 2):
size = len(copy)
for j in range(2, len(copy)):
if ((copy[j - 2] == copy[j - 1]) and (copy[j - 1] == copy[j])):
cut = j + 1
while (cut < len(copy)):
if (copy[j] != copy[cut]):
break
cut += 1
copy = (copy[:j - 2] + copy[cut:])
break
if (len(copy) == size):
break
answer = max(answer, n_balls - len(copy))
print(answer)