import std; int readInt() { int x; readf!" %d"(x); return x; } int[] readArray(int n) { auto a = new int[](n); return a.map!(i => readInt).array; } void main() { int n = readInt; int[] p = readArray(n); long ans = 0; auto q = zip(n.iota.array, p); foreach(i; 0 .. n) { int sgn = (p[i] == n ? -1 : 1); ans += sgn * (i + 1); } if(n == 1) ans = 0; writeln(ans); }