#include using namespace std; int main(){ int N; cin >> N; vector P(N); for (int i = 0; i < N; i++){ cin >> P[i]; P[i]--; } if (N == 1){ cout << 0 << endl; } else { vector A(N); for (int i = 0; i < N; i++){ A[P[i]] = i + 1; } vector S(N + 1); S[0] = 0; for (int i = 0; i < N; i++){ S[i + 1] = S[i] + A[i]; } long long ans = 0; for (int i = 1; i < N; i++){ ans = max(ans, S[i] - A[i]); } cout << ans << endl; } }