#include #include #include #include #include #include #include #include #include #include #include #include #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second typedef long long LL; using namespace std; const int MOD = 1e9+7; const int SIZE = 1e2+10; int a[SIZE],used[SIZE],tt; LL dp[SIZE]; LL fac[SIZE]; void add(LL &x,LL v){ x=(x+v)%MOD; } int main(){ fac[0]=1; REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD; REPP(i,2,SIZE){ REPP(j,1,i+1){ add(dp[i],dp[i-1]); add(dp[i],(j-1)*fac[i-1]); } } int n; while(RI(n)==1){ tt++; REP(i,n){ RI(a[i]); } LL an=0; REP(i,n){ int cnt=0; REPP(j,1,a[i]){ if(used[j]!=tt){ add(an,dp[n-i-1]); add(an,cnt*fac[n-i-1]); cnt++; } } used[a[i]]=tt; } tt++; LL now=1; for(int i=n-1;i>=0;i--){ int cnt=0; LL lt=now; for(int j=1;ja[j])an--; cout<