#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
vector<long long> nfact;
long long modpow(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
long long ncr(long long n, long long r, int N = 1000000) {
  if (!nfact.size()) {
    nfact.resize(N + 1);
    nfact[0] = 1;
    for (int i = 1; i <= N; i++) {
      nfact[i] = nfact[i - 1] * i;
      nfact[i] %= MOD;
    }
  }
  if (r > n) return 0;
  long long d1 = modpow(nfact[r], MOD - 2, MOD);
  long long d2 = modpow(nfact[n - r], MOD - 2, MOD);
  long long mult = (d1 * d2) % MOD;
  return (nfact[n] * mult) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  vector<int> h(n);
  for (int &i : h) cin >> i;
  vector<long long> kpow(n + 1), km2pow(n + 1), twoPow(n + 1);
  kpow[0] = 1, km2pow[0] = 1, twoPow[0] = 1;
  for (int i = 1; i <= n; i++) {
    kpow[i] = kpow[i - 1] * k;
    kpow[i] %= MOD;
    km2pow[i] = km2pow[i - 1] * (k - 2);
    km2pow[i] %= MOD;
    twoPow[i] = twoPow[i - 1] * 2;
    twoPow[i] %= MOD;
  }
  int s = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] != h[(i + 1) % n]) s++;
  }
  long long ans = 0;
  for (int j = 0; j < s; j++) {
    int rem = s - j;
    long long val = twoPow[rem - 1];
    if (!(rem % 2)) val -= ncr(rem, rem / 2) * modpow(2, MOD - 2, MOD);
    val %= MOD;
    if (val <= 0) val += MOD;
    val *= km2pow[j];
    val %= MOD;
    val *= ncr(s, j);
    ans += val;
    ans %= MOD;
  }
  ans *= kpow[n - s];
  ans %= MOD;
  cout << ans;
  return 0;
}
