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 <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 500010
const int mod = 1e9 + 7;
int a[maxn], pre[maxn], suf[maxn], pre2, low[maxn], up[maxn];
int pwd[maxn], ans, bit[maxn];
bool appear[maxn];
int main()
{
//	setfile();
	int n, K = 0; scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		--a[i];
		K += (a[i] == -1);
		if (a[i] != -1) appear[a[i]] = 1;
	}
	pwd[0] = 1;
	for (int i = 1; i <= n; ++i) pwd[i] = 1ll * pwd[i - 1] * i % mod;
	for (int i = 0; i < n; ++i) pre[i] = (i > 0 ? pre[i - 1] : 0) + (a[i] == -1);
	for (int i = n - 1; ~i; --i) suf[i] = suf[i + 1] + (a[i] == -1);
	for (int i = 0; i < n; ++i) low[i] = (i > 0 ? low[i - 1] : 0) + !appear[i];
	for (int i = n - 1; ~i; --i) up[i] = up[i + 1] + !appear[i];
	// printf("K = %d\n", K);
	ans = pwd[K];

	int CK2 = (1ll * K * (K - 1) >> 1) % mod;
	if (a[n - 1] != -1)
	{
		for (int j = a[n - 1] + 1; j <= n; j += j & -j) ++bit[j];
		pre2 = (pre2 + up[a[n - 1]]) % mod;
	}
	for (int i = n - 2; i >= 0; --i)
	{
		if (a[i] != -1)
		{
			int num = 0;
			for (int j = a[i]; j; j -= j & -j)
				num += bit[j];
			ans = (ans + 1ll * num * pwd[K] % mod * pwd[n - i - 1]) % mod;
			ans = (ans + 1ll * low[a[i]] * pwd[K - 1] % mod * suf[i] % mod * pwd[n - i - 1]) % mod;
			for (int j = a[i] + 1; j <= n; j += j & -j) ++bit[j];
			pre2 = (pre2 + up[a[i]]) % mod;
		}
		else
		{
			ans = (ans + 1ll * pre2 * pwd[K - 1] % mod * pwd[n - i - 1]) % mod;
			K > 1 ? ans = (ans + 1ll * CK2 * pwd[K - 2] % mod * (suf[i] - 1) % mod * pwd[n - i - 1]) % mod : 0;
		}
		// printf("%d\n", ans );
	}
	printf("%d\n", ans );
	return 0;
}
/*
5
5 2 0 3 1 
*/