#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

struct SegTree
{
    vector<int> t;
    int n;

    int sum(int v, int tl, int tr, int l, int r) {
        if (l > r)
            return 0;
        if (l == tl && r == tr) {
            return t[v];
        }
        int tm = (tl + tr) / 2;
        return add(sum(v*2, tl, tm, l, min(r, tm)), sum(v*2+1, tm+1, tr, max(l, tm+1), r));
    }

    void update(int v, int tl, int tr, int pos, int new_val) {
        if (tl == tr) {
            t[v] = new_val;
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                update(v*2, tl, tm, pos, new_val);
            else
                update(v*2+1, tm+1, tr, pos, new_val);
            t[v] = add(t[v*2], t[v*2+1]);
        }
    }

    SegTree(int N)
    {
        n = N;
        t.resize(1<<19);
    }

    int sum(int l, int r)
    {
        return sum(1, 0, n-1, l, r);
    }

    void upd(int pos, int new_val)
    {
        update(1, 0, n-1, pos, new_val);
    }
};

int P;

vector<int> deg;
vector<int> invdeg;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n, k;
    cin>>n>>k;
    vector<int> a(n);
    for (int i = 0; i<n; i++) {cin>>a[i]; a[i]--;}

    vector<int> pos(n);
    for (int i = 0; i<n; i++) pos[a[i]] = i;

    P = mul(k-1, inv(k));
    deg.resize(n);
    deg[0] = 1;
    for (int i = 1; i<n; i++) deg[i] = mul(deg[i-1], P);
    invdeg.resize(n);
    invdeg[0] = 1;
    for (int i = 1; i<n; i++) invdeg[i] = mul(invdeg[i-1], inv(P));

    ll res = 0;


    reverse(pos.begin(), pos.end());

    SegTree decr(n);
    for (auto x: pos)
    {
        int sum = decr.sum(x+1, n-1);
        res = add(res, mul(mul(sum, invdeg[max(x, k-1)]), inv(2)));
        decr.upd(x, deg[max(x, k-1)]);
    }

    //cout<<res<<endl;

    reverse(pos.begin(), pos.end());
    SegTree incr(n);
    SegTree cnt(n);

    for (auto x: pos)
    {
        int L = max(x+1, k);
        int sum = incr.sum(x+1, n-1);
        int tot = cnt.sum(x+1, n-1);
        res = add(res, tot);
        res = sub(res, mul(mul(sum, invdeg[max(x, k-1)]), inv(2)));
        incr.upd(x, deg[max(x, k-1)]);
        cnt.upd(x, 1);
    }

    cout<<res;


}



Measured memory_bytes: 12452