#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x class BIT { public: V bit[1<=0;i--) if(tv+bit[ent+(1< P; ll fact[101010], totinv[101010]; ll ret; ll mo=1000000007; ll getsmaller(int n) { static BIT bt; ZERO(bt.bit); ZERO(bt.val); int i; ll tot=0; for(i=n+1;i=0;i--) { int j=0; while(k>=fact[i]) { r+=(totinv[i]+j*(fact[i]%mo))%mo; k-=fact[i]; j++; } } return r%mo; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; if(K==0) return _P("0\n"); P.push_back(0); FOR(i,N) cin>>x, P.push_back(x); N++; fact[0]=1; totinv[0]=0; for(i=1;i<=N;i++) { fact[i]=fact[i-1]*i; if(fact[i]=0;i--) { if(fact[N-1-i]>=K) { out: ret += factinv(K); break; } if(P[i]>P[i+1]) { ll smaller=getsmaller(i); for(x=i;x