#include using namespace std; #include using namespace atcoder; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair #define LP pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() template void chmax(T& a, T b) { a = max(a, b); }; template void chmin(T& a, T b) { a = min(a, b); }; int main() { int n; cin >> n; if (n == 1) { cout << 1 << " " << 0 << endl; return 0; } vector a(n), pos(n+1); rep(i,n) { cin >> a[i]; pos[a[i]] = i+1; } ll ans = 0; ll tot = (ll)n*(n+1)/2; for (int i = n; i >= 1; i--) { chmax(ans, tot-2*pos[i]); tot -= pos[i]; } cout << ans << endl; return 0; }