#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = 998244353;
int n, k, diff, a[N];
long long f[N], ans;
long long fpow(long long base, long long expo) {
  long long ans = 1LL;
  while (expo) {
    if (expo & 1LL) ans = (ans * base) % M;
    base = (base * base) % M;
    expo >>= 1LL;
  }
  return ans;
}
long long C(long long a, long long b) {
  long long ans = f[a];
  ans *= fpow(f[b] * f[a - b] % M, M - 2LL) % M;
  return ans % M;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) diff += a[i] != a[(i - 1 + n) % n];
  f[0] = 1LL;
  for (int i = 1; i <= n; ++i) f[i] = (f[i - 1] * i * 1LL) % M;
  for (int m = 1; m <= diff; ++m) {
    long long t = C(diff, m) * fpow(k - 2LL, diff - m) % M;
    long long x = (fpow(2LL, m) - (m & 1 ? 0LL : C(m, m >> 1LL)) + M) % M;
    x = (x * fpow(2LL, M - 2LL)) % M;
    t = (t * x) % M;
    ans = (ans + t) % M;
  }
  ans = (ans * fpow(k, n - diff)) % M;
  cout << ans;
}
