#include <bits/stdc++.h>
using namespace std;
template <typename TYPE>
inline void chkmax(TYPE &first, TYPE second) {
  first < second ? first = second : 0;
}
template <typename TYPE>
inline void chkmin(TYPE &first, TYPE second) {
  second < first ? first = second : 0;
}
template <typename TYPE>
void readint(TYPE &first) {
  first = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
  first *= f;
}
const int MAXN = 200005, MOD = 998244353;
long long qmi(long long first, long long second) {
  long long ans = 1;
  for (; second; second >>= 1, first = first * first % MOD)
    if (second & 1) ans = ans * first % MOD;
  return ans;
}
int a[MAXN];
long long n, m, fac[MAXN], k, invf[MAXN];
int main() {
  readint(n);
  readint(k);
  for (int i = 1; i <= n; ++i) readint(a[i]);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % MOD;
  invf[n] = qmi(fac[n], MOD - 2);
  for (int i = n - 1; i >= 0; --i) invf[i] = invf[i + 1] * (i + 1) % MOD;
  a[0] = a[n];
  for (int i = 1; i <= n; ++i)
    if (a[i] != a[i - 1]) ++m;
  long long sum = qmi(k, m);
  for (int i = 0; i <= m / 2; ++i)
    sum = (sum -
           fac[m] * invf[i] % MOD * invf[i] % MOD * invf[m - 2 * i] % MOD *
               qmi(k - 2, m - 2 * i) % MOD +
           MOD) %
          MOD;
  printf("%lld\n", sum * qmi(k, n - m) % MOD * qmi(2, MOD - 2) % MOD);
  return 0;
}
