# ifndef ONLINE_JUDGE # define _GLIBCXX_DEBUG # endif #include using namespace std; using ll = long long; using vi = vector; using vvi = vector>; using pii = pair; # define rep(i, n) for(int i = 0; i < (int)(n); ++i) # define all(v) v.begin(), v.end() int main(){ constexpr char endl = '\n'; ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); //input(); ll N;cin >> N; vi P(N); for(auto &&e : P) cin >> e; //solve(); map index; rep(i, N){ index[P[i]] = i+1; } ll ans = 0; ll sum = (N*(N+1))/2; for(int i = N; 1 <= i; --i){ ans = max(ans, sum-2*index[i]); sum -= index[i]; } //output(); cout << ans << endl; }