int input INF -float inf INF INF ans for in range int input if max els

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
n = int(input())
INF = -float('inf')
a = [INF]*3
b = [INF]*3
ans = 0
for i in range(n):
x = int(input())
if x > 0: a[x%3] = max(a[x%3],x)
else:
ans = max(ans,a[0]+b[0],a[1]+b[2],a[2]+b[1])
for i in range(3):
b[i] = max(b[i],a[i])
a[i] = INF
print(max(ans,a[0]+b[0],a[1]+b[2],a[2]+b[1]))