#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 2e5 + 5, MOD = 998244353;
const long double EPS = 1e-9;
int read() {
  int xx = 0, ff = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = (xx << 3) + (xx << 1) + ch - '0';
    ch = getchar();
  }
  return xx * ff;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long add(long long a, long long b) { return (a + b) % MOD; }
long long mul(long long a, long long b) { return (a * b) % MOD; }
long long fastpow(long long a, long long p) {
  if (p == 0) return 1;
  long long z = fastpow(a, p / 2);
  z = mul(z, z);
  if (p % 2) z = mul(z, a);
  return z;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < n; ++j) {
    for (int i = 0; i < j; ++i) {
      long long rat = mul(k - 1, fastpow(k, MOD - 2));
      rat = fastpow(rat, max(0, j - max(k - 1, i)));
      rat = mul(rat, fastpow(2, MOD - 2));
      if (a[i] < a[j])
        ans = add(ans, rat);
      else {
        long long num = mul(2, fastpow(k, max(0, j - max(k - 1, i)))) -
                        fastpow(k - 1, max(0, j - max(k - 1, i)));
        num %= MOD;
        if (num < 0) num += MOD;
        long long denom = mul(2, fastpow(k, max(0, j - max(k - 1, i))));
        num = mul(num, fastpow(denom, MOD - 2));
        num %= MOD;
        ans = add(ans, num);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
