#!python # -*- coding: utf-8 -*- def main(): N = int(input()) A = [] for i in range(N): A.append(int(input())) print("-" * 10) cnt = 0 for k in range(N): if k == 0: V = A[k:] + A[:k] for i in range(1, N): for j in range(i): if V[i] < V[j]: cnt += 1 else: for i in range(1, N): if V[i] < V[0]: cnt -= 1 else: cnt += 1 V.append(V.pop(0)) print(cnt) if __name__ == '__main__': main()