#include <bits/stdc++.h>
using namespace std;
int n, k, num, ans;
int s[200005], fc[200005], ny[200005];
int po(int a, int b) {
  int an = 1;
  while (b != 0) {
    if (b & 1) an = (long long)an * a % 998244353;
    a = (long long)a * a % 998244353;
    b = (b >> 1);
  }
  return an;
}
int C(int a, int b) {
  return (long long)fc[b] * ny[a] % 998244353 * ny[b - a] % 998244353;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= n; i++) {
    int tmp = i + 1;
    if (tmp == n + 1) tmp = 1;
    if (s[i] != s[tmp]) num++;
  }
  fc[0] = ny[0] = 1;
  for (int i = 1; i <= n; i++)
    fc[i] = (long long)fc[i - 1] * i % 998244353,
    ny[i] = po(fc[i], 998244353 - 2);
  int an = po(k, n - num);
  for (int i = 0; i < num; i++) {
    int tmp = (long long)po(k - 2, i) * C(i, num) % 998244353;
    int ti = po(2, num - i);
    if ((num - i) % 2 == 0)
      ti = (ti - C((num - i) / 2, (num - i)) + 998244353) % 998244353;
    ti = (long long)ti * po(2, 998244353 - 2) % 998244353;
    tmp = (long long)tmp * ti % 998244353;
    ans = (ans + (long long)an * tmp % 998244353) % 998244353;
  }
  printf("%d\n", ans);
  return 0;
}
