#include <bits/stdc++.h>
using namespace std;
const int N = 210000;
const long long mod = 998244353;
long long pow_mod(long long a, long long e) {
  long long res = 1;
  for (; e; a = a * a % mod, e >>= 1)
    if (e & 1) res = res * a % mod;
  return res;
}
int n, k;
int a[N];
int eq;
const int maxn = 410000;
const long long P = 998244353;
const long long g = 3;
int NN = 1, na, nb;
long long c[maxn * 2], d[maxn * 2], W[2][maxn * 2], rev[maxn * 2];
long long inv[410000];
long long f[410000];
void NTT(long long* a, int f, int N) {
  for (int i = 0; i < N; i++)
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int i = 1; i < N; i <<= 1)
    for (int j = 0, t = N / (i << 1); j < N; j += i << 1)
      for (int k = 0, l = 0, x, y; k < i; k++, l += t)
        x = (long long)W[f][l] * a[j + k + i] % P, y = a[j + k],
        a[j + k] = (y + x) % P, a[j + k + i] = (y - x + P) % P;
  if (f)
    for (int i = 0, x = pow_mod(N, P - 2); i < N; i++)
      a[i] = (long long)a[i] * x % P;
}
void change(int N) {
  for (int i = 0; i < N; i++) {
    int x = i, y = 0;
    for (int k = 1; k < N; x >>= 1, k <<= 1) (y <<= 1) |= x & 1;
    rev[i] = y;
  }
}
void init(int N) {
  W[0][0] = W[1][0] = 1;
  for (int i = 1, x = pow_mod(g, (P - 1) / N), y = pow_mod(x, P - 2); i < N;
       i++)
    W[0][i] = (long long)x * W[0][i - 1] % P,
    W[1][i] = (long long)y * W[1][i - 1] % P;
  change(N);
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  f[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++)
    f[i] = (long long)i * f[i - 1] % mod, inv[i] = pow_mod(f[i], mod - 2);
  if (a[1] == a[n]) eq = 1;
  for (int i = 1; i < n; i++)
    if (a[i] == a[i + 1]) eq++;
  if (eq == n) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = pow_mod(k, eq);
  int dd = n - eq;
  long long p = k - 2;
  c[0] = d[0] = 1;
  for (int i = 1; i <= dd; i++) c[i] = d[i] = inv[i];
  while (NN < 2 * dd) NN <<= 1;
  init(NN);
  NTT(c, 0, NN);
  NTT(d, 0, NN);
  for (int i = 0; i < NN; i++) c[i] = c[i] * d[i] % mod;
  NTT(c, 1, NN);
  long long res = 0;
  for (int i = 1; i <= dd; i++) {
    long long tmp = c[i] * pow_mod(p, dd - i) % mod;
    tmp = tmp * inv[dd - i] % mod;
    tmp = tmp * f[dd] % mod;
    res = (res + tmp) % mod;
  }
  for (int i = 1; i + i <= dd; i++) {
    long long tmp = f[dd] * inv[i] % mod;
    tmp = tmp * inv[i] % mod;
    tmp = tmp * inv[dd - i - i] % mod;
    tmp = tmp * pow_mod(p, dd - i - i) % mod;
    res = (res + mod - tmp) % mod;
  }
  ans = ans * res % mod;
  ans = ans * pow_mod(2, mod - 2) % mod;
  cout << ans << endl;
  return 0;
}
