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<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A[510000],n,w[510000],x[510000],num[510000],B[510000];
const int mo=1e9+7;
int add(int *A,int k1,int k2){
	for (;k1<=n;k1+=k1&(-k1)) A[k1]=(A[k1]+k2)%mo;
}
int find(int *A,int k1){
	int ans=0; for (;k1;k1-=k1&(-k1)) ans=(ans+A[k1])%mo; return ans;  
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&x[i]),w[x[i]]++; w[0]=0;
	for (int i=1;i<=n;i++) w[i]+=w[i-1];
	for (int i=1;i<=n;i++) w[i]=i-w[i];
	num[n]=1; int tot=w[n]; //cout<<tot<<" "<<w[1]<<" "<<w[2]<<" "<<w[3]<<endl;
	for (int i=n-1;i;i--) num[i]=1ll*num[i+1]*(n-i)%mo;
	int pre=0,pre1=0,pre2=0;
	for (int i=1;i<=n;i++) if (x[i]) pre1=(pre1+1ll*w[x[i]]*num[i])%mo;
	int nu=1ll*tot*(tot-1)/2%mo,way=1,way2=1;
	for (int i=1;i<=tot-2;i++) nu=1ll*nu*i%mo;
	for (int i=1;i<=tot;i++) way=1ll*way*i%mo;
	for (int i=1;i<tot;i++) way2=1ll*way2*i%mo;
	int ans=0;
	for (int i=n;i;i--)
		if (x[i]){
			pre=(pre+tot-w[x[i]])%mo; 
			pre1=(pre1-1ll*w[x[i]]*num[i])%mo;
			add(A,x[i],1);
			ans=(ans+1ll*find(A,x[i]-1)*num[i]%mo*way)%mo;
		//	cout<<"fa "<<i<<" "<<num[i]<<" "<<find(A,x[i]-1)<<endl;
		} else {
		//	cout<<pre<<" "<<pre1<<" "<<nu<<endl;
			ans=(ans+(1ll*num[i]*pre+pre1)%mo*way2)%mo;
			ans=(ans+1ll*nu*pre2%mo*num[i])%mo;
			pre2++;// cout<<ans<<endl;
		}
	ans=(ans+way)%mo;
	printf("%d\n",(ans+mo)%mo);
	return 0;
}