tower = [] #解答用のリスト
que = [] #初期のリスト
a = 0 #towerからpop()した変数
b = 0 #queからpop(0)した変数
N = int(input())
que = list(map(int,input().split()))
b = que.pop(0)
tower.append(b)
while que != []:
b = que.pop(0)
a = tower.pop()
while a == b:
b += a
a = 0
if tower != []:
a = tower.pop()
else:
flg = 1
break
if flg == 1:
tower.append(b)
else:
tower.append(a)
tower.append(b)
flg = 0
for i in tower[::-1]:
print(i)