#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long MOD = 998244353;
const long long inv2 = (MOD + 1) / 2;
int h[N];
long long pw2[N];
long long fac[N], inv[N];
long long pw(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return ans;
}
void init() {
  fac[0] = inv[0] = 1;
  pw2[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = pw(fac[i], MOD - 2);
    pw2[i] = pw2[i - 1] * 2 % MOD;
  }
}
long long C(int n, int m) { return fac[n] * inv[m] % MOD * inv[n - m] % MOD; }
long long cal(int n) {
  if (n & 1)
    return pw2[n - 1];
  else
    return (pw2[n] - C(n, n / 2)) * inv2 % MOD;
}
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", h + i);
  if (k == 1) {
    printf("0\n");
    return;
  }
  int a = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n]) a++;
  }
  long long ans = 0;
  int b = n - a;
  for (int i = 0; i < b; i++) {
    ans += C(b, i) * pw(k - 2, i) % MOD * cal(b - i);
    ans %= MOD;
  }
  ans *= pw(k, a);
  ans %= MOD;
  if (ans < 0) ans += MOD;
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
