#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
mt19937_64 rnd(228);
const int mod = 998244353;

int mult(int a, int b) {
    return (1LL * a * b) % mod;
}

int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
struct Fenwick {
    vector<int> f;
    int n;

    Fenwick(int _n) {
        n = _n;
        f.resize(_n + 1);
    }

    void upd(int pos, int v) {
        while (pos <= n) {
            f[pos] = sum(f[pos], v);
            pos = (pos | (pos - 1)) + 1;
        }
    }

    int get(int r) {
        int ans = 0;
        while (r > 0) {
            ans = sum(ans, f[r]);
            r &= (r - 1);
        }
        return ans;
    }

    int get(int l, int r) {
        return sub(get(r), get(l - 1));
    }
};

const int maxN = 2e5 + 10;
int n, k;
int invK[maxN];
int pwK[maxN];
int p[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    int nk = mult(k, pw(k - 1, mod - 2));
    for (int i = 0; i <= n; i++) {
        invK[i] = pw(pw(nk, i), mod - 2);
        pwK[i] = pw(nk, i);
    }
    int ans = mult((k - 1), mult(k - 2, pw(4, mod - 2)));
    Fenwick f_sum(n);
    Fenwick cnt(n);
    for (int i = 1; i <= k - 1; i++) {
        f_sum.upd(p[i], pwK[k]);
        cnt.upd(p[i], +1);
    }
    for (int i = k; i <= n; i++) {
        int cnt_smaller = f_sum.get(p[i] - 1);
        ans = sum(ans, mult((mod + 1) / 2, mult(cnt_smaller, invK[i])));
        int cnt_bigger = f_sum.get(p[i] + 1, n);
        int tot_bigger = cnt.get(p[i] + 1, n);
        ans = sum(ans, sub(tot_bigger, mult(invK[i], mult((mod + 1) / 2, cnt_bigger))));
        f_sum.upd(p[i], pwK[i]);
        cnt.upd(p[i], +1);
    }
    cout << ans;
    return 0;
}