#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
long long fact[401000];
long long invfact[401000];
long long pow2[401000];
long long binpow(long long x, int pwr) {
  if (pwr < 0) return 0;
  if (pwr == 0) return 1;
  if (pwr % 2 == 0) {
    long long tmp = binpow(x, pwr / 2);
    return (tmp * tmp) % 998244353;
  }
  return (x * binpow(x, pwr - 1)) % 998244353;
}
long long inv(long long x) { return binpow(x, 998244353 - 2); }
long long binco(int n, int k) {
  long long tmp = fact[n] * invfact[k];
  tmp = tmp % 998244353;
  return (tmp * invfact[n - k]) % 998244353;
}
long long less_half_sum(long long n) {
  if (n == 1) return 1;
  if (n % 2 == 0) {
    long long total = pow2[n] + 998244353 - binco(n, (n) / 2);
    return (total * inv(2)) % 998244353;
  } else {
    long long total = pow2[n - 1];
    return total;
  }
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  int n;
  long long k;
  cin >> n >> k;
  vector<int> hh(n);
  for (int i = 0; i < n; i++) {
    cin >> hh[i];
  }
  fact[0] = 1;
  invfact[0] = inv(1);
  for (long long i = 1; i < 401000; i++) {
    fact[i] = (fact[i - 1]) * i;
    fact[i] = fact[i] % 998244353;
    invfact[i] = inv(fact[i]);
  }
  pow2[0] = 1;
  for (long long i = 1; i < 401000; i++) {
    pow2[i] = (pow2[i - 1]) * 2;
    pow2[i] = pow2[i] % 998244353;
  }
  long long eq = 0, neq = 0;
  for (int i = 1; i <= n; i++) {
    int first = hh[i - 1];
    int second = hh[(i + n - 2) % n];
    second = hh[(i + n) % n];
    if (first == second)
      eq++;
    else
      neq++;
  }
  long long ans = 0;
  for (long long i = 1; i <= neq; i++) {
    long long curr = less_half_sum(i);
    curr *= binco(neq, i);
    curr = (curr % 998244353);
    curr *= binpow(k - 2, neq - i);
    curr = (curr % 998244353);
    ans = (ans + curr) % 998244353;
  }
  cout << (ans * binpow(k, eq)) % 998244353;
  return 0;
}
