#include using namespace std; const int N = 1202; const int Mod = 1000000007; long long fact[N]; int main() { fact[0] = 1; for (int i = 1; i < 10; i++) { fact[i] = fact[i - 1] * i; fact[i] %= Mod; } int n; cin >> n; vector v(n), vSorted(n); for (int i = 0; i < n; i++) { cin >> v[i]; vSorted[i] = v[i]; } sort(vSorted.begin(), vSorted.end()); if (v == vSorted) { long long sum = 0; for (int i = 0; i < n; i++) { sum += fact[i]; sum %= Mod; } cout << sum << endl; } else { cout << 1 << endl; } }