n = input()
arr = [int(e) for e in input().split()]


upArr = []
downArr = []

i = 0
for i in range(len(arr)):
  tmp = (i,arr[i])
  upArr.append(tmp)
  downArr.append(tmp)
  i += 1

upArr.sort(key=lambda x: x[1])
downArr.sort(key=lambda x: x[1],reverse=True)

rl = n
ll = 0
ans = 0
for v in downArr:
  tmp = v[0] - int(n) + 1
  if tmp > v[0]:
    rl -= 1
    ans += tmp * v[1]
  else:
    ll += 1
    ans += v[0] * v[1]

print(ans)