description: Mr. Chanek opened a letter from his fellow, who is currently studying at Singanesia. Here is what it says.
  
  Define an array b (0 ≤ b_i < k) with n integers. While there exists a pair (i, j) such that b_i ≠ b_j, do the following operation:
  
    * Randomly pick a number i satisfying 0 ≤ i < n. Note that each number i has a probability of 1/n to be picked. 
    * Randomly Pick a number j satisfying 0 ≤ j < k. 
    * Change the value of b_i to j. It is possible for b_i to be changed to the same value. 
  
  
  
  Denote f(b) as the expected number of operations done to b until all elements of b are equal. 
  
  You are given two integers n and k, and an array a (-1 ≤ a_i < k) of n integers. 
  
  For every index i with a_i = -1, replace a_i with a random number j satisfying 0 ≤ j < k. Let c be the number of occurrences of -1 in a. There are k^c possibilites of a after the replacement, each with equal probability of being the final array.
  
  Find the expected value of f(a) modulo 10^9 + 7. 
  
  Formally, let M = 10^9 + 7. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and q not ≡ 0 \pmod{M}. Output the integer equal to p ⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p \pmod{M}.
  
  After reading the letter, Mr. Chanek gave the task to you. Solve it for the sake of their friendship!
  
  Input
  
  The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 10^9). 
  
  The second line contains n integers a_1, a_2, …, a_n (-1 ≤ a_i < k).
  
  Output
  
  Output an integer denoting the expected value of f(a) modulo 10^9 + 7.
  
  Examples
  
  Input
  
  
  2 2
  0 1
  
  
  Output
  
  
  2
  
  
  Input
  
  
  2 2
  0 -1
  
  
  Output
  
  
  1
  
  
  Input
  
  
  3 3
  0 1 1
  
  
  Output
  
  
  12
  
  
  Input
  
  
  3 3
  -1 -1 -1
  
  
  Output
  
  
  11
  
  
  Input
  
  
  10 9
  -1 0 -1 1 1 2 2 3 3 3
  
  
  Output
  
  
  652419213
