#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int sz = 3e5;
long long n, k;
long long h[sz], f[sz], invf[sz];
long long mpw(long long b, long long e) {
  if (!e) return 1;
  long long tmp = mpw(b, e >> 1);
  tmp *= tmp;
  tmp %= mod;
  if (e & 1) {
    tmp *= b;
    tmp %= mod;
  }
  return tmp;
}
void prec() {
  f[0] = 1;
  for (int i = 1; i < sz; i++) f[i] = (f[i - 1] * i) % mod;
  invf[sz - 1] = mpw(f[sz - 1], mod - 2);
  for (int i = sz - 2; i >= 0; i--) invf[i] = (invf[i + 1] * (i + 1)) % mod;
}
inline long long mul(const long long &lhs, const long long &rhs) {
  return ((lhs % mod) * (rhs % mod)) % mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  bool eq = 1;
  prec();
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    eq &= (i ? (h[i - 1] == h[i]) : 1);
  }
  if (eq) {
    cout << 0 << '\n';
    return 0;
  }
  long long free = 0, no = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n])
      free++;
    else
      no++;
  }
  long long x = 0;
  k -= 2;
  for (int i = 0; 2 * i <= no; i++) {
    long long tmp = f[no];
    tmp = mul(tmp, invf[i]);
    tmp = mul(tmp, invf[i]);
    tmp = mul(tmp, invf[no - 2 * i]);
    tmp = mul(tmp, mpw(k, no - 2 * i));
    x += tmp;
    x %= mod;
  }
  long long ret = mpw(k + 2, free);
  long long t2 = ((mpw(k + 2, no) - x) % mod + mod) % mod;
  ret = mul(ret, t2);
  ret = mul(ret, mpw(2, mod - 2));
  cout << ret << '\n';
  return 0;
}
