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<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 5e5+7, MOD = 1e9+7;

//need define int long long
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

struct M {
ll x;
M (int x_) {
    x = mod(x_);
}   
M () {
    x = 0;
}
M operator + (M y) {
    int ans = x + y.x;
    if (ans >= MOD)
        ans -= MOD;
    return M(ans);
}
M operator - (M y) {
    int ans = x - y.x;
    if (ans < 0)
        ans += MOD;
    return M(ans);            
}   
M operator * (M y) {
    return M(x * y.x % MOD);   
}   
M operator / (M y) {
    return M(x * fp(y.x, MOD - 2) % MOD);
}   
M operator + (int y) {
    return (*this) + M(y);
}
M operator - (int y) {
    return (*this) - M(y);
}   
M operator * (int y) {
    return (*this) * M(y);
}   
M operator / (int y) {
    return (*this) / M(y);
}   
M operator ^ (int p) {
    return M(fp(x, p));
}   
void operator += (M y) {
    *this = *this + y;
}   
void operator -= (M y) {
    *this = *this - y;
}   
void operator *= (M y) {
    *this = *this * y;
}
void operator /= (M y) {
    *this = *this / y;
}   
void operator += (int y) {
    *this = *this + y;
}   
void operator -= (int y) {
    *this = *this - y;
}   
void operator *= (int y) {
    *this = *this * y;
}
void operator /= (int y) {
    *this = *this / y;
}   
void operator ^= (int p) {
    *this = *this ^ p;
}
};  

M f[N], inv[N];
void prec() {
    f[0] = M(1);
    for (int i = 1; i < N; ++i)
        f[i] = f[i - 1] * M(i);
    inv[N - 1] = f[N - 1] ^ (MOD - 2);
    for (int i = N - 2; i >= 0; --i)
        inv[i] = inv[i + 1] * M(i + 1);
}
M C(int n, int k) {
    if (n < k)
        return M(0);
    else
        return f[n] * inv[k] * inv[n - k];
}   

int p[N], pos[N];

struct Fen {
int f[N];
void clear() {
    for (int i = 0; i < N; ++i) f[i] = 0;
}   
void add(int i, int x) {
    for (; i < N; i |= i + 1) 
        f[i] += x;
}   
int get(int i) {
    int ans = 0;
    for (; i >= 0; i &= i + 1, --i) ans += f[i];
    return ans;
}   
int get(int l, int r) {
    //check r < l!
    return get(r) - get(l - 1);
}   
} fen_nu, fen_used;

int suff[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    prec();

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        if (p[i]) {
            pos[p[i]] = i;
        }
    }   

    int nul = 0;
    for (int i = 1; i <= n; ++i)
        nul += !p[i];
    int l = 0;

    for (int i = 1; i <= n; ++i) {
        if (pos[i])
            fen_used.add(i, 1);
        else
            fen_nu.add(i, 1);
    }

    for (int i = n; i; --i)
        suff[i] = suff[i + 1] + (pos[i] == 0);        

    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; ++i) {
        if (pos[i]) {
            sum1 += suff[i + 1];
        }
        else {
            sum2 += suff[i + 1];
        }   
    }   

    M ans = f[nul];
    for (int i = 1; i <= n; ++i) {
        if (p[i]) {
            int x1 = fen_used.get(p[i] - 1);
            ans += (C(nul, l) * f[l]) * f[nul - l] * f[n - i] * x1;
            int x2 = fen_nu.get(p[i] - 1);
            ans += (C(nul - 1, l) * f[l]) * f[nul - l] * f[n - i] * x2;
        }   
        else {

            int x1 = sum1;
            int x2 = sum2;
            ans += (C(nul - 1, l) * f[l]) * f[nul - 1 - l] * f[n - i] * x1;
            ans += (C(nul - 2, l) * f[l]) * f[nul - 1 - l] * f[n - i] * x2;

            /*
            for (int x = 1; x <= n; ++x) {
                if (!pos[x]) {
                    int x1 = fen_used.get(x - 1);
                    int x2 = fen_nu.get(x - 1);
                    ans += (C(nul - 1, l) * f[l]) * f[nul - 1 - l] * f[n - i] * x1;
                    ans += (C(nul - 2, l) * f[l]) * f[nul - 1 - l] * f[n - i] * x2;
                }   
            }
            */  
        }   
        if (p[i] == 0) {
            l++;
        }
        else {
            sum1 -= suff[p[i]];
            fen_used.add(p[i], -1);
        }
    }   
    cout << ans.x << endl;
}
