#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)2e5 + 5;
const long long MOD = 998244353;
long long mult(long long a, long long b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
long long add(long long a, long long b) {
  return ((a % MOD) + (b % MOD) + MOD + MOD) % MOD;
}
long long binpow(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  if (b % 2) {
    return mult(binpow(a, b - 1), a);
  } else {
    long long x = binpow(a, b / 2);
    return mult(x, x);
  }
}
long long h[MAXN];
long long n, k;
long long fact[MAXN];
long long divide(long long a, long long b) {
  return mult(a, binpow(b, MOD - 2));
}
long long C(long long n, long long k) {
  long long up = fact[n];
  long long down = mult(fact[k], fact[n - k]);
  return divide(up, down);
}
void prepare() {
  fact[0] = 1;
  for (long long i = 1; i < MAXN; i++) {
    fact[i] = mult(fact[i - 1], i);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  prepare();
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> h[i];
  }
  if (k == 1) {
    cout << 0 << "\n";
    return 0;
  }
  long long t = 0;
  for (long long i = 1; i <= n; i++) {
    long long nxt = i % n + 1;
    if (h[i] != h[nxt]) {
      t++;
    }
  }
  long long ans = 0;
  for (long long zero = 0; zero < t; zero++) {
    long long cur_ans = 1;
    cur_ans = mult(cur_ans, binpow(k - 2, zero));
    cur_ans = mult(cur_ans, C(t, zero));
    long long big = 0;
    if ((t - zero) % 2) {
      big = binpow(2, t - zero - 1);
    } else {
      big = divide(add(binpow(2, t - zero), -C(t - zero, (t - zero) / 2)), 2);
    }
    cur_ans = mult(cur_ans, big);
    ans = add(ans, cur_ans);
  }
  cout << mult(ans, binpow(k, n - t)) << "\n";
}
