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; immutable long MOD = 10^^9 + 7; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!long).array; long ans = 0; foreach (i; 0..N) if (A[i] != N) ans += i + 1; else ans -= i + 1; long ans2 = 0; foreach (i; 0..N) { if (A[i] == N) { } else if (A[i] == N - 1) { ans2 -= i + 1; } else { ans2 += i + 1; } } writeln(max(ans, ans2, 0)); }