import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n = ni() a = na() b = [a[i+1] > a[i] for i in range(n-1)] c = 0 ans = 0 for i in range(n-2,-1,-1): if b[i] == 0: c += 1 else: ans += c print(ans)