#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 3;
long long n, h[N];
long long k, fact[N], dp[N];
long long fpow(long long a, long long p) {
  if (p == 0) return 1;
  long long b = fpow(a, p / 2);
  b = (b * b) % mod;
  if (p % 2 == 0) {
    return b;
  } else {
    return b * a % mod;
  }
}
long long inv(long long a) { return fpow(a, mod - 2); }
long long bc(long long a, long long b) {
  return fact[a] * inv(fact[b]) % mod * inv(fact[a - b]) % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  fact[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  long long cnt_same = 0, cnt_diff = 0;
  long long free = 1;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (h[i] == h[(i + 1) % n]) {
      cnt_same++;
    } else {
      cnt_diff++;
    }
  }
  for (int i = 0; i < cnt_same; ++i) {
    free *= k;
    free %= mod;
  }
  dp[1] = dp[2] = 1;
  for (long long i = 3; i <= cnt_diff; ++i) {
    if (i % 2 == 0) {
      dp[i] = (dp[i - 1] * 2LL % mod - bc(i - 1, i / 2) + mod) % mod;
    } else {
      dp[i] = (dp[i - 1] * 2LL % mod + bc(i - 1, i / 2) + mod) % mod;
    }
  }
  for (long long i = 0; i < cnt_diff; ++i) {
    ans += fact[cnt_diff] * inv(fact[i]) % mod * inv(fact[cnt_diff - i]) % mod *
           fpow(k - 2, i) % mod * dp[cnt_diff - i] % mod;
    ans %= mod;
  }
  cout << ans * free % mod;
}
