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>
  #pragma GCC optimize(2, 3, "Ofast")
  using namespace std;
  template <typename T1, typename T2>
  void ckmin(T1 &a, T2 b) {
    if (a > b) a = b;
  }
  template <typename T1, typename T2>
  void ckmax(T1 &a, T2 b) {
    if (a < b) a = b;
  }
  int read() {
    int x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
    return f ? -x : x;
  }
  template <typename T>
  void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
  }
  template <typename T>
  void print(T x, char let) {
    print(x), putchar(let);
  }
  const int N = 100005;
  const int mod = 1e9 + 7;
  inline int qpow(int a, int b = mod - 2) {
    int res = 1;
    while (b) {
      if (b & 1) res = 1ll * res * a % mod;
      a = 1ll * a * a % mod;
      b >>= 1;
    }
    return res;
  }
  int fac[N], ifac[N];
  inline void init(int n) {
    fac[0] = ifac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
    ifac[n] = qpow(fac[n]);
    for (int i = n; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % mod;
  }
  inline int C(int n, int m) {
    return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
  }
  map<int, int> cnt;
  int f[N], zyk;
  int a[N], buc[N], pw[N], n, k;
  inline int gao(int x) {
    int res = 0;
    for (int i = 0; i <= zyk; i++) {
      int coef = 1ll * f[x + i] * C(zyk, i) % mod * pw[zyk - i] % mod;
      res = (res + coef) % mod;
    }
    return res;
  }
  int main() {
    init(N - 5);
    n = read(), k = read();
    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
      pw[i] = 1ll * pw[i - 1] * (k - 1) % mod;
      a[i] = read();
      if (a[i] == -1)
        zyk++;
      else
        cnt[a[i]]++;
    }
    f[0] = 0, f[1] = 0;
    for (int a = 1; a <= n - 1; a++) {
      f[a + 1] = 1ll *
                 (1ll * (k - 1) * a % mod * f[a - 1] +
                  1ll * (2ll * a - 1ll * a * k % mod - n) * f[a] + 1ll * a * k) %
                 mod * qpow(a - n) % mod;
      if (f[a + 1] < 0) f[a + 1] += mod;
    }
    int qwq = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] != -1 && cnt[a[i]]) {
        buc[cnt[a[i]]]++;
        cnt[a[i]] = 0;
        qwq++;
      }
    }
    buc[0] += k - qwq;
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (buc[i]) {
        ans = (ans + 1ll * buc[i] * gao(i)) % mod;
      }
    }
    ans = 1ll * ans * qpow(qpow(k, zyk)) % mod;
    print((ans + mod - f[n]) % mod, '\n');
    return 0;
  }
  