#include <bits/stdc++.h>
using namespace std;
const int sz = 222222;
const long long int mod = 998244353;
long long int arr[sz], arr2[sz], dp1[sz], dp2[sz], dp3[sz], dp4[sz];
long long int calc3(long long int now, long long int num) {
  if (num == 0) return 1;
  if (num == 1) return now;
  long long int now2 = calc3(now, num / 2);
  if (num % 2 == 0) return (now2 * now2) % mod;
  return (((now2 * now2) % mod) * now) % mod;
}
long long int calc2(long long int f, long long int s) {
  return (f * calc3(s, mod - 2)) % mod;
}
long long int calc(int f, int s) {
  return calc2(dp3[f], (dp3[s] * dp3[f - s]) % mod);
}
int main(void) {
  long long int n, k;
  scanf("%lld%lld", &n, &k);
  for (int e = 0; e < n; e++) scanf("%lld", &arr[e]);
  for (int e = 1; e < n; e++) arr2[e] = arr[e - 1];
  arr2[0] = arr[n - 1];
  int tmp = 0;
  for (int e = 0; e < n; e++)
    if (arr2[e] == arr[e]) tmp++;
  n -= tmp;
  dp1[0] = 1;
  dp2[0] = 1;
  dp3[0] = 1;
  dp4[0] = 1;
  for (int e = 1; e < sz; e++) dp1[e] = (dp1[e - 1] * k) % mod;
  for (int e = 1; e < sz; e++) dp2[e] = (dp2[e - 1] * (k - 2)) % mod;
  for (int e = 1; e < sz; e++) dp3[e] = (dp3[e - 1] * (long long int)e) % mod;
  for (int e = 1; e < sz; e++) dp4[e] = (dp4[e - 1] * 2) % mod;
  long long int ans = 0;
  for (int e = 0; e <= n; e++) {
    long long int ans3 = calc(n, e);
    ans3 = (ans3 * dp2[n - e]) % mod;
    ans3 = (ans3 * dp4[e]) % mod;
    ans = (ans + ans3) % mod;
  }
  for (int e = 0; e <= (n / 2); e++) {
    long long int ans3 = dp2[n - 2 * e];
    ans3 = (ans3 * calc(n, 2 * e)) % mod;
    ans3 = (ans3 * calc(2 * e, e)) % mod;
    ans = (ans - ans3 + mod * mod) % mod;
  }
  ans = calc2(ans, 2);
  printf("%lld", (dp1[tmp] * ans) % mod);
  return 0;
}
