#include <bits/stdc++.h>
using namespace std;
int N, M, K, a[200001], fc[200001], inv[200001], ans;
int pow(int a, int b) {
  int ans = 1;
  while (b)
    b& 1 ? ans = 1ll * ans * a % 998244353 : 0, a = 1ll * a * a % 998244353,
           b >>= 1;
  return ans;
}
int getans(int N, int M) {
  fc[0] = 1;
  for (int i = 1; i <= N; i++) fc[i] = 1ll * fc[i - 1] * i % 998244353;
  inv[N] = pow(fc[N], 998244353 - 2);
  for (int i = N - 1; i >= 0; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % 998244353;
  int ans = 0;
  for (int i = 0; i <= N / 2; i++)
    ans = (ans + 1ll * fc[N] * inv[N - i * 2] % 998244353 * inv[i] % 998244353 *
                     inv[i] % 998244353 * pow(M - 2, N - i * 2) % 998244353) %
          998244353;
  return 1ll * (pow(M, N) - ans + 998244353) * inv[2] % 998244353;
}
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> a[i];
  M = unique(a + 1, a + N + 1) - a - 1;
  if (a[M] == a[1]) M--;
  cout << 1ll * pow(K, N - M) * getans(M, K) % 998244353 << endl;
  return 0;
}
