n = int(input()) a = list(map(int, input().split())) c = s = 0 for i in range(n-1): if a[i] > a[i+1]: c += 1; s += i print(s-c*(c-1)//2)