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 <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

const int mod = 1000*1000*1000+7;
const int N = 500010;

int n;
int m;
int f[N];
int rf[N];
int p[N];
int q[N];
int cnt[N];
int fen[N];

int power (int a, int b) {
	int c = 1;
	while (b) {
		if (b & 1) c = ((ll)c * a) % mod;
		a = ((ll)a * a) % mod;
		b /= 2;
	}
	re c;
}

int get (int x) {
	int y = 0;
	while (x > 0) {
		y += fen[x];
		x = (x & (x + 1)) - 1;
	}
	re y;
}

void add (int x, int y) {
	while (x <= n) {
		fen[x] += y;
		x |= x + 1;
	}
}

int main () {
	scanf ("%d", &n);
	int zero = 0;
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &p[i]);
		q[p[i]] = i;
		zero += int (p[i] == 0);
	}
	cnt[0] = 0;
	int cur = 0, sum = 0, zerop = 0;
	for (int i = 1; i <= n; i++) {
		if (q[i] == 0) {
			zerop = (zerop + cur) % mod;
			cur++;
			sum = (sum + i - 1) % mod;
		}
		cnt[i] = cur;
	}	
	f[0] = rf[0] = 1;
	for (int i = 1; i <= n; i++) {
		f[i] = ((ll)f[i - 1] * i) % mod;
		rf[i] = power (f[i], mod - 2);
	}
	int ans = 0, pos = 0, tot = 0;
	for (int i = 1; i <= n; i++) {
		int cur = 0;
		if (p[i] != 0) {
			cur = (cur + (ll)(p[i] - 1) * f[zero]) % mod;
			if (zero > 0) cur = (cur - (ll)pos * cnt[p[i] - 1] % mod * f[zero - 1] % mod + mod) % mod;
			cur = (cur - (ll)f[zero] * get (p[i] - 1) % mod + mod) % mod;
			add (p[i], 1);
			tot = (tot + zero - cnt[p[i]]) % mod;
			if (tot < 0) tot += mod;
		} else {
			cur = (cur + (ll)sum * (zero - 1)) % mod;
			if (zero > 1) cur = (cur - (ll)zerop * pos % mod + mod) % mod;				
			cur = (cur - (ll)(zero - 1) * tot % mod + mod) % mod;
			cur = ((ll)cur * f[zero - 2]) % mod;
			pos++;
		}
		ans = (ans + (ll)cur * f[n - i]) % mod;
	}
	ans = (ans + f[zero]) % mod;
	printf ("%d\n", ans);
	return 0;
}