#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int root = 5;
int pow_mod(int a, int n) {
  int r = 1;
  for (; n; n >>= 1) {
    if (n & 1) r = (long long)r * a % mod;
    a = (long long)a * a % mod;
  }
  return r;
}
void ntt(int a[], int n, int sign) {
  for (int i = 1, j = 0; i < n - 1; ++i) {
    for (int k = n >> 1; (j ^= k) < k; k >>= 1)
      ;
    if (i < j) swap(a[i], a[j]);
  }
  vector<int> roots(n);
  for (int mh = 1; mh << 1 <= n; mh <<= 1) {
    int wm = pow_mod(root, (mod - 1) / (mh << 1));
    roots[mh] = 1;
    for (int i = 1; i < mh; ++i)
      roots[i + mh] = (long long)roots[i + mh - 1] * wm % mod;
  }
  for (int m, mh = 1; (m = mh << 1) <= n; mh = m) {
    for (int i = 0; i < n; i += m)
      for (int j = i; j < i + mh; ++j) {
        int x = a[j], y = (long long)a[j + mh] * roots[mh + j - i] % mod;
        a[j] = x + y;
        a[j + mh] = x - y;
        if (a[j] >= mod) a[j] -= mod;
        if (a[j + mh] < 0) a[j + mh] += mod;
      }
  }
  if (sign < 0) {
    int inv = pow_mod(n, mod - 2);
    for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * inv % mod;
    reverse(a + 1, a + n);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (auto &i : h) cin >> i;
  if (k == 1) {
    cout << "0\n";
    return 0;
  }
  vector<int> a = {1, (k - 2) % mod, 1};
  int e = 0;
  for (int i = 0; i < n; ++i) {
    int hn = h[(i + 1) % n];
    if (h[i] != hn) ++e;
  }
  if (!e)
    a = {1};
  else {
    int sz = 1;
    while (sz <= 2 * e) sz *= 2;
    a.resize(sz, 0);
    ntt(a.data(), sz, +1);
    for (int i = 0; i < sz; ++i) a[i] = pow_mod(a[i], e);
    ntt(a.data(), sz, -1);
  }
  int c = pow_mod(k % mod, n - e);
  vector<int> ans(n - e);
  for (auto i : a) ans.push_back((long long)i * c % mod);
  int ret = 0;
  for (int i = ans.size() - 1; i > n; --i)
    ret = ((long long)ret + ans[i]) % mod;
  cout << ret << "\n";
  return 0;
}
