#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const vector<int> mods = {998244353, 1000000007, 1000000009};
const long long inf = 3e18;
const double pi = acos(-1.0);
const double eps = 0.0000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class... K>
using umap = unordered_map<K...>;
template <class... K>
using uset = unordered_set<K...>;
long long inv(long long a, long long b) {
  return a > 1 ? b - inv(b % a, a) * b / a : 1;
}
long long modpow(long long b, long long e) {
  long long ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1) ans = ans * b % mod;
  return ans;
}
long long n, k, fct[200100], ift[200100], pt[200100], pt2[200100];
vector<long long> a;
long long nd = 1, opts;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.precision(12);
  cin >> n >> k;
  fct[0] = 1;
  ift[0] = 1;
  pt[0] = 1;
  pt2[0] = 1;
  for (long long i = (1); i < (200100 - 10); ++i) {
    fct[i] = (i * fct[i - 1]) % mod;
    ift[i] = inv(fct[i], mod);
    pt[i] = (pt[i - 1] * (k - 2)) % mod;
    pt2[i] = (pt2[i - 1] * 2) % mod;
  }
  a.resize(n);
  for (long long i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  for (long long i = (0); i < (n); ++i) {
    long long nx = (i + 1) % n;
    if (a[i] != a[nx]) {
      opts++;
    } else {
      nd = (nd * k) % mod;
    }
  }
  long long res = 0;
  long long inv2 = inv(2, mod);
  for (long long i = (0); i < (opts + 1); ++i) {
    long long mi_ = fct[opts] % mod * ift[i] % mod;
    mi_ = mi_ * ift[opts - i] % mod;
    mi_ = (mi_ * pt[opts - i]) % mod;
    if (i & 1)
      mi_ = mi_ * (pt2[i - 1]) % mod;
    else {
      long long c = fct[i] * ift[i / 2] % mod * ift[i / 2] % mod;
      c = ((pt2[i] - c) % mod + mod) % mod;
      c = c * inv2 % mod;
      mi_ = mi_ * c % mod;
    }
    res = (res + mi_) % mod;
  }
  res = (res * nd) % mod;
  cout << res << "\n";
  return 0;
}
