#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
long long expo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 1) res = (res * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return res;
}
long long fact[200001];
long long ncr(long long n, long long r) {
  if (n < r) return 0;
  long long vv = (expo(fact[r], M - 2) * expo(fact[n - r], M - 2)) % M;
  return (vv * fact[n]) % M;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  fact[0] = 1;
  for (long long i = 1, ll = 1; i <= n; i++) {
    fact[i] = (ll * i) % M;
    ll = fact[i];
  }
  long long x = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] != a[(i + 1) % n]) x++;
  }
  if (k == 1) {
    cout << 0;
    return;
  }
  long long ans1 = 1, ans = 0, vx = expo(2, M - 2);
  ;
  for (long long i = 0; i < n - x; i++) ans1 = (ans1 * k) % M;
  if (k == 2) {
    long long val = expo(2, x);
    if (x % 2 == 0) {
      long long tmp = val - ncr(x, x / 2);
      if (tmp < 0) tmp += M;
      val = (tmp * vx) % M;
    } else
      val = (val * vx) % M;
    cout << (val * ans1) % M;
    return;
  }
  for (long long i = 0, vv = 1; i < x; i++, vv = (vv * (k - 2)) % M) {
    long long val = expo(2, x - i);
    if ((x - i) % 2 == 0) {
      long long tmp = val - ncr(x - i, (x - i) / 2);
      if (tmp < 0) tmp += M;
      val = (tmp * vx) % M;
    } else
      val = (val * vx) % M;
    val = (val * ncr(x, i)) % M;
    ans += (vv * val) % M;
    if (ans >= M) ans -= M;
  }
  cout << (ans * ans1) % M;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
