26 lines
584 B
Python
26 lines
584 B
Python
import copy
|
|
import itertools
|
|
max = 0
|
|
ostatki = []
|
|
n = int(input())
|
|
chisla = map(int, input().split())
|
|
oldallresults = []
|
|
somechisl = ""
|
|
for i in range(1, n + 1):
|
|
newlist = copy.deepcopy(chisla)
|
|
result = itertools.combinations(newlist, i)
|
|
oldallresults.extend(result)
|
|
|
|
for i in range(len(oldallresults)):
|
|
for j in oldallresults[i]:
|
|
somechisl = str(somechisl) + str(j)
|
|
intsomechisl = int(somechisl)
|
|
if intsomechisl % 15 == 0 and intsomechisl > max:
|
|
max = intsomechisl
|
|
somechisl = ""
|
|
|
|
if max != 0:
|
|
print(max)
|
|
else:
|
|
print("Impossible")
|