#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr long long inf = 3e18;

template<int MOD>
struct mint{
	int n;
	mint():n(0){}
	mint(int x):n(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD){}

	mint &operator+=(const mint &p){
		if((n+=p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator-=(const mint &p){
		if((n+=MOD-p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator*=(const mint &p){
		n=n*p.n%MOD;
		return *this;
	}
	mint &operator/=(const mint &p){
		*this*=p.inverse();
		return *this;
	}
	mint operator-()const{return mint(-n);}
	mint operator+(const mint &p)const{return mint(*this)+=p;}
	mint operator-(const mint &p)const{return mint(*this)-=p;}
	mint operator*(const mint &p)const{return mint(*this)*=p;}
	mint operator/(const mint &p)const{return mint(*this)/=p;}
	mint operator==(const mint &p)const{return n==p.n;}
	mint operator!=(const mint &p)const{return n!=p.n;}

	friend ostream &operator<<(ostream &os,const mint &p){
		return os<<p.n;
	}
	friend istream &operator>>(istream &is,mint &p){
		int x;is>>x;
		p=mint(x);
		return is;
	}
	mint pow(int x)const{
		mint res(1),mul(n);
		while(x>0){
			if(x&1)res*=mul;
			mul*=mul;
			x>>=1;
		}
		return res;
	}
	mint inverse()const{
		return pow(MOD-2);
	}
};
using modint=mint<mod>;

template<class T>
class BIT{
	int N;
	vector<T>bit;
	void add_(int x,T y){
		while(x<=N){
			bit[x]+=y;x+=x&-x;
		}
	}
	T sum_(int x){
		T res=0;
		while(x>0){
			res+=bit[x];x-=x&-x;
		}
		return res;
	}
public:
	int lower_bound(T w){
		if(w<=0)return -1;
		int x=0;
		int k=1;while(k*2<=N)k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&bit[x+k]<w){
				w-=bit[x+k];
				x+=k;
			}
		}
		return x;
	}
	void add(int x,T y){add_(x+1,y);}
	T sum(int l,int r){return sum_(r)-sum_(l);}
	BIT(int x):N(x),bit(x+1){}
};

int N,K,A[200005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>K;
	rep(i,N){cin>>A[i];A[i]--;}

	BIT<modint>bit(N),bit2(N);
	modint ans;
	rep(i,N){
		int j=max(0ll,i+1-K);
		modint k=(modint(K-1)/modint(K)).pow(j);
		ans+=bit.sum(A[i],N)*k/modint(2);
		ans+=bit2.sum(A[i],N)-bit.sum(A[i],N)*k;
		ans+=bit.sum(0,A[i])*k/modint(2);
		bit.add(A[i],modint(1)/k);
		bit2.add(A[i],1);
	}
	cout<<ans<<"\n";
}