#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;
}
### Prompt

Construct a cpp code solution to the problem outlined:

Given are a permutation p_1, p_2, \dots, p_N of (1, 2, ..., N) and an integer K. Maroon performs the following operation for i = 1, 2, \dots, N - K + 1 in this order:

* Shuffle p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly.



Find the expected value of the inversion number of the sequence after all the operations are performed, and print it modulo 998244353.

More specifically, from the constraints of this problem, it can be proved that the expected value is always a rational number, which can be represented as an irreducible fraction \frac{P}{Q}, and that the integer R that satisfies R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 is uniquely determined. Print this R.

Here, the inversion number of a sequence a_1, a_2, \dots, a_N is defined to be the number of ordered pairs (i, j) that satisfy i < j, a_i > a_j.

Constraints

* 2 \leq N \leq 200,000
* 2 \leq K \leq N
* (p_1, p_2, \dots, p_N) is a permutation of (1, 2, \dots, N).
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N K
p_1 p_2 ... p_N


Output

Print the expected value modulo 998244353.

Examples

Input

3 2
1 2 3


Output

1


Input

10 3
1 8 4 9 2 3 7 10 5 6


Output

164091855

### Response

```cpp
#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;
}
```