#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long arr[200200];
long long fact[200200], inv[200200];
long long binexp(long long a, long long b) {
  if (b == 0) return 1ll;
  if (b == 1) return a % 998244353;
  if (b % 2) return (a * binexp(a, b - 1) + 998244353) % 998244353;
  return binexp((a * a + 998244353) % 998244353, b / 2);
}
long long ginv(long long a) { return binexp(a, 998244353 - 2); }
long long choose(long long a, long long b) {
  long long res = (fact[a] * inv[b]) % 998244353;
  res = (res * inv[a - b]) % 998244353;
  return res;
}
int main() {
  scanf(" %lld%lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  arr[n] = arr[0];
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  long long x = 0;
  for (int i = 0; i < n; i++) x += (arr[i] != arr[i + 1]);
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < 200200; i++) {
    fact[i] = (fact[i - 1] * (long long)i) % 998244353;
    inv[i] = ginv(fact[i]);
  }
  long long ans = 0;
  for (int i = 0; i < x; i++) {
    long long mv = (choose(x, i) * binexp(k - 2, i)) % 998244353;
    long long rem = x - i;
    long long cv;
    if (rem % 2)
      cv = binexp(2, rem - 1);
    else
      cv = (inv[2] *
            ((binexp(2, rem) - choose(rem, rem / 2) + 998244353) % 998244353)) %
           998244353;
    ans += (cv * mv) % 998244353;
  }
  ans %= 998244353;
  ans *= binexp(k, n - x);
  ans %= 998244353;
  printf("%lld\n", ans);
}
