#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

using mint = atcoder::modint998244353;
struct S {
    mint val;
    int sz;
};
struct F {
    mint a, b;
};
S e() {
    return {mint(0), 0};
}

S mapping(F f, S x) {
    x.val = x.val * f.a + f.b * x.sz;
    return x;
}

F composition(F l, F r) {
    return {r.a * l.a, r.b * l.a + l.b};
}

F id() {
    return {1, 0};
}

S op(S a, S b) {
    return {a.val + b.val, a.sz + b.sz};
}
ll N, K;
ll p[201000];
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree() {
        int sz = 201000;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = 0;
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};

const ll mod = 998244353;
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]--;
    }
    vector<S> a(N);
    for(int i = 0; i < N; i++) {
        a[i].val = mint(1);
        a[i].sz = 1;
    }
    ll Kinv = beki(K, mod - 2);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    SegmentTree segnum;
    for(int i = 0; i < N; i++) {
        segnum.update(i, 1);
    }
    for(int i = 0; i < K; i++) {
        seg.apply(p[i], {0, Kinv});
        segnum.update(p[i], 0);
    }
    ll one = 0;
    ll zero = 0;
    for(int i = K; i < N; i++) {
        /*
        cerr << "-----" << i << "------" << endl;
        for(int i = 0; i < N; i++) {
            cerr << seg.prod(i, i + 1).val.val() << " ";
        }
        cerr << endl;
        */
        ll tmpone = seg.prod(p[i], N).val.val();
        tmpone += mod - segnum.getsum(p[i], N);
        one += tmpone;
        ll tmpzero = seg.prod(0, p[i]).val.val();
        tmpzero += mod - segnum.getsum(0, p[i]);
        tmpzero %= mod;
        tmpone %= mod;
        zero += tmpzero;
        //cerr << i << " " << tmpzero << " " << tmpone << endl;
        one %= mod;
        zero %= mod;
        seg.apply(0, N, {(K - 1) * Kinv % mod, Kinv});
        seg.apply(p[i], {0, Kinv});
        segnum.update(p[i], 0);
    }
    ll total = N * (N - 1) / 2;
    ll rest = total - zero - one + 2 * mod;
    rest %= mod;
    //cerr << zero << " " << one << " " << rest << endl; 
    ll ans = one + rest * beki(2, mod - 2);
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14596