#include #include #include #include #include #include #include #include #include #define MOD 1000000007 using namespace std; int num[110]; long long f[110] , g[110] , r[110]; void init() { f[0] = f[1] = 0; f[2] = 1LL; for( int i=3 ; i<=100 ; i++ ) { f[i] = 1LL; f[i] = f[i] * i * (i-1) / 2; f[i] = f[i] * f[i] % MOD; for( int j=i-2 ; j>=1 ; j-- ) f[i] = f[i] * j % MOD; } //for( int i=1 ; i<=5 ; i++ ) cout << f[i] << endl; g[0] = g[1] = 1; for( int i=2 ; i<=100 ; i++ ) g[i] = g[i-1] * i % MOD; //for( int i=1 ; i<=100 ; i++ ) cout << f[i] << endl; } void init2( int n ) { r[n+1] = 1; r[n] = 1; for( int i=n-1 ; i>=1 ; i-- ) { long long t = 0; for( int j = i+1 ; j<=n ; j++ ) if( num[i] > num[j] ) t++; r[i] = g[n-i] * t % MOD + r[i+1]; r[i] = r[i] % MOD; } } int main() { int n , k; init(); while( scanf( "%d" , &n ) != EOF ) { for( int i=1 ; i<=n ; i++ ) scanf( "%d" , &num[i] ); init2(n); //for( int i=1 ; i<=n ; i++ ) cout << r[i] << " "; cout << endl; long long ans = 0; for( int i=1 ; i<=n ; i++ ) { long long tt = 0; for( int j=i+1 ; j<=n ; j++ ) if( num[i] > num[j] ) tt++; ans = ( ans + tt * f[n-i] % MOD ) % MOD; for( long long z = 1 ; z <= tt ; z++ ) ans = ( ans + (z-1) * g[n-i] % MOD ) % MOD; ans = ( ans + ( r[i+1] - 1 ) * tt ) % MOD; } cout << ans << endl; } return 0; }