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
                                            
  //File Name: E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年10月26日 星期三 10时29分59秒
                                   
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
#include <vector>
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int MAXN  = 500000 + 5;
const int MOD = (int)1e9 + 7;
int p[MAXN],bit1[MAXN],bit2[MAXN],n;
bool use[MAXN];
LL jie[MAXN];
void update(int x,int add,int *bit){
	for(int i=x;i<=n;i+=i&-i)
		bit[i] += add;
}
int query(int x,int *bit){
	int res = 0;
	for(int i=x;i>0;i-=i&-i)
		res += bit[i];
	return res;
}
struct Seg{
	int n,ly;
	LL s;
}seg[MAXN << 2];
void pushup(int rt){
	seg[rt].s = seg[rt<<1].s + seg[rt<<1|1].s;
	seg[rt].n = seg[rt<<1].n + seg[rt<<1|1].n;
}
void pushdown(int rt){
	if(seg[rt].ly){
		int &ly = seg[rt].ly;
		int L = rt<<1,R = rt<<1|1;
		seg[L].ly += ly,seg[R].ly += ly;
		seg[L].s += (LL)seg[L].n * ly;
		seg[R].s += (LL)seg[R].n * ly;
		ly = 0;
	}
}
void build(int l,int r,int rt){
	seg[rt].s = seg[rt].ly = seg[rt].n = 0;
	if(l == r){
		if(!use[l]) seg[rt].n = 1;
		return ;
	}
	int m = l + r >> 1;
	build(lson);
	build(rson);
	pushup(rt);
}
void update(int L,int R,int add,int l,int r,int rt){
	if(L <= l && R >= r){
		seg[rt].ly += add;
		seg[rt].s += (LL)add * seg[rt].n;
		return ;
	}
	pushdown(rt);
	int m = l + r >> 1;
	if(L <= m) update(L,R,add,lson);
	if(R > m) update(L,R,add,rson);
	pushup(rt);
}
int init(){
	build(1,n,1);
	jie[0] = 1;
	for(int i=1;i<=n;i++)
		jie[i] = jie[i-1] * i % MOD;
	int sum = 0;
	for(int i=1;i<=n;i++){
		if(!use[i]){
			update(i,1,bit2);
			sum++;
		}
	}
	return sum;
}
LL solve(){
	int sum = init();
	LL ans = 0,tmp1,tmp2;
	int suf = 0;
	for(int i=n;i>0;i--){
		tmp1 = tmp2 = 0;
//		ans = 0;
		if(p[i]){
			int x = query(p[i] - 1,bit1);
			tmp1 = x * jie[sum] % MOD * jie[n - i] % MOD;
			int y = query(p[i],bit2);
			if(sum >= 1)
				tmp2 = (LL)y*suf % MOD * jie[sum-1] % MOD * jie[n-i] % MOD;
			ans = (ans + tmp1 + tmp2) % MOD;
			update(p[i],1,bit1);
			if(p[i] < n) update(p[i]+1,n,1,1,n,1);
		}
		else{
			if(sum >= 2)
				tmp1 = ((LL)sum * (sum - 1) / 2) % MOD * jie[sum-2] % MOD * suf % MOD * jie[n-i] % MOD;
			if(sum >= 1)
				tmp2 = seg[1].s % MOD * jie[sum-1] % MOD * jie[n-i] % MOD;
//			printf("tmp1 = %lld\ntmp2 = %lld\n",tmp1,tmp2);
			ans = (ans + tmp1 + tmp2) % MOD;
			suf++;
		}
//		printf("i = %d ans = %lld\n",i,ans);
	}
//	cout << jie[sum] << endl;
	ans = (ans + jie[sum]) % MOD;
	return ans;
}
int main(){
	scanf("%d",&n);
	memset(use,false,sizeof(use));
	for(int i=1;i<=n;i++){
		scanf("%d",p + i);
		use[p[i]] = true;
	}
	printf("%d\n",(int)solve());
	return 0;
}