#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
  putchar(' ');
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <typename R, typename D>
inline void Min(R &a, D b) {
  if (a > b) a = b;
}
template <typename D, typename R>
inline void Max(D &a, R b) {
  if (a < b) a = b;
}
const int N = 200003, base = 331, mod = 998244353;
int n, ans, t, gt[N], gtd[N], k, a[N];
int power(int a, int b) {
  int c = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) c = 1ll * c * a % mod;
  return c;
}
void Pre() {
  gt[0] = gtd[0] = 1;
  for (int i = 1; i < N; ++i) gt[i] = 1ll * gt[i - 1] * i % mod;
  gtd[N - 1] = power(gt[N - 1], mod - 2);
  for (int i = N - 2; i >= 1; --i) gtd[i] = 1ll * gtd[i + 1] * (i + 1) % mod;
}
int ckn(int n, int k) {
  return 1ll * (1ll * gt[n] * gtd[k] % mod) * gtd[n - k] % mod;
}
int calc(int x) {
  if (x & 1) return power(2, x - 1);
  int tmp = power(2, x);
  tmp -= ckn(x, x / 2);
  if (tmp < 0) tmp += mod;
  if (tmp & 1) tmp += mod;
  return tmp / 2;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  Pre();
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  a[n + 1] = a[1];
  for (int i = 1; i <= n; ++i)
    if (a[i] != a[i + 1]) ++t;
  if (!t || k == 1) return !(cout << 0);
  for (int i = 0; i <= t - 1; ++i) {
    int tmp = power(k - 2, i);
    tmp = 1ll * tmp * ckn(t, i) % mod;
    tmp = 1ll * tmp * calc(t - i) % mod;
    ans += tmp;
    if (ans >= mod) ans -= mod;
  }
  ans = 1ll * ans * power(k, n - t) % mod;
  cout << ans;
  return 0;
}
