#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9 + 9;
const int MAXN = 1000006;
int n, m, k, arr[MAXN], good, bad;
bool feasible = true;
string s;
char c, t[MAXN], C[MAXN];
ll binPow(ll b, ll e) {
  ll r = 1;
  while (e > 0) {
    if (e & 1) {
      r = r * b % MOD;
    }
    b = b * b % MOD;
    e >>= 1;
  }
  return r;
}
inline ll inv(ll b) { return binPow(b, MOD - 2); }
ll NchooseK(ll n, ll k) {
  ll r = 1;
  for (int i = 2; i <= n; i++) {
    if (i > k) r = r * i % MOD;
    if (i <= n - k) r = r * inv(i) % MOD;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i < n; i++) {
    if (arr[i] == arr[i - 1]) {
      m++;
    }
  }
  if (arr[0] == arr[n - 1]) m++;
  n -= m;
  ll ans = 0;
  ll nci = 1, mci = 1, potk = binPow(k - 2, n);
  for (int i = 0; i <= n / 2; i++) {
    ans = (ans + nci * mci % MOD * binPow(k - 2, n - i - i) % MOD) % MOD;
    nci = nci * inv(i + 1) % MOD;
    mci = mci * (n - 2 * i) % MOD * (n - 2 * i - 1) % MOD * inv(i + 1) % MOD;
  }
  ans = (binPow(k, n) + MOD - ans) % MOD * inv(2) % MOD;
  cout << binPow(k, m) * ans % MOD << endl;
}
