#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define bits(x) bitset<22>(x)
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
const ll mod = 998244353;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 2e5+10;
///===========================================  template  =======================================================

inline ll add(ll x, ll y){
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

inline ll sub(ll x, ll y){
    x -= y;
    if(x < 0) x += mod;
    return x;
}

ll modexpo(ll x, ll n, ll m = mod){
	x %= m;
	ll ret = 1;
    while(n){
        if(n & 1LL) ret = (ret*x) % m;
        x = (x*x) % m;
        n >>= 1;
    }
    return ret;
}

int N;	//N is size
int bit1[nmax];
ll bit2[nmax];

pair<int, ll> prefix(int i)
{
    pair<int, ll> ret = {0, 0ll};	//identity
    while(i >= 1) {
        ret.first += bit1[i];
        ret.second = add(ret.second, bit2[i]);
        i -= i&-i;
    }
    return ret;
}

void update(int i, ll x)
{
    while(i<=N && i) {
        bit1[i] += 1;
        bit2[i] = add(bit2[i], x);
        i += i&-i;
    }
}

pair<int, ll> query(int l, int r){
    if(l > r) return {0, 0ll};

    pair<int, ll> ret;
    ret = prefix(r);
    if(l != 1){
        auto tmp = prefix(l-1);
        ret.first -= tmp.first;
        ret.second = sub(ret.second, tmp.second);
    }
    return ret;
}

int main(){
    FASTIO;

    int n;
    ll k;
    cin>>n>>k;
    N = n;
    vector<int> v(n);

    ll inv2 = (mod+1)/2;

    for(int i = 0; i<n; i++){
        cin>>v[i];
    }

    ll ans = k*(k-1) % mod;
    ans = ans * inv2 % mod;
    ans = ans * inv2 % mod;

//    debug(), dbg(ans*4%mod);

    ll prob = (k-1) * modexpo(k, mod-2) % mod;

//    debug(), dbg(prob*2%mod);

    for(int i = n-1; i>=0; i--){

        ll invP = modexpo(prob, mod-1-max(i-(k-1), 0ll));

//        debug(), dbg(invP);

        auto q = query(v[i], n);

        ans += (q.second * invP) % mod * inv2;
        ans %= mod;

        q = query(1, v[i]);

        ans += q.first - q.second * invP % mod * inv2;
        ans %= mod;
        if(ans < 0) ans += mod;

//        debug(), dbg(ans*4%mod);

        if(i >= k){
            ll p = modexpo(prob, i-(k-1));
            update(v[i], p);
        }
    }


    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6416