n = int(input())
A = list(map(int, input().split()))

# Count the occurrences of each number (1 to 8)
count = [0] * 9
for num in A:
    count[num] += 1

# Precompute sum_pows for each a from 1 to 8
sum_pows = [0] * 9
for a in range(1, 9):
    total = 0
    for k in range(1, 9):
        total += (a ** k) * count[k]
    sum_pows[a] = total

# Calculate the total answer
answer = 0
for num in A:
    answer += sum_pows[num]

print(answer)