#include <bits/stdc++.h>
using namespace std;

template<int MAX>
struct Combination {
    vector<long long> _inv, _fac, _ifac;
    const long long MOD;
    Combination(long long mod) : _inv(MAX+1), _fac(MAX+1), _ifac(MAX+1), MOD(mod) { init(); }
    inline void init() { init_inv(), init_fac(); }

    inline void init_inv() {
        _inv[0] = 0;
        for (int i = 1; i <= MAX; i++) {
            if (i == 1) _inv[i] = 1;
            else {
                _inv[i] = (MOD - (MOD / i) * _inv[MOD % i]) % MOD;
                if (_inv[i] < 0) _inv[i] += MOD;
            }
        }
    }
    inline void init_fac() {
        _fac[0] = _ifac[0] = 1;
        for (int i = 1; i <= MAX; i++) {
            _fac[i] = _fac[i-1] * i % MOD;
            _ifac[i] = _ifac[i-1] * _inv[i] % MOD;
        }
    }

    inline long long modpow(long long n, long long r) {
        n %= MOD, r %= (MOD-1);
        if (!n) return 0;
        long long ret = 1; long long tmp = n;
        while (r != 0) {
            if (r % 2) ret *= tmp;
            tmp *= tmp; tmp %= MOD; ret %= MOD;
            r /= 2;
        }
        return ret;
    }
    inline long long invb(int i) const { return (i <= MAX) ? _inv[i] : this->modpow(i, MOD-2); }
    inline long long inv(int i) const { return _inv[i]; }
    inline long long fac(int i) const { return _fac[i]; }
    inline long long ifac(int i) const { return _ifac[i]; }

    long long operator()(int n, int r) const {
        if (n < r) return 0;
        return fac(n) * ifac(r) % MOD * ifac(n-r) % MOD;
    }
};

constexpr long long mod = 998244353;

// zero-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] = (bit[x]+w) % mod;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret = (ret + bit[x]) % mod;
        return ret;
    }
    // sum [a, b)
    T sum(int a, int b) { return (sum(b) - sum(a) + mod) % mod; }
};

long long invsum(vector<int> v, int n){
    vector<pair<int, int>> v_sort;
    for (int i = 0; i < n; i++) {
        v_sort.push_back(make_pair(v[i]-1, i));
    }
    sort(v_sort.begin(), v_sort.end());
    for (int i = 0; i < n; i++) {
        v[v_sort[i].second] = i;
    }
    Fenwick<long long> b(n);
    long long num = 0;
    for (int i = 0; i < n; i++) {
        num += b.sum(n) - b.sum(v[i]);
        b.add(v[i], 1);
    }
    return num;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Combination<500000> C(mod);
    long long N, K; cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++) cin >> V[i];
    // cout << invsum(V, N) << " " << invsum(V, K) << "\n";
    long long Rw = (K - 1) * C.inv(K) % mod;
    long long inv = K * C.inv(K - 1) % mod;
    Fenwick<long long> F(N+1);
    long long Cur = 1, CurInv = 1;
    long long Ans = 0;
    for (int i = 0; i < N; i++) {
        if (i >= K) Cur = Cur * Rw % mod, CurInv = CurInv * inv % mod;
        Ans += F.sum(V[i]) * Cur % mod;
        Ans -= F.sum(V[i], N + 1) * Cur % mod;
        Ans = (Ans % mod + mod) % mod;
        assert(Ans >= 0);
        // cout << F.sum(V[i]) * Cur % mod << " " << F.sum(V[i + K - 1], N + 1) * Cur % mod << "\n";
        F.add(V[i], CurInv);
        // cout << i << ": " << Ans << " " << Cur << " " << CurInv << "\n";
    }
    Ans = Ans * C.inv(2) % mod;
    Ans += invsum(V, N);
    cout << Ans % mod << "\n";
    return 0;
}

Measured memory_bytes: 21232