#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int A[200000], F[200001], Finv[200001];
long long fast_pow(long long a, long long b) {
  long long ret = 1;
  for (; b; b >>= 1) {
    if (b & 1) ret = (ret * a) % MOD;
    a = (a * a) % MOD;
  }
  return ret;
}
int mul(int a, int b) { return 1LL * a * b % MOD; }
int nCr(int a, int b) { return mul(F[a], mul(Finv[a - b], Finv[b])); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int N, K, res = 1, ans = 0, cnt = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    if (A[i] == A[(i + 1) % N])
      res = (1LL * res * K) % MOD;
    else
      cnt++;
  }
  F[0] = Finv[0] = 1;
  for (int i = 1; i <= N; i++) F[i] = (1LL * F[i - 1] * i) % MOD;
  Finv[N] = fast_pow(F[N], MOD - 2);
  for (int i = N - 1; i > 0; i--) Finv[i] = (i + 1LL) * Finv[i + 1] % MOD;
  for (int i = 0; i <= cnt; i++) {
    if ((cnt - i) & 1) {
      ans = (ans + mul(mul(nCr(cnt, i), fast_pow(K - 2, i)),
                       fast_pow(2, cnt - i - 1))) %
            MOD;
    } else {
      int v = ((MOD + fast_pow(2, cnt - i) - nCr(cnt - i, (cnt - i) / 2)) *
               fast_pow(2, MOD - 2)) %
              MOD;
      ans = (ans + mul(mul(nCr(cnt, i), fast_pow(K - 2, i)), v)) % MOD;
    }
  }
  cout << (1LL * ans * res) % MOD << '\n';
  return 0;
}
