#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const long long MOD = 998244353;
const long long MAXN = 2e5 + 100;
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}
long long inv(long long x) { return qpow(x, MOD - 2); }
long long fact[MAXN];
long long C(long long n, long long k) {
  return fact[n] * inv(fact[k] * fact[n - k] % MOD) % MOD;
}
long long N, K;
long long arr[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact[0] = 1;
  for (long long i = 1; i < MAXN; i++) fact[i] = fact[i - 1] * i % MOD;
  cin >> N >> K;
  long long cont = 0;
  for (long long i = 0; i < N; i++) {
    cin >> arr[i];
  }
  for (long long i = 0; i < N; i++) {
    if (arr[i] != arr[(i + 1) % N]) {
      cont++;
    }
  }
  long long res = 0;
  for (long long i = 1; i <= cont; i++) {
    long long tp = qpow(2, i);
    if (i % 2 == 0) tp = (tp + MOD - C(i, i / 2)) % MOD;
    tp = tp * inv(2) % MOD;
    tp = tp * qpow(K - 2, cont - i) % MOD;
    tp = tp * C(cont, i) % MOD;
    res = (res + tp) % MOD;
  }
  res = res * qpow(K, N - cont) % MOD;
  cout << res << '\n';
  return 0;
}
