//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 998244353;
const ll INF = 1000000010;
const ll LOG = 20;

int fen[2][N], n, k, a[N], ans, Fac;

int POW(int a, int b){
	int res = 1;
	while (b){
		if (b & 1) res = res * 1ll * a % MOD;
		b >>= 1;
		a = a * 1ll * a % MOD;
	}
	return res;
}

inline int add(int a, int b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

inline int mul(int a, int b){
	return a * 1ll * b % MOD;
}

inline int minu(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

inline void Add(int ind, int id, int x){
	for (; id < N; id += id & (-id)) fen[ind][id] = (fen[ind][id] + x) % MOD;
	return;
}

inline int get(int ind, int id){
	int res = 0;
	for (; id > 0; id -= id & (-id)) res = (res + fen[ind][id]) % MOD;
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	Fac = 1;
//	cout << POW(2, 4) << '\n';
	for (int i = 3; i <= k; i++) Fac = Fac * 1ll * i % MOD;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int tot = mul(POW(k, n - k), Fac * 2 % MOD);
//	cout << tot << '\n';
	for (int i = 1; i <= n; i++){
		int x = max(k, i);
		int res = get(0, a[i]);
//		cout << res << '\n';
		ans = add(ans, mul(res,mul(mul(POW(k - 1, x), POW(k, n - x)), Fac)));
		res = minu(get(0, n), get(0, a[i]));
//		cout << ans << '\n';
		int ted = minu(get(1, n), get(1, a[i]));
		ted = ted * 1ll * tot % MOD;
		ted = minu(ted, mul(res,mul(mul(POW(k - 1, x), POW(k, n - x)), Fac)));
		ans = add(ans, ted);
//		cout << ans << '\n';
		Add(1, a[i], 1);
		Add(0, a[i], mul(POW(k, x - k), POW(k - 1, MOD - 1 - x)));
	}
//	cout << ans << '\n';
	cout << mul(ans, POW(tot, MOD - 2));
	return 0;
}

/*
4 2
4 2 1 3
*/
