#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long int m = 998244353, f[N], inv[N];
long long int ncr(long long int n, long long int r) {
  if (r < 0 || r > n) return 0;
  long long int res = (f[n] * inv[r]) % m;
  res = (res * inv[n - r]) % m;
  return res;
}
long long int p(long long int a, long long int b) {
  long long int r = 1;
  while (b) {
    if (b % 2) r = (r * a) % m;
    a = (a * a) % m;
    b /= 2;
  }
  return r;
}
long long int a[N];
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, k;
  f[0] = 1;
  for (int i = 1; i <= N - 1; i++) f[i] = (f[i - 1] * 1ll * i) % m;
  inv[N - 1] = p(f[N - 1], m - 2);
  for (int i = N - 2; i >= 0; i--) inv[i] = (inv[i + 1] * 1ll * (i + 1)) % m;
  cin >> n >> k;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  if (n == 1) {
    cout << 0;
    return 0;
  }
  long long int ans = 1;
  long long int cnt = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (a[i] == a[(i + 1) % n])
      ans = (ans * k) % m;
    else
      cnt++;
  }
  if (cnt == 0) {
    cout << 0;
    return 0;
  }
  long long int s = 0, pp = 1;
  long long int in2 = p(2, m - 2);
  for (int i = 0; i <= cnt; i++) {
    long long int rem = cnt - i;
    if (rem % 2 == 0) {
      long long int r = (p(2, rem) - ncr(rem, rem / 2)) % m;
      r = (r * in2) % m;
      r = (r * ncr(cnt, i)) % m;
      s = (s + r * pp) % m;
    } else {
      long long int r = p(2, rem - 1);
      r = (r * ncr(cnt, i)) % m;
      s = (s + r * pp) % m;
    }
    pp = (pp * (k - 2)) % m;
  }
  ans = (ans * s) % m;
  cout << (ans + m) % m;
  return 0;
}
