#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

using mint = modint998244353;

struct S{
    ll num;
    mint psum;
};
S e(){ return S{0, 0}; }
S op(S x, S y){ return S{x.num + y.num, x.psum + y.psum}; }

int main(){
    ll n, k;
    cin >> n >> k;

    vector<ll> p(n);
    REP(i, n){
        cin >> p.at(i);
        p.at(i)--;
    }

    const mint q = mint(k - 1) / mint(k);
    const mint qinv = q.inv();

    // cerr << "q=" << q.val() << ", qinv=" << qinv.val() << endl;

    segtree<S, op, e> st(n);

    mint ans = 0;

    REP(i, n){
        const ll pi = p.at(i);
        const ll fi = max(i - k + 1, 0LL);

        const auto sd = st.prod(0, pi);
        mint tmp1 = q.pow(fi) * sd.psum / 2;

        const auto su = st.prod(pi + 1, n);
        mint tmp2 = su.num - q.pow(fi) * su.psum / 2;

        mint tmp = tmp1 + tmp2;

        // cerr << "i=" << i << ", tmp=" << tmp.val() << ", tmp1=" << tmp1.val() << ", tmp2=" << tmp2.val() << endl;
        ans += tmp;

        st.set(pi, S{1, qinv.pow(fi)});
    }

    cout << ans.val() << endl;

    return 0;
}
