import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 N, B, *S = map(int, read().split()) counter = [0] * N for x in S: counter[x] += 1 powB = [1] * N for n in range(1, N): powB[n] = powB[n-1] * B % MOD used = 0 f = 1 df = 0 for n in counter[::-1]: if not n: continue total = 1 stay = 1 for i in range(1, n+1): total *= used+i stay *= used+i-1 total %= MOD stay %= MOD a = stay b = total - stay # a + bx をかける g = a + b * B dg = b f, df = f*g, f*dg+df*g f %= MOD df %= MOD used += n print(df * B % MOD)