//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
// #define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 998244353;
const int inf = 1e9 + 7;
const int N = 2e5 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int inv[N], ifac[N], fac[N];

int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
int sub(int x, int y) { return x-y >= 0 ? x-y : x-y+mod; }
int mul(int x, int y) { return x * 1ll * y % mod; }
template<class T, class... O> int add(T x, O... y) { return add(x, add(y...)); }
template<class T, class... O> int mul(T x, O... y) { return mul(x, mul(y...)); }
int norm(int x) { return x >= 0 ? (x < mod ? x : x-mod) : x+mod; }
int pw(int x, int y) {
  int r = 1;
  for (; y; x = mul(x, x), y /= 2)
    if (y & 1)
      r = mul(r, x);
  return r;
}
int inverse(int x) { return pw(x, mod-2); }
int ncr(int n, int k) {
  if (n < k || k < 0) return 0;
  if (n < N) return mul(fac[n], ifac[n-k], ifac[k]);
  int r = 1;
  for (int i = 1; i <= k; i++)
    r = mul(r, n-i+1, inv[i]);
  return r;
}

void precomputeInverse(int n) {
  inv[1] = ifac[0] = ifac[1] = fac[0] = fac[1] = 1;
  for (int i = 2; i < n; i++) {
    inv[i] = mod - mul(mod / i, inv[mod % i]);
    fac[i] = mul(fac[i-1], i);
    ifac[i] = mul(ifac[i-1], inv[i]);
  }
}

struct mat : array<int,4> {
  mat() {}
  mat(int i, int j, int k, int l) { (*this)[0] = i, (*this)[1] = j, (*this)[2] = k, (*this)[3] = l; }
  mat operator+=(mat x) {
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        (*this)[2*i+j] = add((*this)[2*i+j], x[2*i+j]);
    return *this;
  }
  mat operator*=(mat x) {
    mat r;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        r[2*i+j] = add(mul((*this)[2*i+0], x[2*0+j]), mul((*this)[2*i+1], x[2*1+j]));
    *this = r;
    return *this;
  }
  mat& operator=(mat x) {
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        (*this)[2*i+j] = x[2*i+j];
    return *this;
  }
  friend mat operator+(mat x, mat y) { return x += y; }
  friend mat operator*(mat x, mat y) { return x *= y; }
} pref[2][2][N], ipref[2][2][N], suf[N], pre[N], lo[N][2], hi[N][2];
pair<mat,mat> seg[4*N];

string to_string(const mat& x) { string ret = ""; for (int i = 0; i < 4; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }

mat imat(mat x) {
  return mat(inverse(x[2*0+0]),0,mul(mod-1,x[2*1+0],inverse(x[2*0+0]),inverse(x[2*1+1])),inverse(x[2*1+1]));
}

void build(int l, int r, int k) {
  seg[k].st = mat(0,0,0,0);
  seg[k].nd = mat(0,0,0,0);
  if (l == r) return;
  int m = (l+r) / 2;
  build(l, m, k*2); build(m+1, r, k*2+1);
}

void upd(int l, int r, int k, int x) {
  if (l == r) {
    seg[k] = make_pair(lo[x][1], hi[x][0]);
    return;
  }
  int m = (l+r) / 2;
  if (x <= m) upd(l, m, k*2, x);
  else upd(m+1, r, k*2+1, x);
  seg[k].st = seg[k*2].st + seg[k*2+1].st;
  seg[k].nd = seg[k*2].nd + seg[k*2+1].nd;
}

pair<mat,mat> qry(int l, int r, int k, int x, int y) {
  if (r < x || y < l || x > y) return make_pair(mat(0,0,0,0),mat(0,0,0,0));
  if (x <= l && r <= y) return seg[k];
  int m = (l+r) / 2;
  pair<mat,mat> lhs = qry(l, m, k*2, x, y);
  pair<mat,mat> rhs = qry(m+1, r, k*2+1, x, y);
  rhs.st = rhs.st + lhs.st;
  rhs.nd = rhs.nd + lhs.nd;
  return rhs;
}

int main() {
  FIO
  precomputeInverse(N);
  int n, k; read(n, k); vector<int> p(n); read(p);
  for (int visi = 0; visi <= 1; visi++) {
    for (int visj = 0; visj <= 1; visj++) if (visi ^ visj) {
      pref[visi][visj][0] = mat(1, 0, 0, 1);
      ipref[visi][visj][0] = mat(1, 0, 0, 1);
      for (int i = 1; i <= n; i++) {
        mat cur = mat(norm(min(k, n-i+1) - visi - visj), 0, visi, min(k, n-i+1));
        pref[visi][visj][i] = cur * pref[visi][visj][i-1];
        ipref[visi][visj][i] = ipref[visi][visj][i-1] * imat(cur);
      }
    }
  }
  pre[0] = mat(1, 0, 0, 1);
  for (int i = 1; i <= n; i++)
    pre[i] = mat(min(k, n-i+1), 0, 0, min(k, n-i+1)) * pre[i-1];
  suf[n+1] = mat(1, 0, 0, 1);
  for (int i = n; i; i--)
    suf[i] = suf[i+1] * mat(norm(min(k, n-i+1) - 2), 0, 1, min(k, n-i+1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) // i < j, i > j
      hi[i][j] = suf[max(0,i-k+1)+1] * pref[j^1][j][max(0,i-k+1)];
    for (int j = 0; j < 2; j++) // i < j, i > j
      lo[i][j] = ipref[j^1][j][max(0,i-k+1)] * pre[max(0,i-k+1)];
  }
  int ans = 0, tot = mul(pw(k, n-k), fac[k]), itot = inverse(tot);
  vector<int> ind(n); iota(all(ind), 0);
  sort(all(ind), [&](int l, int r) { return p[l] < p[r]; });
  build(0, n-1, 1);
  for (int ii = 0; ii < n; ii++) {
    int i = ind[ii];
    ans = add(ans, (hi[i][1] * qry(0, n-1, 1, 0, i-1).st)[2]); // lo[][1]
    ans = add(ans, (qry(0, n-1, 1, i+1, n-1).nd * lo[i][0])[2]); // hi[][0]
    upd(0, n-1, 1, i);
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < n; j++) if (p[i] > p[j]) { // place i before j
  //     ans = add(ans, (hi[max(i,j)][i > j] * lo[min(i,j)][i > j])[2]);
  //   }
  // }
  ans = mul(ans, itot);
  print(ans);
  return 0;
}


Measured memory_bytes: 54636