solution: #include <bits/stdc++.h>
  using namespace std;
  int n, k;
  int fact[100005], invf[100005], inv[100005], f[100005];
  map<int, int> cnt;
  void add(int &a, int b) {
    a += b;
    if (a >= 1000000007) a -= 1000000007;
  }
  void dec(int &a, int b) {
    a -= b;
    if (a < 0) a += 1000000007;
  }
  int pow_mod(int a, int i) {
    int s = 1;
    while (i) {
      if (i & 1) s = 1LL * s * a % 1000000007;
      a = 1LL * a * a % 1000000007;
      i >>= 1;
    }
    return s;
  }
  int comb(int n, int k) {
    if (n < k) return 0;
    return 1LL * fact[n] * invf[k] % 1000000007 * invf[n - k] % 1000000007;
  }
  const double PI = acos(-1.0);
  namespace fft {
  struct num {
    double x, y;
    num() { x = y = 0; }
    num(double x, double y) : x(x), y(y) {}
  };
  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) {
    return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
  }
  inline num conj(num a) { return num(a.x, -a.y); }
  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};
  const double PI = acosl(-1.0);
  void ensure_base(int nbase) {
    if (nbase <= base) return;
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++)
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    roots.resize(1 << nbase);
    while (base < nbase) {
      double angle = 2 * PI / (1 << (base + 1));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
        double angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }
  void fft(vector<num> &a, int n = -1) {
    if (n == -1) n = a.size();
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++)
      if (i < (rev[i] >> shift)) swap(a[i], a[rev[i] >> shift]);
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }
  vector<num> fa, fb;
  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int)fa.size()) fa.resize(sz);
    for (int i = 0; i < sz; i++) {
      int x = (i < (int)a.size() ? a[i] : 0);
      int y = (i < (int)b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) res[i] = fa[i].x + 0.5;
    return res;
  }
  vector<int> multiply_mod(vector<int> &a, vector<int> &b, int m, int eq = 0) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int)fa.size()) fa.resize(sz);
    for (int i = 0; i < (int)a.size(); i++) {
      int x = (a[i] % m + m) % m;
      fa[i] = num(x & ((1 << 15) - 1), x >> 15);
    }
    fill(fa.begin() + a.size(), fa.begin() + sz, num{0, 0});
    fft(fa, sz);
    if (sz > (int)fb.size()) fb.resize(sz);
    if (eq)
      copy(fa.begin(), fa.begin() + sz, fb.begin());
    else {
      for (int i = 0; i < (int)b.size(); i++) {
        int x = (b[i] % m + m) % m;
        fb[i] = num(x & ((1 << 15) - 1), x >> 15);
      }
      fill(fb.begin() + b.size(), fb.begin() + sz, num{0, 0});
      fft(fb, sz);
    }
    double ratio = 0.25 / sz;
    num r2(0, -1), r3(ratio, 0), r4(0, -ratio), r5(0, 1);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num a1 = (fa[i] + conj(fa[j]));
      num a2 = (fa[i] - conj(fa[j])) * r2;
      num b1 = (fb[i] + conj(fb[j])) * r3;
      num b2 = (fb[i] - conj(fb[j])) * r4;
      if (i != j) {
        num c1 = (fa[j] + conj(fa[i]));
        num c2 = (fa[j] - conj(fa[i])) * r2;
        num d1 = (fb[j] + conj(fb[i])) * r3;
        num d2 = (fb[j] - conj(fb[i])) * r4;
        fa[i] = c1 * d1 + c2 * d2 * r5;
        fb[i] = c1 * d2 + c2 * d1;
      }
      fa[j] = a1 * b1 + a2 * b2 * r5;
      fb[j] = a1 * b2 + a2 * b1;
    }
    fft(fa, sz);
    fft(fb, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      long long aa = fa[i].x + 0.5;
      long long bb = fb[i].x + 0.5;
      long long cc = fa[i].y + 0.5;
      res[i] = (aa + ((bb % m) << 15) + ((cc % m) << 30)) % m;
    }
    return res;
  }
  vector<int> square_mod(vector<int> &a, int m) {
    return multiply_mod(a, a, m, 1);
  }
  };  // namespace fft
  int prob[100005];
  int main() {
    scanf("%d%d", &n, &k);
    fact[0] = invf[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = 1LL * fact[i - 1] * i % 1000000007;
    invf[n] = pow_mod(fact[n], 1000000007 - 2);
    for (int i = n - 1; i >= 1; i--)
      invf[i] = 1LL * invf[i + 1] * (i + 1) % 1000000007;
    for (int i = 1; i <= n; i++)
      inv[i] = 1LL * invf[i] * fact[i - 1] % 1000000007;
    f[0] = k - 1;
    for (int i = 1; i < n; i++)
      f[i] = 1LL * (k - 1) * (n + 1LL * i * f[i - 1] % 1000000007) % 1000000007 *
             inv[n - i] % 1000000007;
    for (int i = n - 1; i >= 0; i--) add(f[i], f[i + 1]);
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      cnt[x]++;
    }
    int num = cnt[-1], invk = pow_mod(k, 1000000007 - 2),
        pr = 1LL * invk * (k - 1) % 1000000007;
    for (int i = 0; i <= num; i++)
      prob[i] = 1LL * comb(num, i) * pow_mod(invk, i) % 1000000007 *
                pow_mod(pr, num - i) % 1000000007;
    vector<int> v1, v2;
    for (int i = 0; i <= n; i++) v1.push_back(prob[i]);
    for (int i = n; i >= 0; i--) v2.push_back(f[i]);
    vector<int> g = fft::multiply_mod(v1, v2, 1000000007);
    int ans = 0;
    int c = 0;
    for (auto p : cnt) {
      if (p.first == -1) continue;
      c++;
      add(ans, g[n - p.second]);
    }
    add(ans, 1LL * (k - c) * g[n] % 1000000007);
    dec(ans, 1LL * (k - 1) * f[0] % 1000000007);
    ans = 1LL * ans * pow_mod(k - 1, 1000000007 - 2) % 1000000007;
    printf("%d\n", ans);
    return 0;
  }
  