#include <bits/stdc++.h>
using namespace std;

typedef long long int   ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll N    = 2e5 + 10;
const ll MOD  = 998244353;
const ll INF  = 1e18;

ll n, k, A[N], fen[2][N], dp[N], F[N], ans;

void Add(int z, int i, ll val) {
	for (i += 2; i < N; i += i & (-i))
		fen[z][i] = (fen[z][i] + val) % MOD;
}

ll Get(int z, int r) {
	ll res = 0;
	for (r += 2; r > 0; r -= r & (-r))
		res = (res + fen[z][r]) % MOD;
	return res;
}

ll Get(int z, int l, int r) {
	return (Get(z, r) - Get(z, l - 1) + MOD) % MOD;
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
    	cin >> A[i];
    	F[i] = min(n, max(i - k + 1, 0LL) + k);
    }
    dp[0] = pw(2, MOD - 2, MOD);
    ll kinv = pw(k, MOD - 2, MOD);
    for (int i = 1; i <= n; i++) {
    	dp[i] = kinv * (1 + (k - 2) * dp[i - 1] % MOD) % MOD;
    }
    ll w = (k - 1) * pw(k, MOD - 2, MOD) % MOD;
    ll winv = k * pw(k - 1, MOD - 2, MOD) % MOD;
    for (int i = 0; i < n; i++) {
    	ll gt = i - Get(0, A[i]);
    	Add(0, A[i], +1);
    	ll g = dp[n - F[i]] * pw(w, F[i], MOD) % MOD;
    	ans += Get(1, 0, A[i]) * g % MOD; 
    	ans += (gt + MOD - Get(1, A[i], n) * g % MOD) % MOD;
    	ans %= MOD;
    	Add(1, A[i], pw(winv, F[i], MOD));
    }
    cout << ans << endl;
    return 0;
}
