#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 239;
const long long MOD = 998244353;
long long add(long long a, long long b) {
  a %= MOD;
  b %= MOD;
  return (a + b) % MOD;
}
long long mul(long long a, long long b) {
  a %= MOD;
  b %= MOD;
  return (a * b) % MOD;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
long long divv(long long a, long long b) { return mul(a, binpow(b, MOD - 2)); }
long long F[MAXN];
void init() {
  F[0] = 1;
  for (long long i = 1; i < MAXN; i++) {
    F[i] = mul(F[i - 1], i);
  }
}
long long C(long long n, long long k) {
  return divv(F[n], mul(F[n - k], F[k]));
}
long long solve(long long x, long long k) {
  long long ans = 0;
  for (long long i = 0; 2 * i <= x; i++) {
    long long f = C(x, 2 * i);
    long long s = C(2 * i, i);
    long long all = mul(f, s);
    long long left = x - 2 * i;
    long long cur = mul(all, binpow(k - 2, left));
    ans = add(ans, cur);
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  init();
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    exit(0);
  }
  long long nm = 0;
  long long m = 0;
  vector<long long> a(n);
  for (auto &t : a) {
    cin >> t;
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] == a[(i + 1) % n]) {
      nm++;
    } else {
      m++;
    }
  }
  long long all = binpow(k, m);
  all -= solve(m, k);
  all += MOD;
  all %= MOD;
  all = divv(all, 2);
  cout << mul(all, binpow(k, nm)) << endl;
}
