// Author: Habibie
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define vc vector
#define vci vector<ll>
#define ar array
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x.size())
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#pragma GCC optimize("O3", "unroll-loops")
using db=double;
using ll=long long;
using ull=unsigned long long;
using ii=pair<ll,ll>;
using i128=__int128_t;
const ll inf = 4e18;
const ll mod = 1'000'000'007;
const ll maxn = 3e5;
void solve() {
function<ll(ll, ll)> binpow = [&](long long a, long long b) {
if (b == 0) return 1ll;
long long res = binpow(a, b / 2);
if (b % 2) return((res * res) % mod * a) % mod;
else return (res * res) % mod;
};
ll fac[maxn + 1], finv[maxn + 1];
fac[0] = 1;
finv[0] = 1;
for (ll i = 1; i <= maxn; i++) fac[i] = fac[i - 1] * i % mod;
finv[maxn] = binpow(fac[maxn], mod - 2);
for (ll i = maxn - 1; i >= 0; i--) {
finv[i] = finv[i + 1] * (i + 1) % mod;
}
function<ll(ll, ll)> c = [&](ll n, ll k) {
if (n < 0 or k < 0 or k > n) return 0ll;
return (fac[n] * finv[k] % mod) * finv[n - k] % mod;
};
ll n;
cin >> n;
vci a(n);
for(ll& x : a) cin >> x;
vci b = a;
sort(ALL(b));
if(n==2) {
if(a[0] < a[1]) {
cout << "1\n";
} else {
cout << "2\n";
}
return;
}
if(b==a) {
cout << "1\n";
return;
}
sort(rALL(b));
if(b==a) {
cout << fac[n] << "\n";
return;
}
sort(ALL(b));
ll cnt = 1;
do {
if(a==b) {
cout << cnt << endl;
return;
}
cnt++;
} while(next_permutation(ALL(b)));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t=1;
// cin >> t;
while(t--)
solve();
return 0;
}