#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005, mod = 998244353;
int n, k, p[MX], a[MX];
ll ft[MX], res;

void update (int i, int k) {
	while (i < MX) {
		(ft[i] += k) %= mod;
		i += i & -i;
	}
}

ll query (int i) {
	ll s = 0;
	while (i) {
		(s += ft[i]) %= mod;
		i -= i & -i;
	}
	return s;
}

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	forn (i, n) cin >> p[i];
	forn (i, n) a[i] = max(0, i - k + 1);

	forn (i, n) {
		res += i - query(p[i]);
		update(p[i], 1);
	}

	res %= mod;

	memset(ft, 0, sizeof(ft));

	ll f = (k - 1) * pot(k, mod - 2) % mod;
	ll inv2 = pot(2, mod - 2);

	forn (i, n) {
		ll x = query(p[i]);
		ll y = query(n) - x;

		(res += pot(f, a[i]) * x % mod * inv2) %= mod;
		(res -= pot(f, a[i]) * y % mod * inv2) %= mod;

		update(p[i], pot(pot(f, mod - 2), a[i]));
	}

	cout << MOD(res, mod) << endl;

	return 0;
}
