#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.first << ',' << P.second << ')';
}
long long int modpow(long long int a, long long int n,
                     long long int m = 998244353) {
  long long int ans = 1;
  while (n) {
    if (n % 2) ans = ((long long)ans * a) % m;
    a = ((long long)a * a) % m;
    n /= 2;
  }
  return ans;
}
long long int inv(long long int a, long long int m = 998244353) {
  return modpow(a, m - 2, m);
}
long long int fact[200005 + 1], ifact[200005 + 1];
void ini_fact() {
  fact[0] = ifact[0] = 1;
  for (long long int i = 1; i <= 200005; i++) {
    fact[i] = ((long long)fact[i - 1] * i) % 998244353;
    ifact[i] = inv(fact[i]);
  }
}
long long int c(long long int n, long long int r) {
  return ((((long long)fact[n] * ifact[r]) % 998244353) *
          (long long)ifact[n - r]) %
         998244353;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ini_fact();
  long long int n;
  cin >> n;
  long long int k;
  cin >> k;
  vector<long long int> a(n);
  for (long long int i = 0; i < (n); i++) cin >> a[i];
  long long int ct = 0;
  for (long long int i = 0; i < (n); i++) {
    ct += (a[i] != a[(i + 1) % n]);
  }
  long long int ans = 0;
  for (long long int x = 0; x <= ct; x += 2) {
    long long int y = ct - x;
    long long int tans = (c(x, x / 2) * modpow(k - 2, y)) % 998244353;
    tans *= c(ct, x);
    ans += tans % 998244353;
    ans %= 998244353;
  }
  ans *= modpow(k, n - ct);
  ans %= 998244353;
  ans = modpow(k, n) - ans;
  ans %= 998244353;
  ans *= inv(2);
  ans %= 998244353;
  ans += 998244353;
  cout << ans % 998244353 << '\n';
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  ;
}
