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

const int P = 998244353; int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a = a * a % P; b >>= 1;} return tms;}
int pot[200003] , N , K;
#define lowbit(x) ((x) & -(x))
struct bit{
	int arr[200003];
	void add(int x , int v){while(x <= N){arr[x] = (arr[x] + v) % P; x += lowbit(x);}}
	int qry(int x){int sum = 0; while(x){sum = (sum + arr[x]) % P; x -= lowbit(x);} return sum;}
}sum1 , sum2;

int main(){
	int ans = 0; cin >> N >> K; for(int i = 1 ; i <= N ; ++i) cin >> pot[i];
	int lft1 = 1ll * (K - 1) * poww(K , P - 2) % P , lft2 = 1ll * (K - 2) * poww(K , P - 2) % P;
	for(int i = 1 ; i <= N ; ++i){
		int p1 = sum1.qry(pot[i]) , p2 = i - 1 - sum1.qry(pot[i]) , r2 = max(i - K , 0);
		int q1 = sum2.qry(pot[i]) , q2 = (sum2.qry(N) - sum2.qry(pot[i]) + P) % P;
		sum1.add(pot[i] , 1); sum2.add(pot[i] , poww(lft1 , P - 1 - r2)); ans = (ans + p2 - 1ll * q2 * poww(lft1 , r2)) % P;

		int prob = 1ll * (q1 + q2) * poww(lft1 , r2) % P;
		ans = (ans + 1ll * prob * (P + 1 - lft1) % P * (P + 1 - poww(lft2 , N - K - r2)) % P * poww(P + 1 - lft2 , P - 2)) % P;
		ans = (ans + 1ll * prob * poww(lft2 , N - K - r2) % P * (P + 1) / 2) % P;
	}
	cout << ans; return 0;
}