import sys from itertools import permutations def solve(): def factoradic(n, seq): def add(idx, v): while idx <= n: fenwick[idx] += v idx += idx & -idx return def read(idx): ret = 0 while idx > 0: ret += fenwick[idx] idx &= idx - 1 return ret fenwick = [0] * (n + 1) for i in range(2, n + 1): add(i, 1) ret = [1] * n for i, c in enumerate(seq): ret[i] = read(c + 1) add(c + 1, -1) return ret def sum_inv_all(n): return (n * (n - 1) // 2) % mod * ((mod + 1) // 2) % mod * facts[n] % mod def sum_inv(A): n = len(A) block = 0 ret = 0 isum = 0 for i in range(n - 1, 0, -1): d = A[i] s = i * (i + 1) // 2 % mod t = d * (d - 1) // 2 % mod u = s * block + t + d * isum ret = (ret + u % mod * facts[i]) % mod isum += d block = (block * (i + 1) + d) % mod return ret def update(vals, K): n = len(vals) for i in range(1, n): K, vals[i] = divmod(vals[i] + K, i + 1) ret = 0 if K > 0: ret = K % mod * sum_inv_all(n) % mod return ret F = 100010 mod = 10 ** 9 + 7 facts = [1] * F for i in range(1, F): facts[i] = facts[i - 1] * i % mod input = sys.stdin.readline while 1: try: N, K = map(int, input().split()) except: break A = [c - 1 for c in map(int, input().split())] vals = factoradic(N, A)[::-1] ans = -sum_inv(vals) ans += update(vals, K) ans += sum_inv(vals) print(ans % mod) solve()