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 SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL fac[SIZE];
void ADD(LL& x,LL v){
    x=(x+v)%MOD;
    if(x<0)x+=MOD;
}
LL mypow(LL x,LL y){
    x%=MOD;
    LL res=1%MOD;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}
int p[SIZE];
int BIT[SIZE];
void ins(int x){
    for(;x<SIZE;x+=x&-x)BIT[x]++;
}
int qq(int x){
    int res=0;
    for(;x;x-=x&-x)res+=BIT[x];
    return res;
}
int BIT2[SIZE];
void ins2(int x){
    for(;x<SIZE;x+=x&-x)BIT2[x]++;
}
int qq2(int x){
    int res=0;
    for(;x;x-=x&-x)res+=BIT2[x];
    return res;
}
bool use[SIZE];
int main(){
    fac[0]=1;
    REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD;
    DRI(n);
    LL zero=0;
    REP(i,n){
        RI(p[i+1]);
        if(!p[i+1])zero++;
        else use[p[i+1]]=1;
    }
    LL sum=0;
    int it=0;
    REPP(i,1,n+1)
        if(!use[i]){
            ins(i);
            sum+=i-1-it;
            it++;
        }
    sum%=MOD;
    LL an=fac[zero];
    LL emp=0;
    LL inv_two=mypow(2,MOD-2);
    REPP(i,1,n+1){
        if(!p[i]){
            ADD(an,sum*fac[zero-1]%MOD*fac[n-i]);
            if(zero>1)ADD(an,fac[zero]*(zero-emp-1)%MOD*inv_two%MOD*fac[n-i]);
            emp++;
        }
        else{
            LL ll=qq(p[i]);
            LL ll2=qq2(p[i]);
            ADD(an,(p[i]-1-ll-ll2)*fac[zero]%MOD*fac[n-i]);
            if(zero)ADD(an,ll*(zero-emp)%MOD*fac[zero-1]%MOD*fac[n-i]);
            ADD(sum,-(zero-ll));
            ins2(p[i]);
        }
        //printf("%d:%lld\n",i,an);
    }
    cout<<an<<endl;
    return 0;
}
