#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long LL;
const LL MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<LL> deny;
    for(int i = 0; i < N; i++){
        int d;
        cin >> d;
        if(d < N){
            deny.push_back(d);
        }
    }
    sort(deny.begin(), deny.end());
    vector<LL> cur((N+1)*2);
    vector<LL> next((N+1)*2);
    LL prev_deny = -1;
    cur[0] = 1;
    for(int i = 1; i <= deny.size(); i++){
        for(int u = 0; u < 2; u++){
            for(int j = 0; j <= N; j++){
                int u2 = u;
                if(prev_deny != deny[i-1]) u2 = 0;
                next[j*2 + u2] += cur[j*2 + u];
                next[j*2 + u2] %= MOD;
            }
            if(u == 0 || prev_deny != deny[i-1]){
                for(int j = 0; j+1 <= N; j++){
                    next[(j+1)*2 + 1] += cur[j*2 + u];
                    next[(j+1)*2 + 1] %= MOD;
                }
            }
        }
        prev_deny = deny[i-1];
        next.swap(cur);
        for(int j = 0; j < next.size(); j++){
            next[j] = 0;
        }
    }
    vector<LL> pat(N+1);
    for(int i = 0; i <= N; i++){
        pat[i] += cur[i*2 + 0];
        pat[i] %= MOD;
        pat[i] += cur[i*2 + 1];
        pat[i] %= MOD;
    }

    LL ans = 1;
    for(int i = 0; i < N; i++){
        ans *= (N-i);
        ans %= MOD;
    }

    for(int cnt = 1; cnt <= N; cnt++){
        LL tmp = pat[cnt];
        for(int i = cnt; i < N; i++){
            tmp *= (N-i);
            tmp %= MOD;
        }
        if(cnt % 2 == 1){
            ans += MOD - tmp;
            ans %= MOD;
        }else{
            ans += tmp;
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}