#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAXN = 1e6 + 10;
long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return sum;
}
int a[MAXN], b[MAXN];
int fac[MAXN], rfac[MAXN], inv[MAXN];
int C(int n, int m) {
  if (n - m < m) m = n - m;
  if (m == 0) return 1;
  return 1ll * fac[n] * rfac[m] % MOD * rfac[n - m] % MOD;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fac[1] = rfac[1] = inv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
  for (int i = 2; i < MAXN; i++)
    fac[i] = 1ll * fac[i - 1] * i % MOD,
    rfac[i] = 1ll * rfac[i - 1] * inv[i] % MOD;
  int n, k, num = 0, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (k == 1) return cout << 0 << endl, 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i % n + 1]) num++;
  for (int i = 0; 2 * i <= num; i++)
    ans = (ans + 1ll * C(num, i) * C(num - i, i) % MOD *
                     qpow(k - 2, num - 2 * i) % MOD * qpow(k, n - num) % MOD) %
          MOD;
  cout << (qpow(k, n) - ans + MOD) % MOD * inv[2] % MOD << endl;
  return 0;
}
