#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 222222;
long long frc[maxn];
long long cc[2222][2222];
long long ccc[maxn];
long long quickpow(long long x, long long k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return ans;
}
void init() {
  frc[0] = 1;
  for (int i = 1; i < maxn; i++) frc[i] = frc[i - 1] * i % mod;
}
long long cal(int n, int m) {
  return frc[n] * quickpow(frc[m], mod - 2) % mod *
         quickpow(frc[n - m], mod - 2) % mod;
}
int main() {
  init();
  int n, k;
  while (cin >> n >> k) {
    for (int i = 0; i <= n; i++) {
      ccc[i] = frc[n] * quickpow(frc[i], mod - 2) % mod *
               quickpow(frc[n - i], mod - 2);
    }
    vector<int> a(n);
    int cnt = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      if (a[i] != a[(i + 1) % n]) cnt++;
    }
    long long ans = quickpow(k, n - cnt);
    if (cnt) {
      long long res = 0;
      for (int i = 0; i * 2 <= cnt; i++) {
        res = (res + cal(cnt, i) * cal(cnt - i, i) % mod *
                         quickpow(k - 2, cnt - i * 2)) %
              mod;
      }
      long long all = quickpow(k, cnt);
      res = (long long)(all - res + mod) * quickpow(2, mod - 2) % mod;
      ans = ans * res % mod;
    } else
      ans = 0;
    cout << ans << endl;
  }
  return 0;
}
