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>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int Mod = 1e9 + 7;

const int maxn = 500100;

int n;
int a[maxn + 5];

int fac[maxn + 5];

bool appear[maxn + 5];
int suf[maxn + 5], pre[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(appear, 0, sizeof appear);
	scanf("%d", &n);
	REP(i, 0, n) scanf("%d", a + i), --a[i], appear[a[i]] = 1;
	suf[n] = 0;
	for (int i = n - 1; i >= 0; --i) suf[i] = suf[i + 1] + (!appear[i]);
	pre[0] = 0;
	REP(i, 0, n) pre[i + 1] = pre[i] + (!appear[i]);
	fac[0] = 1;
	REP(i, 0, n) fac[i + 1] = (LL)fac[i] * (i + 1) % Mod;
	int cnt = 0;
	REP(i, 0, n) if (!~a[i]) ++cnt;
	int sum = 0;
	REP(i, 0, n) if (!appear[i]) (sum += i) %= Mod;
	int ret = fac[cnt];
	int res = 0;
	REP(i, 0, n) if (!~a[i]) (res += fac[n - i - 1]) %= Mod;
	int tmp = ((LL)cnt * (cnt - 1) >> 1) % Mod;
	int now = 0;
	static int fen[maxn + 5];
	memset(fen, 0, sizeof fen);
	REP(i, 0, n) 
	{
		if (!~a[i])
		{
			(ret += (LL)sum * fac[cnt - 1] % Mod * fac[n - i - 1] % Mod) %= Mod;
			if (cnt > 1) (ret -= (LL)now * tmp % Mod * fac[cnt - 2] % Mod * fac[n - i - 1] % Mod) %= Mod;
			++now;
			(res -= fac[n - i - 1]) %= Mod;
		}
		else
		{
			if (cnt) (ret -= (LL)res * suf[a[i]] % Mod * fac[cnt - 1] % Mod) %= Mod;
			int num = a[i];
			for (int k = a[i]; k > 0; k -= k & -k) num -= fen[k];
			(ret += (LL)num * fac[cnt] % Mod * fac[n - i - 1] % Mod) %= Mod;
			if (cnt) (ret -= ((LL)now * pre[a[i]] % Mod * fac[cnt - 1] % Mod * fac[n - i - 1] % Mod)) %= Mod;
			for (int k = a[i] + 1; k <= n; k += k & -k) ++fen[k];
		}
	}
	(ret += Mod) %= Mod;
	printf("%d\n", ret);
	return 0;
}
