#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int MAXN = 2e5 + 100;
long long stab(long long a) { return ((a % MOD + MOD) % MOD); }
array<long long, MAXN> fact;
array<long long, MAXN> obr_fac;
long long pw(long long a, long long b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    return pw((a * a) % MOD, b / 2);
  } else {
    return (a * pw(a, b - 1)) % MOD;
  }
}
long long obr(long long a) { return pw(a, MOD - 2); }
long long c_n_k(long long n, long long k) {
  return (((fact[n] * obr_fac[k]) % MOD) * obr_fac[n - k]) % MOD;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  fact[0] = 1;
  obr_fac[0] = 1;
  for (long long i = 1; i < MAXN; ++i) {
    fact[i] = stab(fact[i - 1] * i);
    obr_fac[i] = obr(fact[i]);
  }
  long long n, k;
  cin >> n >> k;
  vector<long long> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  long long c1 = 0;
  for (int i = 0; i < n; ++i) {
    int j = (i + 1) % n;
    if (vec[i] != vec[j]) {
      c1++;
    }
  }
  long long ans = 0;
  long long o2 = obr(2);
  long long op = pw(k, n - c1);
  for (long long i = 1; i <= c1; ++i) {
    long long cur = 0;
    if (i % 2 == 1) {
      cur = (pw(2, i) * o2) % MOD;
    } else {
      cur = ((pw(2, i) - c_n_k(i, (i / 2))) * o2) % MOD;
    }
    cur *= (op * pw(k - 2, c1 - i)) % MOD;
    cur %= MOD;
    cur *= c_n_k(c1, i);
    cur %= MOD;
    ans += cur;
  }
  ans = stab(ans);
  cout << ans << endl;
  return 0;
}
