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)
li = np.array(range(low, high ,dif))
d = np.array([x[i+1]-x[i] for i in range(N-1)])
SUM = np.dot(li,d)
print(SUM)