#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 998244353;
const int64_t N = 2e5 + 5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int64_t mpow(int64_t x, int64_t y) {
  if (y == 0) return 1;
  int64_t temp = mpow(x, y / 2);
  temp *= temp;
  temp %= MOD;
  if (y & 1) return (x * temp) % MOD;
  return temp;
}
int64_t inverse(int64_t x) { return mpow(x, MOD - 2); }
int64_t fact[N], ifact[N];
int64_t nCr(int64_t n, int64_t r) {
  int64_t ans = fact[n];
  ans *= ifact[r];
  ans %= MOD;
  ans *= ifact[n - r];
  ans %= MOD;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fact[0] = 1;
  ifact[0] = 1;
  for (int64_t i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    ifact[i] = inverse(fact[i]);
  }
  int64_t n, k;
  cin >> n >> k;
  int64_t arr[n];
  for (int64_t i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int64_t equal = 0;
  for (int64_t i = 0; i < n; i++) {
    if (arr[i] == arr[(i + 1) % n]) equal++;
  }
  int64_t ans = mpow(k, equal);
  int64_t ans2 = 0;
  for (int64_t i = 0; i <= n - equal - 1; i++) {
    int64_t lol = mpow(k - 2, i);
    if ((n - equal - i) % 2 == 1) {
      lol *= mpow(2, n - equal - i - 1);
      lol %= MOD;
    } else {
      int64_t rem = mpow(2, n - equal - i);
      rem -= nCr(n - equal - i, (n - equal - i + 1) / 2);
      rem = rem + 10 * MOD;
      rem %= MOD;
      rem *= inverse(2);
      rem %= MOD;
      lol *= rem;
      lol %= MOD;
    }
    lol *= nCr(n - equal, i);
    lol %= MOD;
    ans2 += lol;
    ans2 %= MOD;
  }
  ans *= ans2;
  ans %= MOD;
  cout << ans;
  return 0;
}
