import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!int).array; foreach (i; 0..N) A[i]--; auto B = new int[](N); foreach (i, a; A) B[a] = i.to!int; long search (int i) { if (A[i] == i) return 0; int j = B[A[i]-1]; swap(B[A[i]], B[A[i]-1]); swap(A[i], A[j]); return search(i) + 1; } long ans = 0; foreach (i; 0..N) { ans += search(i); } writeln(ans); }