#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 2e5 + 10;
const int M = 1e4 + 10;
const int maxn = 1e6 + 10;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
int n, k;
int h[N];
long long fac[N], inv[N];
long long qpow(long long a, long long b) {
  long long res = 1;
  for (a %= mod; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long C(int n, int m) { return fac[n] * inv[n - m] % mod * inv[m] % mod; }
void init() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = qpow(fac[i], mod - 2);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> h[i];
  if (k == 1) {
    cout << "0\n";
    return 0;
  }
  init();
  int x = 0;
  for (int i = 1; i <= n; i++) {
    int j = i - 1;
    if (!j) j = n;
    if (h[i] ^ h[j]) x++;
  }
  long long ans = 0;
  long long inv2 = (mod + 1) / 2;
  for (int i = 0; i < x; i++) {
    long long res = C(x, i) * qpow(k - 2, i) % mod;
    long long t = qpow(2, x - i);
    if ((x - i) % 2 == 0) t = ((t - C(x - i, (x - i) / 2)) % mod + mod) % mod;
    res = res * t % mod * inv2 % mod;
    ans = (ans + res) % mod;
  }
  ans = ans * qpow(k, n - x) % mod;
  cout << ans << '\n';
  return 0;
}
