#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a struct fenwick_tree{ vector v; int n; fenwick_tree(int x){ n=x; v.assign(n+1,0); } fenwick_tree(vector &a){ n=(int)a.size(); v.assign(n+1,0); for(int i=0;i>=1){ if(x+k<=n&&v[x+k]>=1; } return ret; } ll division(ll a,ll b){ return (a*modpow(b,mod-2))%mod; } vector factorial; ll nCr(ll n,ll r){ if(n<0||r<0) return 0; if(n> n; vector p(n); rep(i,n){ cin >> p[i]; p[i]--; } vector v(n,1); fenwick_tree f(n),b(v); ll ans=0; rep(i,n){ b.add(p[i],-1); ll fmin=f.sum(p[i]),fmax=f.sum(p[i],n-1); ll bmin=b.sum(p[i]),bmax=b.sum(p[i],n-1); f.add(p[i],1); ans+=nCr(fmin+bmax,fmin)*nCr(fmax+bmin,fmax)%mod; ans%=mod; } cout << ans << '\n'; }