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
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 5e5 + 10;
int F[N], G[N];
int p[N], c[N];
bool visit[N];

int64 power_mod(int64 a, int n) {
  int64 ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * a % MOD;
    a = a * a % MOD;
  }
  return ret;
}

int64 comb(int n, int m) {
  if (m > n || n < 0 || m < 0) return 0;
  return (int64)F[n] * G[m] % MOD * G[n - m] % MOD;
}

int64 c2(int m) {
  return (int64)m * (m - 1) / 2 % MOD;
}

void add(int x, int n) {
  for (; x <= n; x += x & -x) {
    c[x]++;
  }
}

int query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

int main() {
  F[0] = G[0] = 1;
  for (int i = 1; i < N; ++i) {
    F[i] = (int64)F[i - 1] * i % MOD;
    G[i] = power_mod(F[i], MOD - 2);
  }
  int n, m;
  vector<int> zero;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    if (p[i]) visit[p[i]] = true;
  }
  for (int i = 1; i <= n; ++i) {
    if (!visit[i]) zero.push_back(i);
  }
  m = zero.size();
  int ret = 0, cnt = 0;
  int64 sum2 = 0, cnt2 = 0;
  for (auto& it : zero) sum2 = (sum2 + it - 1) % MOD;
  // trace(sum2);
  for (int i = 0; i < n; ++i) {
    if (p[i] == 0) {
      int64 sum = (int64)(sum2 + MOD - cnt2) * F[m - 1] % MOD;
      sum = (sum + MOD -
             c2(m) * comb(m - 2, cnt - 1) % MOD *
             F[m - 1 - cnt] % MOD * F[cnt] % MOD) % MOD;
      ret += sum * F[n - 1 - i] % MOD;
      ret %= MOD;
      ++cnt;
    } else {
      int L = lower_bound(zero.begin(), zero.end(), p[i]) - zero.begin();
      int64 sum = (int64)F[m] * (p[i] - 1 - query(p[i])) % MOD;
      sum = (sum + MOD -
             (int64)L * comb(m - 1, cnt - 1) % MOD *
             F[m - cnt] % MOD * F[cnt] % MOD) % MOD;
      // trace(L, cnt, sum);
      ret += sum * F[n - 1 - i] % MOD;
      ret %= MOD;
      add(p[i], n);
      cnt2 = (cnt2 + m - L) % MOD;
    }
    // trace(i, ret);
  }
  ret = (ret + F[m]) % MOD;
  printf("%d\n", ret);
  return 0;
}
