#include #include #include using namespace std; using V = vector; int main(){ int n; cin >> n; V a(n); for(auto &x:a) cin >> x; sort(a.begin(), a.end()); long long ans = 0; V b; int c = 0; do { b = a; for(int i = 1; i < n; ++i) b[i] = max(b[i-1], b[i]); long long m = a[n-1];; for(int i = n-1; i >= 0; --i) if((m = min(m, a[i])) == b[i]) goto end; ++ans; end:; } while(next_permutation(a.begin(), a.end())); cout << ans << endl; }