#############  B  #############
import numpy as np
N = int(input())
x = list(map(int, input().split()))

low = 2**(N-2)
dif = 2**(N-3)
num = N-1
high = low+dif*(num)
#print(low, high, dif)
li = np.array(range(low, high ,dif))
#print(l)
#li =np.array([i for i in l])
#print(li)

d = np.array([x[i+1]-x[i] for i in range(N-1)])
#print(d)
SUM = np.dot(li,d)
print(SUM)