#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main(){ ll N, P, S, ans=0; cin >> N; S = N*(N+1)/2; vector Q(N+1); for (int i=1; i<=N; i++){ cin >> P; Q[P] = i; } for (int i=N; i>=1; i--){ ans = max(ans, S-Q[i] * 2); S -= Q[i]; } cout << ans << endl; return 0; }