#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) w |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  return w ? -x : x;
}
namespace star {
const int maxn = 2e5 + 5, mod = 998244353;
int n, m, mul[maxn], inv[maxn], h[maxn], a, b, ans;
inline int fpow(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
inline void pre(int n) {
  mul[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) mul[i] = 1ll * mul[i - 1] * i % mod;
  inv[n] = fpow(mul[n], mod - 2);
  for (int i = n - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
inline int C(int n, int m) {
  return 1ll * mul[n] * inv[m] % mod * inv[n - m] % mod;
}
inline void work() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) h[i] = read();
  for (int i = 1; i <= n; i++)
    if (h[i] == h[i == n ? 1 : i + 1])
      a++;
    else
      b++;
  if (!b) return puts("0"), void();
  pre(b);
  for (int i = 1; i <= b; i++)
    ans = (ans + 1ll * fpow(m - 2, b - i) * C(b, b - i) % mod *
                     (i & 1 ? fpow(2, i - 1)
                            : (fpow(2, i - 1) -
                               1ll * C(i, i >> 1) * inv[2] % mod + mod) %
                                  mod) %
                     mod) %
          mod;
  printf("%lld\n", 1ll * ans * fpow(m, a) % mod);
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}
