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>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define ll __int128
//#define int ll
//#dLefine char ll
//#define double ld
typedef vector<char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vpi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector<short> vs;
typedef vector <vs> vvs;
typedef vector <vvs> vvvs;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <vvl> vvvl;
typedef vector <ld> vld;
typedef vector <vld> vvld;
typedef vector <vvld> vvvld;
typedef vector <string> vst;
typedef vector <vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template<class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template<class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template<class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " << get<3>(a) << "}";
}

template<class T>
inline ostream &operator<<(ostream &out, vector <T> &a) {
    out << "[";
    fori (i, a.size())out << a[i] << vector < string > {", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
#ifdef HK_CUP
    freopen("finput.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
#ifndef HK_CUP
    cout << "\n\nTOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
#endif
    return 0;
}

const int M = 1e9 + 7;
const int N = 5e5 + 55;

struct Tree {
    vl t;
    vl pushing;
    Tree(int n) {
        t.resize(n << 2, 0);
        pushing.resize(n << 2, 0);
    }

    void push(int v, int tl, int tr) {
        int tm = tl + tr >> 1;
        if (pushing[v]) {
            t[v << 1] += pushing[v] * (tm - tl + 1);
            t[v << 1 | 1] += pushing[v] * (tr - tm);
            pushing[v << 1] += pushing[v];
            pushing[v << 1 | 1] += pushing[v];
            pushing[v] = 0;
        }
    }

    void set(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v] = val;
            return;
        }
        push(v, tl, tr);
        int tm = tl + tr >> 1;
        if (pos <= tm)
            set(v << 1, tl, tm, pos, val);
        else
            set(v << 1 | 1, tm + 1, tr, pos, val);
        t[v] = t[v << 1] + t[v << 1 | 1];
    }

    void inc(int v, int tl, int tr, int l, int r, ll val) {
        if (l > r)
            return;
        if (tl == l && tr == r) {
            t[v] += val * (tr - tl + 1);
            pushing[v] += val;
            return;
        }
        push(v, tl, tr);
        int tm = tl + tr >> 1;
        inc(v << 1, tl, tm, l, min(tm, r), val);
        inc(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, val);
        t[v] = t[v << 1] + t[v << 1 | 1];
    }

    ll get(int v, int tl, int tr, int l, int r) {
        if (l > r)
            return 0;
        if (tl == l && tr == r)
            return t[v];
        push(v, tl, tr);
        int tm = tl + tr >> 1;
        return get(v << 1, tl, tm, l, min(tm, r)) +
        get(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r);
    }
};

int fact[N];

void init() {
    fact[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = (ll) i * fact[i - 1] % M;
    }
}
int p[N];

void insum(int &a, int b) {
    a = (a + b) % M;
}

int getnum(vi p) {
    int n = p.size();
    vi cur(n);
    fori (i, n) {
        cur[i] = i + 1;
    }
    int ret = 1;
    if (p == cur)
        return ret;
    while (next_permutation(ALL(cur))) {
        ret++;
        if (cur == p)
            return ret;
    }
    assert(0);
}

void smain() {
//    int sum = 0;
//    watch(sum += getnum({5, 3, 1, 2, 4}));
//    watch(sum += getnum({5, 3, 1, 4, 2}));
//    watch(sum += getnum({5, 3, 2, 1, 4}));
//    watch(sum += getnum({5, 3, 2, 4, 1}));
//    watch(sum += getnum({5, 3, 4, 1, 2}));
//    watch(sum += getnum({5, 3, 4, 2, 1}));
//    watch(sum);
    init();

    int n;
    cin >> n;
    set<int> wasnt;
    for (int i = 1; i <= n; ++i) {
        wasnt.insert(i);
    }
    fori (i, n) {
        cin >> p[i];
        wasnt.erase(p[i]);
    }
    vi fset(ALL(wasnt));
    int S = fset.size();
    Tree tree(S);
    fori (i, n) if (p[i]) {
        tree.inc(1, 0, S - 1, lower_bound(ALL(fset), p[i]) - fset.begin(), S - 1, 1);
//        cerr << "(" << lower_bound(ALL(fset), p[i]) - fset.begin() << ", " << S - 1 << ")" << endl;
    }
//    watch(tree.t[1]);
    vi cnt(n);
    {
        Tree tree_us(n);
        for (int i = n - 1; i >= 0; --i) if (p[i]) {
            cnt[i] = tree_us.get(1, 1, n, 1, p[i]);
            tree_us.set(1, 1, n, p[i], 1);
        }
    }
    int ans = 0;
    int rf = S;
    fori (i, n) {
        if (p[i]) {
            int cur = (ll) fact[S] * cnt[i] % M * fact[n - i - 1] % M;
            insum(ans, cur);
            if (S) {
                int cnt_less = lower_bound(ALL(fset), p[i]) - fset.begin();
                cur = (ll) rf * fact[S - 1] % M * cnt_less % M * fact[n - i - 1] % M;
                insum(ans, cur);
            }
            tree.inc(1, 0, S - 1, lower_bound(ALL(fset), p[i]) - fset.begin(), S - 1, -1);
        } else {
            rf--;
            if (S >= 2) {
                int cur = (ll) S * (S - 1) / 2 % M * rf % M * fact[S - 2] % M * fact[n - i - 1] % M;
                insum(ans, cur);
            }
            int A = tree.get(1, 0, S - 1, 0, S - 1) % M;
            int cur = (ll) fact[S - 1] * fact[n - i - 1] % M * A % M;
            insum(ans, cur);
        }
//        watch(ans);
    }
    insum(ans, fact[S]);
    cout << ans;
}