#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double


ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a, ll mod){
    return modpower(a, mod-2, mod);
}

class BIT{
    public:
    int size;
    vector<ll> tree;
    
    void set(int n){
        size = n;
        tree = vector<ll>(n+1, 0);
        return;
    }
    
    void add(int n, ll a) {
        int x = n;
        while (x <= size){
            tree[x] += a;
            x += (x & -x);
        }
        return;
    }
    
    ll getsum(int n) {
        int x = n;
        ll sum = 0;
        while (x > 0) {
            sum += tree[x];
            x -= (x & -x);
        }
        return sum;
    }
    
};

int main() {
    ll N, K;
    cin >> N >> K;
    ll mod = 998244353;
    vector<ll> p(N+1, 0);
    for (int i = 1; i <= N; i++) cin >> p[i];
    
    vector<ll> pow(N+1, 1);
    pow[1] = K*modinv(K-1, mod) % mod;
    for (int i = 2; i <= N; i++) {
        pow[i] = pow[i-1]*pow[1]%mod;
    }
    
    ll inv2 = modinv(2, mod);
    
    BIT bit1, bit2;
    bit1.set(N+1);
    bit2.set(N+1);
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        if (i <= K) {
            ans += (i-1)*inv2%mod;
            bit1.add(p[i], 1);
            bit2.add(p[i], 1);
            continue;
        }
        
        ans += bit2.getsum(p[i]) % mod * modinv(pow[i-K], mod) % mod * inv2 % mod;
        
        ans += i-1-bit1.getsum(p[i]);
        ans += mod-(bit2.getsum(N)-bit2.getsum(p[i])) % mod * modinv(pow[i-K], mod) % mod * inv2 % mod;
        ans %= mod;
        
        bit1.add(p[i], 1);
        bit2.add(p[i], pow[i-K]);
    }
    
    ans %= mod;
    cout << ans << endl;
    return 0;
}
