#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long A = 0, B = 0, C = 0;
long long n, k;
vector<long long> h;
vector<long long> nxt(vector<long long> a) {
  vector<long long> b = {a.back()};
  for (long long i = 0; i < a.size() - 1; ++i) b.push_back(a[i]);
  return b;
}
long long get(vector<long long> a, vector<long long> b) {
  long long cnt = 0;
  for (long long i = 0; i < a.size(); ++i)
    if (a[i] == b[i]) ++cnt;
  return cnt;
}
void rec(vector<long long> a) {
  if (a.size() == n) {
    long long f = get(a, h), s = get(nxt(a), h);
    if (f == s)
      ++B;
    else if (f < s)
      ++A;
    else
      ++C;
    return;
  }
  for (long long i = 1; i <= k; ++i) {
    a.push_back(i);
    rec(a);
    a.pop_back();
  }
}
long long pow(long long n, long long st) {
  if (st == 0) return 1;
  long long v = pow(n, st / 2);
  v = v * v % MOD;
  if (st % 2) v = v * n % MOD;
  return v;
}
const long long N = 2e5 + 5;
long long pr[N], prr[N];
void build() {
  pr[0] = 1, prr[0] = 1;
  for (long long i = 1; i < N; ++i) {
    pr[i] = pr[i - 1] * i % MOD;
    prr[i] = prr[i - 1] * pow(i, MOD - 2) % MOD;
  }
}
long long getcnk(long long n) {
  if (n % 2) return 0;
  return (pr[n] * prr[n / 2]) % MOD * prr[n / 2] % MOD;
}
long long getcnk(long long n, long long k) {
  return (pr[n] * prr[k]) % MOD * prr[n - k] % MOD;
}
long long getpo(long long n) {
  if (n % 2 == 0) return n / 2;
  return (n + MOD) / 2;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  h.resize(n);
  for (long long& i : h) cin >> i;
  A = 0, B = 0, C = 0;
  for (long long i = 0; i < n; ++i) {
    long long j = (i + 1) % n;
    if (h[i] == h[j])
      ++C;
    else
      ++A;
  }
  build();
  long long ans = 0, all = pow(k, n);
  for (long long i = 0; i <= A; ++i) {
    long long nw = getcnk(A - i) * getcnk(A, A - i) % MOD;
    nw = nw * pow(k - 2, i) % MOD;
    nw = nw * pow(k, C) % MOD;
    ans += nw;
    ans %= MOD;
  }
  cout << getpo((all - ans + MOD) % MOD);
}
