n = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(n):
  tall = 0
  for j in range(i):
    if (lst[j] > tall):
      tall = lst[j]
  print (i, tall)
  if (lst[i] < tall):
    sa = tall - lst[i]
    print(i,sa)
    ans = ans + sa
    lst[i] = tall
print(ans)
