#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200050;
const int mod = 998244353;
int a[MAXN], n, k;
int p[MAXN], pf[MAXN];
int add(int o, int p) {
  o += p;
  if (o >= mod) o -= mod;
  return o;
}
int mul(int o, int p) {
  long long ret = 1LL * o * p;
  return ret - ret / mod * mod;
}
int ksm(int o, int p) {
  int ret = 1;
  while (p) {
    if (p & 1) {
      ret = mul(ret, o);
    }
    p >>= 1;
    o = mul(o, o);
  }
  return ret;
}
int sub(int o, int p) {
  o -= p;
  if (o < 0) o += mod;
  return o;
}
int c(int n, int m) { return mul(p[n], mul(pf[m], pf[n - m])); }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  if (k == 1) {
    cout << "0" << endl;
    return 0;
  }
  int nn = n;
  a[n] = a[0];
  for (int i = 0; i < n; ++i) {
    if (a[i] == a[i + 1]) nn--;
  }
  p[0] = 1;
  for (int i = 1; i <= n; ++i) {
    p[i] = mul(p[i - 1], i);
  }
  pf[n] = ksm(p[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    pf[i] = mul(pf[i + 1], i + 1);
  }
  int ans = ksm(k % mod, nn);
  for (int i = 0; i + i <= nn; ++i) {
    ans = sub(ans, mul(ksm(k - 2, nn - i - i), mul(c(nn, i), c(nn - i, i))));
  }
  ans = mul(ans, pf[2]);
  for (int i = nn; i < n; ++i) {
    ans = mul(ans, k % mod);
  }
  cout << ans << endl;
  return 0;
}
