#include <bits/stdc++.h>
using namespace std;
int reformed[200000 + 1];
int fact[200000 + 1];
int two[200000 + 1];
int h[200000 + 1];
int free_pos;
int N, M, K;
void Precalc() {
  two[0] = fact[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    two[i] = (2LL * two[i - 1]) % 998244353;
    fact[i] = (1LL * i * fact[i - 1]) % 998244353;
  }
}
int lgPow(int X, int B) {
  int A = 1;
  while (B > 0) {
    if (B % 2) A = (1LL * A * X) % 998244353;
    X = (1LL * X * X) % 998244353;
    B /= 2;
  }
  return A;
}
int getComb(int N, int K) {
  int inv1 = lgPow(fact[K], 998244353 - 2);
  int inv2 = lgPow(fact[N - K], 998244353 - 2);
  int temp = (1LL * fact[N] * inv1) % 998244353;
  return (1LL * temp * inv2) % 998244353;
}
int computePositiveSum(int X) {
  if (X % 2 == 1) {
    return two[X - 1];
  } else {
    int temp = (two[X] - getComb(X, X / 2) + 998244353) % 998244353;
    int inv = lgPow(2, 998244353 - 2);
    return (1LL * temp * inv) % 998244353;
  }
}
void Modify() {
  for (int i = 1; i < N; i++)
    if (h[i] != h[i + 1]) reformed[++M] = h[i];
  if (h[N] != h[1]) reformed[++M] = h[N];
  free_pos = N - M;
  N = M;
  for (int i = 1; i <= N; i++) h[i] = reformed[i];
}
int main() {
  Precalc();
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> h[i];
  Modify();
  if (K == 1) {
    cout << 0 << "\n";
  } else if (K == 2) {
    cout << (1LL * lgPow(K, free_pos) * computePositiveSum(N)) % 998244353;
  } else {
    int res = computePositiveSum(N);
    for (int i = 1; i < N; i++) {
      int coeff = (1LL * getComb(N, i) * lgPow(K - 2, i)) % 998244353;
      res = (res + 1LL * computePositiveSum(N - i) * coeff) % 998244353;
    }
    cout << (1LL * lgPow(K, free_pos) * res) % 998244353;
  }
  return 0;
}
