One day Mr. Takahashi picked up a dictionary containing all of the N! permutations of integers 1 through N. The dictionary has N! pages, and page i (1 ≤ i ≤ N!) contains the i-th permutation in the lexicographical order.

Mr. Takahashi wanted to look up a certain permutation of length N in this dictionary, but he forgot some part of it.

His memory of the permutation is described by a sequence P_1, P_2, ..., P_N. If P_i = 0, it means that he forgot the i-th element of the permutation; otherwise, it means that he remembered the i-th element of the permutation and it is P_i.

He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo 10^9 + 7.

Constraints

* 1 ≤ N ≤ 500000
* 0 ≤ P_i ≤ N
* P_i ≠ P_j if i ≠ j (1 ≤ i, j ≤ N), P_i ≠ 0 and P_j ≠ 0.

Input

The input is given from Standard Input in the following format:


N
P_1 P_2 ... P_N


Output

Print the sum of the page numbers of the pages he has to check, as modulo 10^9 + 7.

Examples

Input

4
0 2 3 0


Output

23


Input

3
0 0 0


Output

21


Input

5
1 2 3 5 4


Output

2


Input

1
0


Output

1


Input

10
0 3 0 0 1 0 4 0 0 0


Output

953330050
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 500002

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> P;


ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

P add(P a, P b){
    P ans;
    ans.first = (a.first*b.second+a.second*b.first)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

P sub(P a, P b){
    P ans;
    ans.first = ((a.first*b.second-a.second*b.first)%MOD+MOD)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

P mul(P a, P b){
    P ans;
    ans.first = (a.first*b.first)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

//1-indexed
template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }
    
    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};

int N;
int p[500000];
ll cnt_inv[500000];
bool used[500001];
vector<int> v;
int cnt_unused;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> p[i];
        used[p[i]] = true;
    }
    for(int i = 1; i <= N; i++){
        if(!used[i]) {
            v.push_back(i);
            cnt_unused++;
        }
    }
    bit<int> bt(N);
    for(int i = N-1; i >= 0; i--){
        if(p[i] != 0){
            cnt_inv[i] = bt.sum(p[i]);
            bt.add(p[i], 1);
        }
    }
    P inv_exp = P(0, 1);
    ll ans = 0;
    int cnt0 = 0;
    for(int i = N-1; i >= 0; i--){
        if(p[i] == 0){
            P inv = P(0, 1);
            inv = add(inv, P(cnt0, 2));
            inv = add(inv, inv_exp);
            ll tmp = (fac[cnt_unused]*inv.first)%MOD;
            tmp = (tmp*inv_(inv.second))%MOD;
            tmp = (tmp*fac[N-i-1])%MOD;
            // cout << inv.first << ' ' << inv.second << ' ' << tmp << endl;
            ans += tmp;
            ans %= MOD;
            cnt0++;
        }else{
            P inv = P(cnt_inv[i], 1);
            auto ptr = lower_bound(v.begin(), v.end(), p[i]);
            int m = ptr-v.begin();
            P cur_inv = v.size() == 0 ? P(0, 1) : P(m, v.size());
            inv = add(inv, mul(cur_inv, P(cnt0, 1)));
            inv_exp = add(inv_exp, sub(P(1, 1), cur_inv));
            ll tmp = (fac[cnt_unused]*inv.first)%MOD;
            tmp = (tmp*inv_(inv.second))%MOD;
            tmp = (tmp*fac[N-i-1])%MOD;
            // cout << inv.first << ' ' << inv.second << ' ' << tmp << endl;
            ans += tmp;
            ans %= MOD;
        }
        // cout << ans << endl;
    }
    ans += fac[cnt0];
    ans %= MOD;
    cout << ans << endl;
}