#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n"); #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using mint = modint998244353; using vm = vector; void solve() { int n; cin >> n; vi c(n, 0); rep(i, 0, n) { int a; cin >> a; if (a < n) c[a]++; } vector dp(n + 1, 0); dp[0] = 1; rep(i, 0, n) rrep(j, 0, i + 1) dp[j + 1] += dp[j] * c[i]; modint1000000007 ans = 0, f = 1; for (int i = n; i >= 0; i--, f *= n - i) ans += (1 - (i & 1) * 2) * dp[i] * f; cout << ans.val() << endl; } int main() { int t = 1; // cin >> t; while (t--) solve(); }