#include <bits/stdc++.h>
using namespace std;
long long inv(long long a, long long mod) {
  long long b = mod, p = 1, q = 0;
  while (b) {
    long long c = a / b, d = a;
    a = b;
    b = d % b;
    d = p;
    p = q;
    q = d - c * q;
  }
  return (p + mod) % mod;
}
int fs = 505050;
vector<long long> fact(fs), ifact(fs);
long long binom(int a, int b, long long mod) {
  if (a < b) return 0;
  return fact[a] * ifact[b] % mod * ifact[a - b] % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long k;
  cin >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long mod = 998244353;
  fact[0] = 1;
  for (int i = 1; i < fs; i++) fact[i] = fact[i - 1] * i % mod;
  ifact[fs - 1] = inv(fact[fs - 1], mod);
  for (int i = fs - 1; i > 0; i--) ifact[i - 1] = ifact[i] * i % mod;
  long long res = 0;
  int same = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[(i + n - 1) % n]) same++;
  }
  int x = n - same;
  if (x & 1) {
    long long coef = k - 2;
    for (int i = 1; i <= x; i += 2) {
      res +=
          binom(x, i, mod) * coef % mod * binom(x - i, (x - i) / 2, mod) % mod;
      res %= mod;
      coef = coef * (k - 2) % mod * (k - 2) % mod;
    }
  } else {
    long long coef = 1;
    for (int i = 0; i <= x; i += 2) {
      res +=
          binom(x, i, mod) * coef % mod * binom(x - i, (x - i) / 2, mod) % mod;
      res %= mod;
      coef = coef * (k - 2) % mod * (k - 2) % mod;
    }
  }
  for (int i = 0; i < same; i++) {
    res = res * k % mod;
  }
  long long ent = 1;
  for (int i = 0; i < n; i++) {
    ent = ent * k % mod;
  }
  res = (ent - res + mod) % mod;
  res = res * ((mod + 1) / 2) % mod;
  cout << res << "\n";
  return 0;
}
