#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
const int MOD = 998244353;
int fact[MAX];
int pow1[MAX];
int pow2[MAX];
int add(int x, int y) {
  x += y;
  while (x >= MOD) {
    x -= MOD;
  }
  while (x < 0) {
    x += MOD;
  }
  return x;
}
int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int binpow(int x, int y) {
  int z = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      z = mul(z, x);
    }
    x = mul(x, x);
    y /= 2;
  }
  return z;
}
int inv(int x) { return binpow(x, MOD - 2); }
int divide(int x, int y) { return mul(x, inv(y)); }
int comb(int n, int k) {
  if (k > n) {
    return 0;
  }
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, n1 = 0, n2;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++)
    if (v[i] != v[(i + 1) % n]) n1++;
  n2 = n - n1;
  pow1[0] = 1;
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) pow1[i] = mul(pow1[i - 1], k);
  for (int i = 1; i <= n; i++) pow2[i] = mul(pow2[i - 1], k - 2);
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = mul(i, fact[i - 1]);
  }
  int cnt = 0;
  for (int i = 0; i <= n1 / 2; i++) {
    cnt = add(cnt, mul(mul(pow2[n1 - i * 2], comb(n1, i)), comb(n1 - i, i)));
  }
  int sol = mul(divide(add(pow1[n1], -cnt), 2), pow1[n2]);
  cout << sol << "\n";
  return 0;
}
