#include #include #include #include #include #include #include #include #include #include #include #include #include #define p(s) cout<<(s)<=n;i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define F first #define S second typedef long long ll; using namespace std; const ll inf=1e9+7; ll n; ll A[500010]; map m; set s; ll cnt[500010]; //右に大きいものが何個 int main(){ cin>>n; ll ans; REP(i,0,n){ cin>>A[i]; if(A[i]==n){ s.insert(i); ans += n-i-1; } m[A[i]]=i; } RREP(i,1,n){ ll tmp = distance(s.lower_bound(m[i]), s.end()); s.insert(m[i]); //p(tmp); ans += n - (m[i]+1) - tmp; } p(ans); REP(i,0,n-1){ ans += n - A[i] - (A[i]-1); p(ans); } return 0; }