#include <bits/stdc++.h>
using namespace std;
long long n, k, same, diff, ar[200005], fr[400010], inv[400010];
long long coff(long long), ncr(long long, long long), ifsame(long long),
    func(long long, long long);
void pre();
int main() {
  pre();
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", &ar[i]);
  for (int i = 0; i < n; i++) {
    if (ar[i] == ar[(i + 1) % n])
      same++;
    else
      diff++;
  }
  long long ans = 0;
  for (int i = 1; i < diff + 1; i++) {
    ans += ((coff(i) - ifsame(i)) * func(k - 2, diff - i) % 998244353 * inv[2] %
                998244353 +
            998244353) %
           998244353;
    ans %= 998244353;
  }
  cout << (ans * func(k, same)) % 998244353;
}
void pre() {
  fr[0] = inv[0] = 1;
  for (int i = 1; i < 400010; i++) {
    fr[i] = (fr[i - 1] * i) % 998244353;
    inv[i] = func(fr[i], 998244353 - 2);
  }
}
long long coff(long long i) {
  long long n = diff;
  return ncr(diff, i) * func(2, i) % 998244353;
}
long long ifsame(long long i) {
  long long n = diff;
  if (i % 2) return 0;
  return ncr(n, i) * ncr(i, i / 2) % 998244353;
}
long long ncr(long long n, long long r) {
  return fr[n] * inv[n - r] % 998244353 * inv[r] % 998244353;
}
long long func(long long num, long long k) {
  if (k == 0) return 1;
  long long ans = func(num, k / 2);
  ans = (ans * ans) % 998244353;
  if (k % 2) ans = (ans * num) % 998244353;
  return ans;
}
