#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 2e5 + 5;
const long long MOD = 998244353;
int n, tab[N], k, cnt;
long long ans, frac[N], pot2[N], km2[N];
long long pot(long long a, long long p) {
  if (p == 0) return 1;
  long long w = pot(a, p / 2);
  w = w * w % MOD;
  if (p % 2) w = w * a % MOD;
  return w;
}
long long dwum(long long n, long long k) {
  long long ans = frac[n];
  ans = ans * pot(frac[k], MOD - 2) % MOD;
  ans = ans * pot(frac[n - k], MOD - 2) % MOD;
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  frac[0] = 1;
  for (int i = 1; i <= n; i++) frac[i] = (long long)i * frac[i - 1] % MOD;
  pot2[0] = 1;
  km2[0] = 1;
  for (int i = 1; i <= n; i++) km2[i] = (long long)(k - 2) * km2[i - 1] % MOD;
  for (int i = 1; i <= n; i++) pot2[i] = (long long)2 * pot2[i - 1] % MOD;
  for (int i = 1; i <= n; i++) scanf("%d", &tab[i]);
  if (tab[n] == tab[1])
    ;
  else {
    cnt++;
  }
  for (int i = 1; i < n; i++) {
    if (tab[i] == tab[i + 1])
      ;
    else {
      cnt++;
    }
  }
  for (int i = 1; i <= cnt; i++) {
    if (i % 2) {
      long long val = pot2[i - 1] * km2[cnt - i] % MOD;
      val = val * dwum(cnt, i) % MOD;
      ans += val;
    } else {
      long long val = pot2[i] - dwum(i, i / 2);
      val %= MOD;
      if (val < 0) val += MOD;
      val = val * pot(2, MOD - 2) % MOD;
      val = val * dwum(cnt, i) % MOD;
      val = val * km2[cnt - i] % MOD;
      ans += val;
    }
  }
  ans %= MOD;
  while (cnt < n) {
    ans = ans * (long long)k % MOD;
    cnt++;
  }
  printf("%lld", ans);
  return 0;
}
