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;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int MN = 500010;

// 1-indexed, [1, n]
template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = MN;
		memset(bit, 0, sizeof(bit));
	}

	T sum(int i) {
		++i;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x) {
		++i;
		while (i < n) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

const int SZ = 1 << 19;

struct segtree {
	vector<ll> dat1, dat2;

	void init() {
		dat1.resize(SZ * 2, 0);
		dat2.resize(SZ * 2, 0);	
	}
	
	void add(int a, int b, ll x, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return ;
		if (a <= l && r <= b) dat1[k] += x;
		else {
			dat2[k] += (min(b, r) - max(a, l)) * x;
			add(a, b, x, k * 2 + 1, l, (l + r) / 2);
			add(a, b, x, k * 2 + 2, (l + r) / 2, r);
		}
	}

	ll sum(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return dat1[k] * (r - l) + dat2[k];
		else {
			ll res = (min(b, r) - max(a, l)) * dat1[k];
			res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
			res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
			return res;
		}
	}
};

const ll MOD = TEN(9) + 7;
const int MX = TEN(5) * 6;
const ll i2 = (MOD + 1) / 2;

ll inv[MX], fact[MX], ifact[MX];

void init() {
	inv[1] = 1;
	for (int i = 2; i < MX; ++i) {
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	}
	fact[0] = ifact[0] = 1;
	for (int i = 1; i < MX; ++i) {
		fact[i] = fact[i-1] * i % MOD;
		ifact[i] = ifact[i-1] * inv[i] % MOD;
	}
}

int main() {
	init();

	int N; cin >> N;
	vi P(N);

	int free = 0;

	rep(i, N) {
		cin >> P[i];
		--P[i];
		if (P[i] == -1) {
			++free;
		}
	}

	ll ans = 0;

	{
		ll ff = 0; //free and free
		int cur = 0;
		for (int i = N-1; i >= 0; --i) {
			if (P[i] == -1) {
				ff = (ff + cur * fact[free] % MOD * i2 % MOD * fact[N-1-i]) % MOD;
				++cur;
			}
		}
		//dump(ff);

		ans = (ans + ff) % MOD;
	}

	{
		ll dd = 0; //defined and defined
		BIT<int> T;
		rep(i, N) if (P[i] != -1) T.add(P[i], 1);

		rep(i, N) {
			if (P[i] == -1) continue;
			T.add(P[i], -1);
			int rem = T.sum(P[i]);
			dd = (dd + rem * fact[free] % MOD * fact[N-1-i]) % MOD;
		}

		//dump(dd);

		ans = (ans + dd) % MOD;
	}

	{
		vi fr(N, 1);

		rep(i, N) if (P[i] != -1) {
			fr[P[i]] = 0;
		}

		vi cand;
		rep(i, N) if (fr[i]) cand.pb(i);

		segtree seg;
		seg.init();

		ll fd = 0; //free and defined

		for (int i = N-1; i >= 0; --i) {
			if (P[i] == -1) {
				ll s = seg.sum(0, cand.size()) % MOD;
				fd = (fd + fact[free] * inv[free] % MOD * s % MOD * fact[N-1-i]) % MOD;
			} else {
				int u = lower_bound(ALL(cand), P[i]) - cand.begin();
				seg.add(u, cand.size(), 1);
			}
		}

		//dump(fd);
		ans = (ans + fd) % MOD;
	}

	{
		ll df = 0; //defined and free

		int cur = 0;
		BIT<int> T;
		rep(i, N) T.add(i, 1);
		rep(i, N) if (P[i] != -1) T.add(P[i], -1);

		for (int i = N-1; i >= 0; --i) {
			if (P[i] == -1) {
				++cur;
			} else {
				int small = T.sum(P[i]);
				df = (df + fact[free] * small % MOD * inv[free] % MOD * fact[N-1-i] % MOD * cur) % MOD;
			}
		}

		//dump(df);

		ans = (ans + df) % MOD;
	}

	ans = (ans + fact[free]) % MOD;
	cout << ans << endl;

	return 0;
}