#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<map> #define ll long long #define int long long #define INF 0x3f3f3f3f usingnamespace std;
ll rd(){ ll x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') { x = x * 10 + (c - '0'); c = getchar(); }
return x * w; }
constint N = 1e5 + 5;
constint mod = 1e9 + 7; const ll inv2 = (mod + 1) >> 1; int n; ll k, ans; int a[N], b[N]; int pre[N];
map <int, int> mp; bool fl[N];
ll calc(ll a, ll b, ll c){ return (a % mod + b % mod) % mod * c % mod *inv2 % mod; }
signedmain(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); n = rd(), k = rd(); for(int i = 1; i <= n; ++i) { a[i] = rd(); if(mp.count(a[i])) pre[i] = mp[a[i]]; else fl[i] = true; mp[a[i]] = i; }
for(int i = 1; i <= n; ++i) { if(fl[i]) { ans = (ans % mod + ( 1ll * i % mod * 1ll * (n % mod * k % mod - i + 1) % mod) % mod) % mod; ans = (ans % mod + ((n + i - pre[i]) % mod * calc((n % mod * (k - 1) % mod - (i - 1) % mod) % mod, n - i + 1, k - 1) % mod) % mod) % mod; } else { ans = (ans % mod + (i - pre[i]) % mod * calc(((n % mod * k % mod - i + 1) % mod) % mod, n - i + 1, k) % mod) % mod; } }