#include<bits/stdc++.h>

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
/*
struct matrix{
    LL a[2][2];
};
int mod=998244353;
matrix operator*(const matrix &a,const matrix &b){
    matrix c;
    for(int i = 0;i<2;i++){
        for(int j = 0;j<2;j++){
            c.a[i][j]=0;
        }
    }
    for(int i = 0;i<2;i++){
        for(int j = 0;j<2;j++)[
            for(int k =0;k<2;k++){
                c.a[i][j]+=a.a[i][k]*b.a[k][j]%mod;
            }
            c.a[i][j]%=mod;
        ]
    }
    return c;
}
matrix f_pow(matrix a,int b){
    matrix res,tmp=a;
    res.a[0][0]=res.a[1][1]=1;
    res.a[0][1]=res.a[1][0]=0;
    while(b){
        if(b&1)res=res*tmp;
        tmp=tmp*tmp;
        b>>=1;
    }
    return res;
}*/
const int mod=998244353;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
LL s[200005];
LL sum[200005];
void add(LL x,LL k,LL *S){
   // printf("%lld\n",x);
    for(int i = x;i<200005;i+=i&-i){
        S[i]+=k;
        S[i]%=mod;
    }
    //return res;
}
LL query(LL x,LL *S){
    LL res=0;
    for(int i = x;i>0;i-=i&-i){
        res+=S[i];
    }
    return res%mod;
}
void solve(){
    int n,k;
    scanf("%d %d",&n,&k);
    LL ans=0;
    LL aa=(k-1)*f_pow(k,mod-2)%mod;
    for(int i = 1;i<=n;i++){
        int x;
        scanf("%d",&x);
        LL q1=query(x-1,s),q2=((query(n,s)-query(x-1,s))%mod+mod)%mod;
        ans+=(q1+q2)*f_pow(aa,max(i-k,0))%mod*((mod+1)/2)%mod;
      //  printf("%lld %lld %lld %lld\n",q1,q2,ans,i-1-query(x,sum));
        ans+=((i-1-query(x,sum)-q2*f_pow(aa,max(i-k,0)))%mod+mod)%mod;
        ans%=mod;
        add(x,1,sum);
        add(x,f_pow(f_pow(aa,max(i-k,0)),mod-2),s);
        //printf("%lld %lld %lld\n",q1,q2,ans);
    }
    printf("%lld\n",ans);
}
int main(){
    int t=1;
    //scanf("%d",&t);
    while(t--){
        solve();
    }
}
/*
1 6 6
2 7 4
3 5 2
4 3 1
5 2 5
6 4 0
7 1 3
*/
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/
