n = int(input()) A = list(map(int,input().split())) ans = 0 num = 0 for a,na in zip(A,A[1:]): if a < na: num += 1 else: ans += num print(ans)