int input input for in range join split for in range len if i-p pop i-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
n = int(input())
t = [0]*3
a = [input() for i in range(n)]
a = ''.join(a).split('0')
p = 0
for i in range(len(a)):
if a[i-p] == '':
a.pop(i-p)
p += 1
for i in range(len(a)):
x = max(list(map(int,a[i])))
t[x%3] = x
if t[0] == 0 and (t[1]+t[2])%3 != 0:print('no')
elif max(t[0],t[1]+t[2])%3 == 0: print(max(t[0],t[1]+t[2]))
else:print(t[0])