#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MX = 998244353;
const long long int INF = 1LL * MX * MX;
namespace NTT {
typedef unsigned long long T;
const T P = 998244353;
const T ROOT = 570984967;
const int MN = 21;
T omega[1 << MN];
T pw(T x, T n) {
  T res = 1;
  while (n) {
    if (n & 1) res = (unsigned long long)res * x % P;
    x = (unsigned long long)x * x % P;
    n >>= 1;
  }
  return res;
}
void fft(vector<T> &a, int n, bool inverse = false) {
  int N = 1 << n;
  a.insert(a.end(), N - (a).size(), 0);
  T root = pw(ROOT, (1 << 23) / N * (inverse ? (N - 1) : 1));
  omega[0] = 1;
  for (int i = (1); i < (N); ++i)
    omega[i] = (unsigned long long)omega[i - 1] * root % P;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (1 << i); ++j) {
      for (int k = (0); k < (1 << (n - i - 1)); ++k) {
        int s = (j << (n - i)) + k;
        int t = s + (1 << (n - i - 1));
        T w = omega[k << i];
        T temp = a[s] + a[t];
        if (temp >= P) temp -= P;
        T t2 = a[s] - a[t] + P;
        a[t] = (unsigned long long)w * t2 % P;
        a[s] = temp;
      }
    }
  }
  for (int i = (0); i < (N); ++i) {
    int x = i, y = 0;
    for (int j = (0); j < (n); ++j) y = (y << 1) + (x & 1), x >>= 1;
    if (i < y) swap(a[i], a[y]);
  }
  if (inverse) {
    T inv = pw(N, P - 2);
    for (int i = (0); i < (N); ++i) a[i] = (unsigned long long)a[i] * inv % P;
  }
}
vector<T> conv(vector<T> A, vector<T> B) {
  int n = 31 - __builtin_clz(2 * ((A).size() + (B).size()) - 1);
  fft(A, n);
  fft(B, n);
  for (int i = (0); i < ((1 << n)); ++i)
    A[i] = (unsigned long long)A[i] * B[i] % P;
  fft(A, n, true);
  return A;
}
vector<T> square(vector<T> A) {
  int n = 32 - __builtin_clz(2 * (A).size() - 1);
  fft(A, n);
  for (int i = (0); i < ((1 << n)); ++i)
    A[i] = (unsigned long long)A[i] * A[i] % P;
  fft(A, n, true);
  return A;
}
}  // namespace NTT
int n, k;
int in[N];
int fac[N];
int facR[N];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &in[i]);
  in[n + 1] = in[1];
  if (k == 1) {
    puts("0");
    exit(0);
  }
  int m = 0;
  for (int i = 1; i <= n; ++i) m += in[i] != in[i + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % MX;
  facR[n] = NTT::pw(fac[n], MX - 2);
  for (int i = n; i >= 1; --i) facR[i - 1] = 1LL * facR[i] * i % MX;
  vector<unsigned long long> Left(m + 1), Right(m + 1);
  for (int i = 0; i <= m; ++i) {
    Left[i] = 1LL * fac[m] * facR[i] % MX;
    Right[i] = facR[i];
  }
  auto ans = NTT::conv(Left, Right);
  for (int i = 0; i <= m; i += 2)
    ans[i] =
        (ans[i] + MX - 1LL * fac[m] * facR[i / 2] % MX * facR[i / 2] % MX) % MX;
  long long int result = 0;
  for (int i = 0; i <= m; ++i)
    result += 1LL * ans[i] * facR[2] % MX * facR[m - i] % MX *
              NTT::pw(k - 2, m - i) % MX;
  result %= MX;
  result = result * NTT::pw(k, n - m) % MX;
  result = (result + MX) % MX;
  printf("%lld\n", result);
  return 0;
}
