from collections import deque
n = int(input())
a = list(map(int, input().split()))
newa = []
for i, j in enumerate(a, 0):
    newa.append([i, j])
newa.sort(key=lambda x:x[1], reverse=True)
ans_list = deque(list(range(n)))
ans = 0
for index, value in newa:
    if abs(index-ans_list[0]) >= abs(index-ans_list[-1]):
        res = ans_list.popleft()
        ans += value*abs(index-res)
    else:
        res = ans_list.pop()
        ans += value*abs(index-res)    
    print(res, value*abs(index-res))
print(ans+1)