Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a*<sub class="lower-index">*i*</sub> coins. 

Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x* + 1 ≤ *n*) and take a coin from each chest with numbers *x*, 2·*x*, 2·*x* + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied.

Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves.
The first line contains a single integer *n* (1 ≤ *n* ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 1000), where *a*<sub class="lower-index">*i*</sub> is the number of coins in the chest number *i* at the beginning of the game.
n = int(input())
arr = list(map(int,input().split()))
t = (n-1)//2
ans = 0
if t>0:	
	for i in range(n-1,0,-1):
		ans+=(arr[i]-0)
		if i%2==1:
			ans+=max(0,arr[i//2]-arr[i])
			arr[i//2] = max(0,arr[i//2]-arr[i])
		else:
			ans+= max(0,arr[(i-1)]-arr[i])
			ans+= max(0,arr[(i-1)//2]-arr[i])
			arr[(i-1)] = max(0,arr[(i-1)]-arr[i])
			arr[(i-1)//2] = max(0,arr[(i-1)//2]-arr[i])
		# print(arr,ans)
	print(ans + arr[0])
else:
	print(-1)