#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 1) {
    return (pow(a, b - 1) * a) % mod;
  } else {
    long long y = pow(a, b / 2);
    return (y * y) % mod;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  long long h[n];
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  long long hh[n];
  hh[n - 1] = h[0];
  for (int j = n - 2; j >= 0; --j) {
    hh[j] = h[j + 1];
  }
  long long eq = 0;
  vector<long long> a;
  vector<long long> aa;
  for (int i = 0; i < n; ++i) {
    if (h[i] == hh[i]) {
      eq++;
    } else {
      a.push_back(h[i]);
      aa.push_back(hh[i]);
    }
  }
  if (a.size() == 0) {
    cout << 0;
    exit(0);
  }
  long long cnt1[a.size() + 1];
  long long cnt2[a.size() + 1];
  cnt1[0] = 1;
  cnt2[0] = 1;
  for (long long i = 2; i < a.size() + 1; ++i) {
    long long nn = i - 2;
    if (i % 2 == 0) {
      cnt1[i] =
          (((cnt1[i - 2] * (nn + 2)) % mod) *
           (((nn + 1) * pow((((nn / 2) + 1) * ((nn / 2) + 1)) % mod, mod - 2)) %
            mod)) %
          mod;
    }
  }
  for (long long i = 1; i < a.size() + 1; ++i) {
    long long nn = i - 1;
    cnt2[i] =
        (cnt2[i - 1] * (((a.size() - nn) * pow(nn + 1, mod - 2)) % mod)) % mod;
  }
  long long ans = 0;
  for (long long cnt = 0; cnt <= a.size(); ++cnt) {
    long long x = a.size() - cnt;
    long long res = 0;
    if (x % 2 == 1) {
      res = pow(2ll, x - 1);
    } else {
      res = (((pow(2ll, x) - cnt1[x] + mod) % mod) * pow(2ll, mod - 2)) % mod;
    }
    ans += ((res * pow(k - 2, cnt)) % mod * cnt2[cnt]) % mod;
    ans %= mod;
  }
  cout << (ans * pow(k, eq)) % mod;
}
