#include <bits/stdc++.h>
using namespace std;
;
const long long MOD = 998244353;
inline void normal(long long &a) { a = (a + MOD) % MOD; }
inline long long modMul(long long a, long long b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline long long modAdd(long long a, long long b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline long long modSub(long long a, long long b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInv(long long a) { return modPow(a, MOD - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInv(b));
}
const long long N = 2e5 + 10;
long long fac[N], inv[N];
long long ncr(long long n, long long r) {
  return modMul(fac[n], modMul(inv[n - r], inv[r]));
}
void pre() {
  fac[0] = inv[0] = 1;
  for (long long i = 1; i < N; i++) {
    fac[i] = modMul(fac[i - 1], i);
    inv[i] = modMul(inv[i - 1], modInv(i));
  }
}
void solve() {
  long long n, k, ans = 0;
  cin >> n >> k;
  long long h[n];
  for (long long i = 0; i < n; i++) {
    cin >> h[i];
  }
  long long m = n;
  for (long long i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n]) m--;
  }
  if (k == 1) {
    cout << 0 << '\n';
    return;
  }
  for (long long i = 1; i <= m; i++) {
    long long x = ncr(m, i);
    x = modMul(x, modPow(k - 2, m - i));
    if (i % 2 == 1) {
      x = modMul(x, modPow(2, i - 1));
    } else {
      x = modMul(x, modDiv(modSub(modPow(2, i), ncr(i, i / 2)), 2));
    }
    ans = modAdd(ans, x);
  }
  cout << modMul(ans, modPow(k, n - m)) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  clock_t start, end;
  start = clock();
  cout << fixed << setprecision(15);
  pre();
  while (t--) {
    solve();
  }
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
