
using namespace std;

#define visual

#ifdef visual
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>
#endif
#ifndef visual
#include <bits/stdc++.h>
#endif

typedef long long ll;


template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }

    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const ModInt& p) {
        return os << p.x;
    }

    friend istream& operator>>(istream& is, ModInt& a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt< 998244353 >;



struct segt {

	struct node {
		mint t, mx, lazyby, lazyto, num, ex, lazytimes;
		ll length, s, e;
		bool set;
		node* l;
		node* r;
	};

	node* rt;

	void build(int i, int j, node* v) {
		v->mx = v->t = v->lazyby = v->lazyto = 0;
		v->length = j - i + 1;
		v->num = 0;
		v->lazytimes = 1;
		v->ex = 0;
		v->s = i;
		v->e = j;
		if (i == j) return;
		v->l = new node();
		v->r = new node();
		build(i, (i + j) / 2, v->l);
		build((i + j) / 2 + 1, j, v->r);
	}

	segt() {}
	segt(int n) {
		rt = new node();
		build(0, n - 1, rt);
	}

	inline void prop(node* v) {
		if (v->l != nullptr) {

			v->l->lazytimes *= v->lazytimes;
			v->r->lazytimes *= v->lazytimes;

		}
		v->ex *= v->lazytimes;
		v->lazytimes = 1;
	}

	void update(int i, int j, mint val, bool prod, node* v) {
		if (j < v->s || v->e < i) return;
		if (i <= v->s && v->e <= j) {
			prop(v);
			if (prod) v->lazytimes *= val;
			else {
				v->num = 1;
				v->ex = val;
			}
			prop(v);
			return;
		}
		prop(v);
		update(i, j, val, prod, v->l);
		update(i, j, val, prod, v->r);
		prop(v->l);
		prop(v->r);
		v->num = v->l->num + v->r->num;
		v->ex = v->l->ex + v->r->ex;

	}

	void updateprod(int i, int j, mint val) { update(i, j, val, true, rt); }
	void updateonce(int i, int j, mint val) { update(i, j, val, false, rt); }


	mint query(int i, int j, bool nums, node* v) {
		if (j < v->s || v->e < i) {

			return 0;
		}
		prop(v);
		if (i <= v->s && v->e <= j) {
			if (nums) return v->num;
			return v->ex;
		}
		mint l = query(i, j, nums, v->l);
		mint r = query(i, j, nums, v->r);
		return l + r;
	}

	mint querynum(int i, int j) { return query(i, j, true, rt); }
	mint queryex(int i, int j) { return query(i, j, false, rt); }
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	segt s(n+1);

	mint ans;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		
		if (i >= k) {
			s.updateprod(0, n, ((mint)(k-1))/k);
		}
		ans += s.queryex(1, x - 1);
		ans += s.querynum(x + 1, n) - s.queryex(x + 1, n);
		s.updateonce(x, x, ((mint)1)/2);
	}
	cout << ans << endl;




}

### Prompt

Please formulate a cpp solution to the following problem:

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

using namespace std;

#define visual

#ifdef visual
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>
#endif
#ifndef visual
#include <bits/stdc++.h>
#endif

typedef long long ll;


template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }

    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const ModInt& p) {
        return os << p.x;
    }

    friend istream& operator>>(istream& is, ModInt& a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt< 998244353 >;



struct segt {

	struct node {
		mint t, mx, lazyby, lazyto, num, ex, lazytimes;
		ll length, s, e;
		bool set;
		node* l;
		node* r;
	};

	node* rt;

	void build(int i, int j, node* v) {
		v->mx = v->t = v->lazyby = v->lazyto = 0;
		v->length = j - i + 1;
		v->num = 0;
		v->lazytimes = 1;
		v->ex = 0;
		v->s = i;
		v->e = j;
		if (i == j) return;
		v->l = new node();
		v->r = new node();
		build(i, (i + j) / 2, v->l);
		build((i + j) / 2 + 1, j, v->r);
	}

	segt() {}
	segt(int n) {
		rt = new node();
		build(0, n - 1, rt);
	}

	inline void prop(node* v) {
		if (v->l != nullptr) {

			v->l->lazytimes *= v->lazytimes;
			v->r->lazytimes *= v->lazytimes;

		}
		v->ex *= v->lazytimes;
		v->lazytimes = 1;
	}

	void update(int i, int j, mint val, bool prod, node* v) {
		if (j < v->s || v->e < i) return;
		if (i <= v->s && v->e <= j) {
			prop(v);
			if (prod) v->lazytimes *= val;
			else {
				v->num = 1;
				v->ex = val;
			}
			prop(v);
			return;
		}
		prop(v);
		update(i, j, val, prod, v->l);
		update(i, j, val, prod, v->r);
		prop(v->l);
		prop(v->r);
		v->num = v->l->num + v->r->num;
		v->ex = v->l->ex + v->r->ex;

	}

	void updateprod(int i, int j, mint val) { update(i, j, val, true, rt); }
	void updateonce(int i, int j, mint val) { update(i, j, val, false, rt); }


	mint query(int i, int j, bool nums, node* v) {
		if (j < v->s || v->e < i) {

			return 0;
		}
		prop(v);
		if (i <= v->s && v->e <= j) {
			if (nums) return v->num;
			return v->ex;
		}
		mint l = query(i, j, nums, v->l);
		mint r = query(i, j, nums, v->r);
		return l + r;
	}

	mint querynum(int i, int j) { return query(i, j, true, rt); }
	mint queryex(int i, int j) { return query(i, j, false, rt); }
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	segt s(n+1);

	mint ans;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		
		if (i >= k) {
			s.updateprod(0, n, ((mint)(k-1))/k);
		}
		ans += s.queryex(1, x - 1);
		ans += s.querynum(x + 1, n) - s.queryex(x + 1, n);
		s.updateonce(x, x, ((mint)1)/2);
	}
	cout << ans << endl;




}

```