#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
  for (T& ai : a) is >> ai;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> const& a) {
  os << "[ ";
  for (const T& ai : a) os << ai << " ";
  return os << "]";
}
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& a) {
  return is >> a.first >> a.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> const& a) {
  return os << "(" << a.first << ", " << a.second << ")";
}
const int M = 998244353;
int egcd(int a, int b, int& x, int& y) {
  if (a < b) return egcd(b, a, y, x);
  int bx = 0, by = 1, q, r, rx, ry;
  x = 1;
  y = 0;
  while (b) {
    q = a / b;
    r = a % b;
    rx = x - q * bx;
    ry = y - q * by;
    a = b;
    x = bx;
    y = by;
    b = r;
    bx = rx;
    by = ry;
  }
  return a;
}
int mod_inv(int a) {
  int x, y;
  egcd(a, M, x, y);
  if (x < 0) x += M;
  return x;
}
int pow_mod(int a, int b) {
  int r = 1, c = a;
  while (b) {
    if (b & 1) r = ((long long)r * c) % M;
    if (b >>= 1) c = ((long long)c * c) % M;
  }
  return r;
}
vector<int> FACT = {1};
int fact(int n) {
  for (int i = FACT.size(); i <= n; ++i) {
    FACT.push_back(((long long)FACT.back() * i) % M);
  }
  return FACT[n];
}
vector<int> FACTINV = {1};
int factinv(int n) {
  for (int i = FACTINV.size(); i <= n; ++i) {
    FACTINV.push_back(((long long)FACTINV.back() * mod_inv(i)) % M);
  }
  return FACTINV[n];
}
int f() {
  int n, k, f;
  cin >> n >> k >> f;
  int p = f, h;
  vector<int> c(2);
  while (--n) {
    cin >> h;
    ++c[h != p];
    p = h;
  }
  ++c[p != f];
  long long r = pow_mod(k, c[0]), z = 0, x = fact(c[1]);
  for (int i = 0; 2 * i <= c[1]; ++i) {
    long long y = x;
    (y *= factinv(i)) %= M;
    (y *= factinv(i)) %= M;
    (y *= factinv(c[1] - 2 * i)) %= M;
    (y *= pow_mod(k - 2, c[1] - 2 * i)) %= M;
    z = (z + y) % M;
  }
  z = (((long long)pow_mod(k, c[1]) + M - z) * mod_inv(2)) % M;
  return (r * z) % M;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << f() << "\n";
  return 0;
}
