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<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

struct BIT {
private:
	vector<ll> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

ll fact[1 << 19];
void init() {
	fact[0] = 1;
	rep1(i, (1 << 19)-1) {
		fact[i] = fact[i - 1] * i%mod;
	}
}
int n; vector<int> p;
vector<int> zeros;
ll calc_ff() {
	ll ret = 0;
	BIT b(n + 1);
	per(i, n) {
		if (p[i] == 0)continue;
		int num = b.sum(p[i]);
		(ret += fact[n - 1 - i] * num%mod*fact[zeros.size()])%=mod;
		b.add(p[i], 1);
	}
	return ret;
}
ll calc_uf() {
	ll sum = 0;
	ll ret = 0;
	per(i, n) {
		if (p[i] == 0) {
			(ret += sum * fact[n - 1 - i]%mod*fact[(int)zeros.size()-1])%=mod;
		}
		else {
			int id = lower_bound(zeros.begin(), zeros.end(), p[i]) - zeros.begin();
			sum += zeros.size() - id;
			if (sum >= mod)sum -= mod;
		}
	}
	return ret;
}
ll calc_fu() {
	int num = 0;
	ll ret = 0;
	per(i, n) {
		if (p[i] > 0) {
			int id = lower_bound(zeros.begin(), zeros.end(), p[i]) - zeros.begin();
			(ret += (ll)id*num%mod*fact[n - 1 - i] % mod*fact[zeros.size() - 1]) %= mod;
		}
		else num++;
	}
	return ret;
}
ll calc_uu() {
	ll ret = 0;
	int tmp = 0;
	per(i, n) {
		if (p[i])continue;
		ll ave = tmp * (mod + 1) / 2 % mod;
		(ret += ave * fact[zeros.size()]%mod*fact[n - 1 - i]) %= mod;
		tmp++;
	}
	return ret;
}
void solve() {
	cin >> n;
	p.resize(n);
	rep(i, n)cin >> p[i];
	vector<bool> used(n + 1, false);
	rep(i, n) {
		used[p[i]] = true;
	}
	rep1(i, n)if (!used[i])zeros.push_back(i);
	ll ans = 0;
	ans += calc_ff();
	ans += calc_fu();
	ans += calc_uf();
	ans += calc_uu();
	ans += fact[zeros.size()];
	cout << ans % mod << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}