#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
const int mod=998244353;
int n,m,i,j,a[200005],s[200005],s2[200005],ans;
int fac[200005],inv[200005],fi[200005],pw[200005],ipw[200005];
vector<int> v[200005];
void add(int x,int y)
{
	while(x){
		inc(s[x],y)
		s2[x]++;
		x-=(x&-x);
	}
}
int query(int x)
{
	int ss=0;
	while(x<=n){
		inc(ss,s[x])
		x+=(x&-x);
	}
	return ss;
}
int query2(int x)
{
	int ss=0;
	while(x<=n){
		ss+=s2[x];
		x+=(x&-x);
	}
	return ss;
}
int main()
{
	fac_init(200002)
	read(n);read(m);
	pw[0]=ipw[0]=1;
	pw[1]=1ll*(m-1)*inv[m]%mod;
	ipw[1]=1ll*m*inv[m-1]%mod;
	fz(i,2,n){
		pw[i]=1ll*pw[i-1]*pw[1]%mod;
		ipw[i]=1ll*ipw[i-1]*ipw[1]%mod;
	}
	fz1(i,n){
		read(a[i]); 
		v[max(1,i-m+1)].push_back(a[i]);
	}
	int s=0,c=0;
	ans=1ll*n*(n-1)/2%mod;
	fz1(i,n-m+1){
		ff(v[i],it){
			ans=(ans+(mod-i+1))%mod;
			ans=(ans+2ll*query2(*it))%mod;
			ans=(ans+2ll*(mod-pw[i])*query(*it))%mod;
		}
		ff(v[i],it){
			c++;
			inc(s,ipw[i])
			add(*it,ipw[i]);
		}
	}
	cout<<1ll*ans*inv[2]%mod<<endl;
	return 0;
}