#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int a[200005];
long long f[200005];
long long pot(long long first, long long second) {
  if (second == 0) return 1;
  long long sol = pot(first, second / 2);
  sol = (sol * sol) % MOD;
  if (second % 2) sol = (sol * first) % MOD;
  return sol;
}
long long div_(long long first, long long second) {
  return first * pot(second, MOD - 2) % MOD;
}
long long fact(long long first) {
  if (first == 0) return 1;
  if (f[first] != -1) return f[first];
  return f[first] = first * fact(first - 1) % MOD;
}
long long choose(long long first, long long second) {
  return div_(fact(first), fact(first - second) * fact(second) % MOD);
}
int main() {
  memset(f, -1, sizeof f);
  long long n, k;
  scanf("%I64d%I64d", &n, &k);
  long long second = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (i and a[i - 1] == a[i]) second++;
  }
  if (a[0] == a[n - 1]) second++;
  if (n == second) {
    printf("0\n");
    return 0;
  }
  long long first = n - second;
  long long br = 0;
  for (long long p = 0; p <= first / 2; p++) {
    br = (br + choose(first, p) * choose(first - p, p) % MOD *
                   pot(k - 2, first - p - p) % MOD * pot(k, second)) %
         MOD;
  }
  printf("%I64d\n", div_((MOD + pot(k, n) - br) % MOD, 2));
  return 0;
}
