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>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int fac[MAXN],invfac[MAXN],p[MAXN],s[MAXN],k;
int tr[MAXN],ans[MAXN];
bool vis[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int lowbit(int x) {return x & (-x);}
void insert(int x,int c) {
    while(x <= N) {
	tr[x] = inc(tr[x],c);
	x += lowbit(x);
    }
}
int query(int x) {
    int r = 0;
    while(x > 0) {
	r = inc(r,tr[x]);
	x -= lowbit(x);
    }
    return r;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);
    fac[0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
	fac[i] = mul(fac[i - 1],i); 
    }
    invfac[N] = fpow(fac[N],MOD - 2);
    for(int i = N - 1 ; i >= 0 ; --i) {
	invfac[i] = mul(invfac[i + 1],i + 1);
    }
    for(int i = 1 ; i <= N ; ++i) {
	read(p[i]);
	if(p[i]) vis[p[i]] = 1;
	else ++k;
    }
    int sum = 0;
    for(int i = N ; i >= 1 ; --i) {
	s[i] += s[i + 1];
	if(!vis[i]) {
	    s[i]++;
	    update(sum,i - 1);
	}
    }

    int pre = 0;
    int rem = 0;
    for(int i = 1 ; i <= N ; ++i) {
	if(!p[i]) {
	    update(ans[i],MOD - pre);
	    if(k >= 2) update(ans[i],MOD - mul(rem,mul(C(k,2),fac[k - 2])));
	    update(ans[i],mul(sum,fac[k - 1]));
	    ++rem;
	}
	else {
	    update(ans[i],mul(p[i] - 1,fac[k]));
	    update(ans[i],MOD - mul(query(p[i] - 1),fac[k]));
	    if(k) update(ans[i],MOD - mul(rem,mul(s[1] - s[p[i]],fac[k - 1])));
	    if(k) update(pre,mul(s[p[i] + 1],fac[k - 1]));
	    insert(p[i],1);
	}
    }
    int res = fac[k];
    for(int i = 1 ; i <= N ; ++i) {
	update(res,mul(fac[N - i],ans[i]));
    }
    out(res);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}
