#include <vector>
#include <iostream>
using namespace std;

const int M = 998244353;

long long modinv(long long a, long long m) {
    long long x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        long long u = x / y;
        long long x0 = y; y = x - y * u; x = x0;
        long long r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

int main() {
    int n, k; cin >> n >> k;
    int p[n]; for (int i = 0; i < n; i++) cin >> p[i];
    vector<long long> ft(n+1, 0);
    long long ans = 0;
    long long b = (long long)(k - 1) * modinv(k, M) % M;
    long long total = 0;
    for (int i = 0; i < n; i++) {
        long long sum = 0;
        for (int x = p[i]; x > 0; x -= x&-x) sum += ft[x];
        ans += (2 * sum - total) % M * modexp(b, max(i, k-1), M) % M;
        long long add = modexp(b, M - max(i, k-1) - 1, M) * ((M + 1) / 2) % M;
        // cerr << "add " << i << " " << add << endl;
        for (int x = p[i]; x <= n; x += x&-x) ft[x] += add;
        total += add;
        // for (int i = 0; i < n; i++) cerr << ft[i+1] << ' ' ; cerr << endl;
        // cerr << "total = " << total << endl;
    }
    fill(ft.begin(), ft.end(), 0);
    for (int i = 0; i < n; i++) {
        int s = 0;
        for (int x = p[i]; x <= n; x += x&-x) s += ft[x];
        for (int x = p[i]; x > 0; x -= x&-x) ft[x]++;
        ans += s;
    }
    cout << (ans % M + M) % M << endl;
}
