#include <bits/stdc++.h>
using namespace std;
int inline read() {
  int num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const int maxn = 200010, mod = 998244353;
int n, k, a, b, h[maxn], ans, sum, fac[maxn], inv[maxn];
int Pow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = 1ll * ans * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return ans;
}
int C(int x, int y) { return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod; }
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) h[i] = read();
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int to;
    if (i == n)
      to = 1;
    else
      to = i + 1;
    if (h[i] == h[to])
      a++;
    else
      b++;
  }
  ans = Pow(k, a);
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= b; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 1; i <= b; i++) inv[i] = Pow(fac[i], mod - 2);
  for (int i = 1; i <= b; i++) {
    int S;
    if (i & 1)
      S = Pow(2, i - 1);
    else
      S = ((1ll * Pow(2, i) * inv[2] % mod - 1ll * C(i, i / 2) * inv[2] % mod) %
               mod +
           mod) %
          mod;
    sum = (sum + 1ll * Pow(k - 2, b - i) * C(b, b - i) % mod * S % mod) % mod;
  }
  cout << 1ll * ans * sum % mod;
  return 0;
}
