#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

namespace io {
#define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
  const int SIZE = (1 << 21) + 1;
  char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;
  inline char getc () {return (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++);}
  inline void flush () {fwrite (obuf, 1, oS - obuf, stdout); oS = obuf;}
  inline void putc (char x) {*oS ++ = x; if (oS == oT) flush ();}
  template<class T>
  inline void read(T &x) {
    char ch; int f = 1;
    x = 0;
    while(isspace(ch = getc()));
    if(ch == '-') ch = getc(), f = -1;
    do x = x * 10 + ch - '0'; while(isdigit(ch = getc()));
    x *= f;
  }
  template<class T, class ...Args>
  inline void read(T &x, Args&... args) {read(x); read(args...);}
  template<class T>
  inline void write(T x) {
    static char stk[128];
    int top = 0;
    if(x == 0) {putc('0'); return;}
    if(x < 0) putc('-'), x = -x;
    while(x) stk[top++] = x % 10, x /= 10;
    while(top) putc(stk[--top] + '0');
  }
  template<class T, class ...Args>
  inline void write(T x, Args... args) {write(x); putc(' '); write(args...);}
  inline void space() {putc(' ');}
  inline void endl() {putc('\n');}
  struct _flush {~_flush() {flush();}} __flush;
};
using io::read; using io::write; using io::flush; using io::space; using io::endl; using io::getc; using io::putc;

const int M = 998244353;
inline int add(int x, int y) {return x+y>=M ? x+y-M : x+y;}
template<class ...Args> inline int add(int x, int y, Args... args) {return add(add(x, y), args...);}
inline int sub(int x, int y) {return x-y<0 ? x-y+M : x-y;}
inline int mul(int x, int y) {return 1LL * x * y % M;}
template<class ...Args> inline int mul(int x, int y, Args... args) {return mul(mul(x, y), args...);}
inline void inc(int &x, int y=1) {x += y; if(x >= M) x -= M;}
inline void dec(int &x, int y=1) {x -= y; if(x < 0) x += M;}
inline int power(int x, int y){
  int res = 1;
  for(; y; y>>=1, x = mul(x, x)) if(y & 1) res = mul(res, x);
  return res;
}
inline int inv(int x){return power(x, M - 2);}

const int N = 200005;
int tr[N];
int cnt[N];
int n, tot = 0, totc = 0;
void modify(int p, int v) {
  inc(tot, v); ++totc;
  for (; p <= n; p += p & -p) inc(tr[p], v), ++cnt[p];
}
pair<int, int> query(int p) {
  ll s = 0;
  int c = 0;
  for (; p; p ^= p & -p) s += tr[p], c += cnt[p];
  return make_pair(int(s % M), c);
}

int p[N], Pk[N], iPk[N];

int main() {
  int k;
  read(n, k);
  for (int i = 1; i <= n; ++i)
    read(p[i]);
  int s1 = mul(k, k - 1, inv(4)), s2 = 0;
  Pk[0] = 1; iPk[0] = 1;
  Pk[1] = mul(k - 1, inv(k)); iPk[1] = inv(Pk[1]);
  for (int i = 2; i <= n; ++i) Pk[i] = mul(Pk[i - 1], Pk[1]);
  for (int i = 2; i <= n; ++i) iPk[i] = mul(iPk[i - 1], iPk[1]);
  for (int i = 1; i <= k; ++i)
    modify(p[i], iPk[k]);
  for (int i = k + 1; i <= n; ++i) {
    pair<int, int> q = query(p[i] - 1);
    int lt = q.first, gt = sub(tot, lt);
    int gtc = totc - q.second;
    inc(s2, mul(lt, Pk[i]));
    inc(s2, sub(add(gtc, gtc), mul(gt, Pk[i])));
    modify(p[i], iPk[i]);
  }
  write(add(s1, mul(s2, (M + 1) / 2))), endl();
  return 0;
}

Measured memory_bytes: 8236