import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); PriorityQueue que = new PriorityQueue<>((o1, o2) -> o2.p - o1.p); for (int i = 0; i < n; i++) { Obj o = new Obj(); o.i = i + 1; o.p = sc.nextInt(); que.add(o); } sc.close(); long val = (long) n * (n + 1) / 2; Obj o = que.peek(); long ans = val - o.i * 2; while (!que.isEmpty()) { Obj cur = que.poll(); val -= cur.i; if (que.isEmpty()) { ans = Math.max(ans, val); } else { Obj next = que.peek(); long val2 = val - next.i * 2; ans = Math.max(ans, val2); } } System.out.println(ans); } static class Obj { int i, p; } }