#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 60;
const int P = 998244353;
struct MI {
  int x;
  inline MI(int x = 0) : x(x) {}
  inline MI &operator=(const MI &b) { return x = b.x, *this; }
  inline MI &operator=(int o) { return x = o, *this; }
  inline MI &operator+=(MI o) {
    return x = x + o.x >= P ? x + o.x - P : x + o.x, *this;
  }
  inline MI &operator-=(MI o) {
    return x = x - o.x < 0 ? x - o.x + P : x - o.x, *this;
  }
  inline MI &operator*=(MI o) { return x = 1ll * x * o.x % P, *this; }
  inline MI &operator^=(long long b) {
    MI a = *this, c;
    if (!~b) b = P - 2;
    c.x = 1 % P;
    while (b) {
      if (b & 1) c *= a;
      a *= a, b >>= 1;
    }
    return x = c.x, *this;
  }
  inline MI &operator/=(MI o) { return *this *= o ^= -1; }
  inline MI &operator+=(int o) {
    return x = x + o >= P ? x + o - P : x + o, *this;
  }
  inline MI &operator-=(int o) {
    return x = x - o < 0 ? x - o + P : x - o, *this;
  }
  inline MI &operator*=(int o) { return x = 1ll * x * o % P, *this; }
  inline MI &operator/=(int o) {
    MI y = MI(o);
    return *this *= y ^= -1;
  }
  template <class I>
  inline friend MI operator+(MI a, I b) {
    return a += b;
  }
  template <class I>
  inline friend MI operator-(MI a, I b) {
    return a -= b;
  }
  template <class I>
  inline friend MI operator*(MI a, I b) {
    return a *= b;
  }
  inline friend MI operator^(MI a, long long b) { return a ^= b; }
  template <class I>
  inline friend MI operator/(MI a, I b) {
    return a /= b;
  }
  inline friend bool operator==(MI a, int b) { return a.x == b; }
  inline bool operator!() { return !x; }
  inline MI operator-() { return x ? P - x : 0; }
};
int n, k, a[N], t;
MI fac[N], inv[N];
MI C(int n, int m) {
  if (m < 0 || m > n) return 0;
  ;
  return fac[n] * inv[m] * inv[n - m];
}
int main() {
  scanf("%d%d", &n, &k);
  if (k == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i);
  a[n + 1] = a[1];
  fac[0] = 1;
  for (int i = 1; i <= (n); ++i) fac[i] = fac[i - 1] * MI(i);
  inv[1] = 1;
  for (int i = 2; i <= (n); ++i) inv[i] = MI(P - P / i) * inv[P % i];
  inv[0] = 1;
  for (int i = 1; i <= (n); ++i) inv[i] *= inv[i - 1];
  for (int i = 1; i <= (n); ++i)
    if (a[i] != a[i + 1]) ++t;
  ;
  MI ans = 0;
  for (int p = 0; p <= (t); ++p) {
    int z = t - p;
    MI d = z % 2 ? (MI(2) ^ (z - 1)) : ((MI(2) ^ z) - C(z, z / 2)) / 2;
    ;
    ans += C(t, p) * (MI(k - 2) ^ (p)) * d;
    ;
  }
  ans *= MI(k) ^ (n - t);
  printf("%d\n", ans.x);
}
