#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const long long mod = 998244353;
long long fact[N + 10], inv[N + 10], inv2;
int h[N + 10], cnt[2];
long long bigmod(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  long long x = bigmod(a, b / 2);
  x = (x * x) % mod;
  if (b & 1) {
    x = (x * a) % mod;
  }
  return x;
}
long long ncr(int n, int r) {
  long long ret = (inv[n - r] * inv[r]) % mod;
  ret = (fact[n] * ret) % mod;
  return ret;
}
int main() {
  inv2 = bigmod(2, mod - 2);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
  }
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int nxt = i + 1;
    if (nxt > n) {
      nxt = 1;
    }
    if (h[i] == h[nxt]) {
      cnt[1]++;
    } else {
      cnt[0]++;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= cnt[0]; i++) {
    long long tmp1 = ncr(cnt[0], i);
    long long tmp2;
    if (i & 1) {
      tmp2 = bigmod(2, i - 1);
    } else {
      tmp2 = (bigmod(2, i) - ncr(i, i / 2) + mod) % mod;
      tmp2 = (tmp2 * inv2) % mod;
    }
    long long tmp3 = bigmod(k - 2, cnt[0] - i);
    long long tmp = (tmp1 * tmp2) % mod;
    tmp = (tmp * tmp3) % mod;
    ans = (ans + tmp) % mod;
  }
  ans = (ans * bigmod(k, cnt[1])) % mod;
  printf("%lld\n", ans);
}
