n = int(input()) a = list(map(int, input().split())) s = [0]*n for i in range(1,n): s[i] = s[i-1] + 2**(i-1) # print(s) res = 0 cur = n for i in range(n-1): res += (a[i]-a[-1+i])*s[-1+i] print(res)