#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const long long N = 3e5 + 5;
const long long oo = 998244353;
long long bigmod(long long a, long long p, long long m) {
  long long res = 1;
  long long x = a;
  while (p) {
    if (p & 1) {
      res = (res * x) % m;
    }
    x = (x * x) % m;
    p = p >> 1;
  }
  return res;
}
long long h[N];
long long fact[N];
long long fact_inv[N];
long long ncr(long long n, long long r) {
  long long ret = 1;
  ret = ret * fact[n] % oo;
  ret = ret * fact_inv[r] % oo;
  ret = ret * fact_inv[n - r] % oo;
  return ret;
}
long long get(long long khali) {
  if (khali <= 0) return 0;
  long long ret = bigmod(2, khali, oo);
  if (khali % 2) {
  } else {
    ret = (ret - ncr(khali, khali / 2) + oo) % oo;
  }
  ret = (ret * bigmod(2, oo - 2, oo)) % oo;
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  fact[0] = 1;
  for (long long i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % oo;
  fact_inv[N - 1] = bigmod(fact[N - 1], oo - 2, oo);
  for (long long i = N - 2; i >= 0; i--)
    fact_inv[i] = ((i + 1) * fact_inv[i + 1]) % oo;
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> h[i];
  long long same = 0;
  for (long long i = 0; i < n; i++) same += h[i] == h[(i + 1) % n];
  long long ans = 0;
  n -= same;
  for (long long x = 0; x < n; x++) {
    ans = (ans + ((bigmod(k - 2, x, oo) * get(n - x)) % oo * ncr(n, x)) % oo) %
          oo;
  }
  ans = ans * bigmod(k, same, oo) % oo;
  if (ans < 0) ans += oo;
  cout << ans << "\n";
}
