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>
  template <typename _Tp>
  void read(_Tp &x) {
    char ch(getchar());
    bool f(false);
    while (!isdigit(ch)) f |= ch == 45, ch = getchar();
    x = ch & 15, ch = getchar();
    while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
    if (f) x = -x;
  }
  template <typename _Tp, typename... Args>
  void read(_Tp &t, Args &...args) {
    read(t);
    read(args...);
  }
  const int N = 100005, mod = 1000000007;
  template <typename _Tp1, typename _Tp2>
  inline void add(_Tp1 &a, _Tp2 b) {
    (a += b) >= mod && (a -= mod);
  }
  template <typename _Tp1, typename _Tp2>
  inline void sub(_Tp1 &a, _Tp2 b) {
    (a -= b) < 0 && (a += mod);
  }
  long long ksm(long long a, long long b = mod - 2) {
    long long res = 1;
    while (b) {
      if (b & 1) res = res * a % mod;
      a = a * a % mod, b >>= 1;
    }
    return res;
  }
  long long fac[N], inv[N], ifac[N];
  void init() {
    fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
    for (int i = 2; i < N; ++i)
      fac[i] = fac[i - 1] * i % mod,
      inv[i] = inv[mod % i] * (mod - mod / i) % mod,
      ifac[i] = ifac[i - 1] * inv[i] % mod;
  }
  inline long long C(int n, int m) {
    return n < m || m < 0 ? 0 : fac[n] * ifac[m] % mod * ifac[n - m] % mod;
  }
  int f[N];
  std::map<int, int> mp;
  int cnt[N], pw[N];
  int main() {
    init();
    int n, k;
    read(n, k);
    for (int i = 0; i <= n; ++i) pw[i] = ksm(k - 1, i);
    f[0] = 0;
    for (int i = 0; i < n; ++i)
      f[i + 1] = (1LL * (k - 1) * i % mod * f[i] % mod + 1) * inv[n - i] % mod;
    for (int i = 1; i <= n; ++i) add(f[i], f[i - 1]);
    int a = 0, s = 0;
    for (int i = 1, x; i <= n; ++i) {
      read(x);
      if (x != -1)
        ++mp[x];
      else
        ++a;
    }
    for (auto it : mp) ++cnt[it.second];
    cnt[0] += k - mp.size();
    for (int i = 0; i <= n; ++i)
      if (cnt[i]) {
        int tmp = 0;
        for (int j = 0; j <= a; ++j)
          add(tmp, 1LL * f[i + j] * C(a, j) % mod * pw[a - j] % mod);
        add(s, 1LL * tmp * cnt[i] % mod);
      }
    s = ksm(k, mod - 1 - a) * s % mod;
    printf("%lld\n", 1LL * (f[n] - s + mod) * n % mod);
    return 0;
  }
  