import std; void main() { int N; readf("%d\n", N); auto P = readln.chomp.split.to!(long[]); long res; long tmp = N * (N - 1) / 2 - P.maxIndex - 1; if (res < tmp) { res = tmp; } foreach (i; 0 .. N) { tmp = P[i] * (P[i] + 1) / 2 - 2 * (i + 1); if (res < tmp) { res = tmp; } } res.writeln; }