#include using namespace std; using Int = signed; #include using ll = boost::multiprecision::cpp_int; template struct BIT{ Int n; vector bit; BIT(Int n_,T d):n(n_),bit(n_+1,d){} T sum(Int i){ T s=bit[0]; for(Int x=i;x>0;x-=(x&-x)) s+=bit[x]; return s; } void add(Int i,T a){ if(i==0) return; for(Int x=i;x<=n;x+=(x&-x)) bit[x]+=a; } }; //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector p(n); for(Int i=0;i>p[i]; ll ans=1,x=1; BIT bit(n+1,0); for(Int i=1;i<=n;i++){ ans+=bit.sum(p[n-i])*x; bit.add(p[n-i],1); x*=i; } cout<