Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- n = 2**n
- a = [0]+list(map(int,input().split()))
- def Find(n,a):
- if n == 2:
- return [a[1]]
- else:
- minimum = a[1]
- q1,q2 = 0,1
- new = [a[0]]
- check = []
- #Делим на 2 части
- while q2 < n:
- if (q1 < len(new)) and (new[q1]+minimum == a[q2]):
- q1 = q1 + 1
- check.append(a[q2])
- else:
- new.append(a[q2])
- q2 = q2 + 1
- #Проверяем правильность деления
- flag = True
- if not len(new) == len(check):
- flag = False
- if flag == True:
- for i in range(n//2):
- if not new[i]+minimum == check[i]:
- flag = False
- break
- if flag == False:
- return -1
- else:
- add = Find(n//2,new)
- if add == -1:
- return -1
- else:
- return [minimum] + add
- result = Find(n,a)
- if result == -1:
- print(-1)
- else:
- print(', '.join(list(map(str,result))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement