n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(n): now = a[i] ans += now - i - 1 a[i] = i + 1 for j in range(i + 1, n): if a[j] < now: a[j] += 1 print(ans)