#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 4;
const int mod = 998244353;
inline int sum(int a, int b) { return (a + b) % mod; }
inline int diff(int a, int b) { return (a - b + mod) % mod; }
inline int mult(int a, int b) { return (long long)a * b % mod; }
int fc[N], ifc[N];
inline int c(int a, int b) { return mult(fc[b], mult(ifc[a], ifc[b - a])); }
int binpow(int a, int b) {
  if (!b) {
    return 1;
  }
  if (b & 1) {
    return mult(a, binpow(a, b ^ 1));
  }
  return binpow(mult(a, a), b >> 1);
}
int inv(int a) { return binpow(a, mod - 2); }
int n, k, h[N];
void read() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
}
int b;
void precalc() {
  fc[0] = ifc[0] = 1;
  for (int i = 1; i < N; ++i) {
    fc[i] = mult(fc[i - 1], i);
    ifc[i] = mult(ifc[i - 1], inv(i));
  }
  for (int i = 0; i < n;) {
    int j = i;
    while (j < n && h[i] == h[j]) {
      ++j;
    }
    ++b;
    i = j;
  }
  if (n > 1 && h[0] == h[n - 1]) {
    b--;
  }
}
int brute() {
  return 0;
  int res = 0;
  for (int x = 0; x <= b; ++x) {
    int tmp1 = mult(binpow(k, n - b), c(x, b));
    int tmp2 = 0;
    for (int j = x + 1; j <= b - x; ++j) {
      tmp2 = sum(tmp2, mult(binpow(k - 2, b - x - j), c(j, b - x)));
    }
    res = sum(res, mult(tmp1, tmp2));
  }
  return res;
}
void myread() {
  srand(time(NULL));
  n = 100;
  k = rand() % 1000000 + 2;
  for (int i = 0; i < n; ++i) {
    h[i] = rand() % k + 1;
  }
}
void solve() {
  read();
  precalc();
  if (b == 1) {
    cout << "0\n";
    return;
  }
  int res = 0, i2 = inv(2);
  for (int t = 0; t < b; ++t) {
    int tmp1 = mult(c(t, b), binpow(k - 2, t));
    int tmp2;
    if ((b - t) % 2 == 0) {
      tmp2 = diff(binpow(2, b - t), c((b - t) / 2, b - t));
    } else {
      tmp2 = binpow(2, b - t);
    }
    res = sum(res, mult(tmp1, mult(i2, tmp2)));
  }
  res = mult(res, binpow(k, n - b));
  cout << res;
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0), cin.tie(0);
  solve();
  return 0;
}
