#include <bits/stdc++.h>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

using Mint = modint998244353;

const int maxv = 1000010;

V<Mint> fact(maxv), ifact(maxv), inv(maxv);

void init() {
    fact[0] = 1;
    for (int i = 1; i < maxv; ++i) {
        fact[i] = fact[i - 1] * i;
    }

    ifact[maxv - 1] = fact[maxv - 1].inv();

    for (int i = maxv - 2; i >= 0; --i) {
        ifact[i] = ifact[i + 1] * (i + 1);
    }

    for (int i = 1; i < maxv; ++i) {
        inv[i] = ifact[i] * fact[i - 1];
    }
}

Mint comb(int n, int r) {
    if (n < 0 || r < 0 || r > n) return Mint(0);
    return fact[n] * ifact[r] * ifact[n - r];
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    init();

    int N, K;
    cin >> N >> K;
    V<int> p(N);
    rep(i, N) cin >> p[i], --p[i];

    V<Mint> ik(N + 1);
    ik[0] = 1;
    rep(i, N) { ik[i + 1] = ik[i] * (1 - inv[K]); }

    Mint ans;
    /*
     rep(i, N) {
         rep(j, i) {
             int x = p[j], y = p[i];
             int l = max(0, j - K + 1);
             int r = max(0, i - K + 1);
             debug(j, i, l, r);
             Mint w = ik[r - l];
             ans += w * inv[2];
             if (l < r && x > y) ans += 1 - w;
         }
     }
     cout << ans.val() << endl;*/

    ans = Mint(K * ll(K - 1) / 2) * inv[2];

    fenwick_tree<Mint> t(N + 1);
    fenwick_tree<int> tc(N + 1);

    Mint su;

    rep(i, K) {
        tc.add(p[i], 1);
        su += 1 / ik[0];
        t.add(p[i], 1 / ik[0]);
    }

    for (int i = K; i < N; ++i) {
        int x = i - K + 1;
        int u = tc.sum(p[i], N);
        ans += u;
        ans += ik[x] * inv[2] * su;
        su += 1 / ik[x];
        tc.add(p[i], 1);

        ans -= ik[x] * t.sum(p[i], N);
        /*
                rep(j, i) {
                    int l = max(0, j - K + 1);

                    if (p[j] > p[i]) {
                        ans -= ik[x - l];
                    }
                }*/

        t.add(p[i], 1 / ik[x]);
    }
    cout << ans.val() << endl;

    return 0;
}

Measured memory_bytes: 17996