#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int power(int a, int n = (int)(998244353) - 2) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = ret * 1ll * a % (int)(998244353);
    a = a * 1ll * a % (int)(998244353);
    n >>= 1;
  }
  return ret;
}
const int N = 200005;
int F[N], I[N];
inline int comb(int n, int k) {
  return (I[k] * 1ll * I[n - k] % (int)(998244353)) * F[n] % (int)(998244353);
}
void prep() {
  F[0] = I[0] = 1;
  for (int i = 1; i < N; i++) {
    F[i] = F[i - 1] * 1ll * i % (int)(998244353);
    I[i] = power(F[i]);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, i, j, k;
  cin >> n >> k;
  prep();
  int h[n];
  for (i = 0; i < n; i++) cin >> h[i];
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  int count = 0;
  for (i = 0; i < n; i++)
    if (h[i] != h[(i + 1) % n]) count++;
  long long int ans = 1;
  for (i = 1; i <= n - count; i++) ans = ans * k % (int)(998244353);
  long long int t = 1ll;
  for (i = 1; i <= count; i++) t = t * k % (int)(998244353);
  if (k == 2) {
    if (count % 2 == 0)
      t = (t + (int)(998244353) - comb(count, count / 2)) % (int)(998244353);
    t = (t * 1ll * I[2]) % (int)(998244353);
    cout << ans * t % (int)(998244353) << endl;
    return 0;
  }
  for (i = 0; 2 * i <= count; i++) {
    int d = ((I[i] * 1ll * I[i] % (int)(998244353)) * 1ll * I[count - 2 * i] %
             (int)(998244353)) *
            1ll * F[count] % (int)(998244353);
    d = d * 1ll * power(k - 2, count - 2 * i) % (int)(998244353);
    t = (t + (int)(998244353) - d) % (int)(998244353);
  }
  t = (t * 1ll * I[2]) % (int)(998244353);
  cout << ans * t % (int)(998244353) << endl;
}
