#include <bits/stdc++.h>
using namespace std;
int Fact[200005], A[200005], Inv[200005];
int put(int a, int b) {
  int rez = 1;
  for (int i = 0; (1 << i) <= b; i++) {
    if ((1 << i) & b) rez = (1LL * rez * a) % 998244353;
    a = (1LL * a * a) % 998244353;
  }
  return rez;
}
int comb(int n, int k) {
  int rez = (1LL * Fact[n] * Inv[k]) % 998244353;
  rez = (1LL * rez * Inv[n - k]) % 998244353;
  return rez;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  int dif = 0;
  for (int i = 1; i <= n; i++)
    if (A[i] != A[i % n + 1]) dif++;
  Fact[0] = 1;
  for (int i = 1; i <= n; i++) Fact[i] = (1LL * Fact[i - 1] * i) % 998244353;
  Inv[n] = put(Fact[n], 998244353 - 2);
  for (int i = n - 1; i >= 0; i--)
    Inv[i] = (1LL * Inv[i + 1] * (i + 1)) % 998244353;
  int rez = 0;
  for (int i = 0; i < dif; i++) {
    int aux = put(k, n - dif);
    aux = (1LL * aux * comb(dif, i)) % 998244353;
    aux = (1LL * aux * put(k - 2, i)) % 998244353;
    if ((dif - i) % 2 == 1)
      aux = (1LL * aux * put(2, dif - i - 1)) % 998244353;
    else {
      aux = (1LL * aux *
             ((put(2, dif - i) - comb(dif - i, (dif - i) / 2) + 998244353) %
              998244353)) %
            998244353;
      aux = (1LL * aux * put(2, 998244353 - 2)) % 998244353;
    }
    rez = (rez + aux) % 998244353;
  }
  cout << rez << "\n";
  return 0;
}
