#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 1;
long long pow2[maxN];
long long fac[maxN];
long long facInv[maxN];
long long km2pow[maxN];
long long sCz[maxN];
long long xCxd2[maxN];
long long div2;
long long modInv(long long val) {
  long long ret = 1;
  long long mult = val;
  long long k = 998244353 - 2;
  while (k > 0) {
    if ((k & 1) > 0) ret = (ret * mult) % 998244353;
    mult = (mult * mult) % 998244353;
    k >>= 1;
  }
  return ret;
}
void fillpow2(int maxVal) {
  pow2[0] = 1;
  for (int i = 1; i <= maxVal; i++) {
    long long temp = pow2[i - 1] << 1;
    if (temp >= 998244353) temp = temp % 998244353;
    pow2[i] = temp;
  }
}
void fillfac(int maxVal) {
  fac[0] = 1;
  facInv[0] = 1;
  for (int i = 1; i <= maxVal; i++) {
    long long temp = fac[i - 1] * i;
    if (temp >= 998244353) temp = temp % 998244353;
    fac[i] = temp;
    facInv[i] = modInv(fac[i]);
  }
}
void fillkm2pow(int maxVal, int k) {
  km2pow[0] = 1;
  if (k < 2) {
    fill(km2pow, km2pow + maxVal, 0);
  } else {
    for (int i = 1; i <= maxVal; i++) {
      long long temp = km2pow[i - 1] * (k - 2);
      if (temp >= 998244353) temp = temp % 998244353;
      km2pow[i] = temp;
    }
  }
}
void fillsCz(int maxVal, int s) {
  long long a = fac[s];
  for (int i = 0; i <= maxVal; i++) {
    long long b = facInv[i];
    long long c = facInv[s - i];
    long long temp = a * b;
    if (temp >= 998244353) temp = temp % 998244353;
    temp *= c;
    if (temp >= 998244353) temp = temp % 998244353;
    sCz[i] = temp;
  }
}
void fillxCxd2(int maxVal) {
  for (int i = 0; i <= maxVal; i += 2) {
    long long a = fac[i];
    long long b = facInv[i / 2];
    long long temp = a * b;
    if (temp >= 998244353) temp = temp % 998244353;
    temp *= b;
    if (temp >= 998244353) temp = temp % 998244353;
    xCxd2[i] = temp;
  }
}
void fillAll(int S, int k) {
  fillpow2(S);
  fillfac(S);
  fillkm2pow(S, k);
  fillsCz(S, S);
  fillxCxd2(S);
  div2 = modInv(2);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int h[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  int R = 0;
  for (int i = 1; i < n; i++) {
    if (h[i] == h[i - 1]) {
      R++;
    }
  }
  if (h[0] == h[n - 1]) R++;
  long long kpowr = 1;
  for (int i = 0; i < R; i++) {
    kpowr *= k;
    if (kpowr >= 998244353) kpowr = kpowr % 998244353;
  }
  int S = n - R;
  fillAll(S, k);
  long long ways = 0;
  for (int z = 0; z < S; z++) {
    long long a = sCz[z];
    long long b = km2pow[z];
    int x = S - z;
    long long c;
    if (x % 2 == 1) {
      c = pow2[x - 1];
    } else {
      c = pow2[x - 1] - ((xCxd2[x] * div2) % 998244353);
      if (c < 0) c = c + 998244353;
    }
    long long temp = a * b;
    if (temp >= 998244353) temp = temp % 998244353;
    temp *= c;
    if (temp >= 998244353) temp = temp % 998244353;
    ways += temp;
    if (ways >= 998244353) ways = ways % 998244353;
  }
  long long output = kpowr * ways;
  if (output >= 998244353) output = output % 998244353;
  printf("%lld\n", output);
}
