#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long inv[200020 + 10], fac[200020 + 10], ifac[200020 + 10];
void setComb() {
  inv[0] = 1;
  inv[1] = 1;
  fac[1] = 1;
  ifac[1] = 1;
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 2; i < 200020; i++) {
    inv[i] = (-MOD / i) * inv[MOD % i] % MOD;
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
    inv[i] = (inv[i] + MOD) % MOD;
    fac[i] = (fac[i] + MOD) % MOD;
    ifac[i] = (ifac[i] + MOD) % MOD;
  }
  return;
}
long long comb(long long n, long long k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  else
    return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD);
}
long long hcomb(long long n, long long r) {
  if (n == 0 && r == 0)
    return 1;
  else if (n < 0 || r < 0)
    return 0;
  else
    return comb(n + r - 1, r - 1);
}
long long mod_pow(long long n, long long x) {
  x %= MOD;
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return (res + MOD) % MOD;
}
long long N, K;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  setComb();
  long long num = 0;
  long long aaans = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] != A[(i + 1) % N])
      num++;
    else
      aaans = aaans * K % MOD;
  }
  long long ans = 0;
  for (long long i = 1; i <= num; i++) {
    long long res = comb(num, i);
    long long p = mod_pow(num - i, K - 2);
    if (i % 2) {
      res = res * mod_pow(i - 1, 2) % MOD;
    } else {
      long long q = (mod_pow(i, 2) - comb(i, i / 2) + MOD) % MOD;
      q = q * inv[2] % MOD;
      res = res * q % MOD;
    }
    res = res * p % MOD;
    ans = (ans + res) % MOD;
  }
  ans = ans * aaans % MOD;
  cout << (ans + MOD) % MOD << endl;
  return 0;
}
