#include using namespace std; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; templateinline bool chmax(T& a,T b){if(ainline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} int main(){ ll n; cin>>n; vector a(n); rep(i,0,n)cin>>a[i],a[i]--; vector pos(n); rep(i,0,n)pos[a[i]]=i+1; ll res=0,sum=n*(n+1)/2; for(int i=n-1;i>=0;i--){ chmax(res,sum-pos[i]*2); sum-=pos[i]; } cout<