N = int(input()) P = list(map(int, input().split())) P = list(map(lambda x : x - 1, P)) D = [0] * N for i in range(N): D[P[i]] = i ans = 0 for i in range(N): v = P[i] ans += v - i # print("ans", i, v, P, D) for j in range(v, i, -1): P[D[j]], P[D[j - 1]] = P[D[j - 1]], P[D[j]] D[j], D[j - 1] = D[j - 1], D[j] print(ans)