#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXQUEST = 200000;
const int MOD = 998244353;
const int INV2 = (MOD + 1) / 2;
void inc(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
void dec(int &a, int b) { inc(a, MOD - b); }
int nquest, nkind;
int ans[MAXQUEST];
int inv[MAXQUEST + 1];
int fac[MAXQUEST + 1];
int ifac[MAXQUEST + 1];
int p2[MAXQUEST + 1];
int pkind[MAXQUEST + 1];
int pkindsub[MAXQUEST + 1];
int choose(int n, int k) {
  if (k < 0 || k > n) return 0;
  return (long long)fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}
int solve() {
  if (nkind == 1) return 0;
  inv[1] = 1;
  for (int i = (2); i <= (nquest); ++i)
    inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD;
  fac[0] = 1;
  for (int i = (1); i <= (nquest); ++i)
    fac[i] = (long long)fac[i - 1] * i % MOD;
  ifac[0] = 1;
  for (int i = (1); i <= (nquest); ++i)
    ifac[i] = (long long)ifac[i - 1] * inv[i] % MOD;
  p2[0] = 1;
  for (int i = (1); i <= (nquest); ++i) p2[i] = (long long)p2[i - 1] * 2 % MOD;
  pkind[0] = 1;
  for (int i = (1); i <= (nquest); ++i)
    pkind[i] = (long long)pkind[i - 1] * nkind % MOD;
  pkindsub[0] = 1;
  for (int i = (1); i <= (nquest); ++i)
    pkindsub[i] = (long long)pkindsub[i - 1] * (nkind - 2) % MOD;
  int nsame = 0, ndiff = 0;
  for (int i = (0); i < (nquest); ++i) {
    int j = (i + 1) % nquest;
    if (ans[i] == ans[j])
      ++nsame;
    else
      ++ndiff;
  }
  int ret = 0;
  for (int nval = (0); nval <= (ndiff); ++nval) {
    int ways = p2[nval];
    if (nval % 2 == 0) dec(ways, choose(nval, nval / 2));
    ways = (long long)ways * INV2 % MOD;
    int cur = (long long)choose(ndiff, nval) * ways % MOD *
              pkindsub[ndiff - nval] % MOD;
    inc(ret, cur);
  }
  ret = (long long)ret * pkind[nsame] % MOD;
  return ret;
}
void run() {
  scanf("%d%d", &nquest, &nkind);
  for (int i = (0); i < (nquest); ++i) scanf("%d", &ans[i]);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
