#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 5;
long long qpow(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
long long fac[N], inv[N];
long long c(long long n, long long m) {
  if (m > n || m < 0) return 0;
  if (m == 0 || m == n) return 1;
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int a[N];
int main() {
  fac[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);
  int n, num = 0;
  long long k;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[0] = a[n];
  for (int i = 1; i <= n; i++) num += a[i] != a[i - 1];
  long long sum = 0;
  for (long long i = 0; i <= num / 2; i++)
    sum = (sum + c(num, i) * c(num - i, i) % mod * qpow(k - 2, num - 2 * i) %
                     mod * qpow(k, n - num)) %
          mod;
  sum = (qpow(k, n) - sum + mod) * qpow(2, mod - 2) % mod;
  printf("%lld\n", sum);
  return 0;
}
