# 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(); int N;cin >> N; vi P(N); for(auto &&e : P) cin >> e; //solve(); vector point(N); rep(i, N){ point[P[i]-1] = make_pair(P[i], i+1); } reverse(all(point)); int ans = 0; int sum = N*(N+1)/2; rep(i, N){ sum -= 2*point[i].second; ans = max(ans, sum); sum += point[i].second; } //output(); cout << ans << endl; }