#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int mxN = 200001;
long long fact[mxN], power[mxN], two[mxN];
int n;
long long k;
int h[mxN];
long long binpow(long long x, long long y) {
  long long res = 1;
  x = x % MOD;
  while (y > 0) {
    if (y % 2 == 1) {
      res = (res * x) % MOD;
    }
    y = y >> 1;
    x = (x * x) % MOD;
  }
  return res;
}
long long modInv(long long n, long long p) { return binpow(n, p - 2); }
long long divide(long long a, long long b) {
  return (a % MOD) * (binpow(b, MOD - 2)) % MOD;
}
long long nCr(int n, int r) {
  if (r == 0) return 1;
  return (fact[n] * modInv(fact[r], MOD) % MOD * modInv(fact[n - r], MOD) %
          MOD) %
         MOD;
}
int main() {
  cin >> n >> k;
  int bad = 0;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
    if (i > 0 && h[i - 1] == h[i]) bad++;
  }
  if (h[n - 1] == h[0]) bad++;
  int tot = n - bad;
  fact[0] = 1;
  power[0] = 1;
  two[0] = 1;
  for (int i = 1; i < mxN; ++i) {
    power[i] = (power[i - 1] * (k - 2)) % MOD;
    two[i] = (two[i - 1] * 2) % MOD;
    fact[i] = (fact[i - 1] * i) % MOD;
  }
  long long ans = 0;
  for (int i = 0; i < tot; ++i) {
    long long curr = (power[i] * nCr(tot, i)) % MOD;
    if ((tot - i) % 2 == 1) {
      curr = (curr * two[tot - i - 1]) % MOD;
    } else {
      long long mult = (two[tot - i] - nCr(tot - i, (tot - i) / 2) + MOD) % MOD;
      mult = divide(mult, 2);
      curr = (curr * mult) % MOD;
    }
    ans = (ans + curr) % MOD;
  }
  ans = (ans * binpow(k, bad)) % MOD;
  cout << ans << "\n";
  return 0;
}
