#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(vector<T> &a, long long n) {
  T x;
  a.clear();
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
}
template <class T>
void write(vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << endl;
}
const int N = 200005;
const long long mod = 998244353;
long long first[N], rev_f[N];
long long bpow(long long a, long long x) {
  if (!x) return 1;
  if (x & 1) return a * bpow(a, x - 1) % mod;
  long long b = bpow(a, x / 2);
  return b * b % mod;
}
long long C(int n, int m) {
  if (n > m) return 0;
  if (n < 0) return 0;
  return first[m] * rev_f[n] % mod * rev_f[m - n] % mod;
}
int n, x, y, k;
vector<int> a;
int main() {
  ios_base::sync_with_stdio(0);
  first[0] = 1;
  rev_f[0] = 1;
  for (int i = 1; i < N; i++) {
    first[i] = (first[i - 1] * i) % mod;
    rev_f[i] = bpow(first[i], mod - 2);
  }
  cin >> n >> k >> x;
  a.push_back(x);
  for (int i = 1; i < n; i++) {
    cin >> x;
    if (x != a.back()) a.push_back(x);
  }
  if (k == 1 || a.size() == 1) {
    cout << 0;
    return 0;
  }
  if (a.back() == a[0]) a.pop_back();
  x = (int)a.size();
  y = n - x;
  long long sum = 0;
  for (int i = 0; 2 * i <= x; i++)
    sum =
        (sum + C(2 * i, x) * C(i, 2 * i) % mod * bpow(k - 2, x - 2 * i) % mod) %
        mod;
  sum = (sum * bpow(k, y)) % mod;
  sum = (bpow(k, n) - sum + mod) % mod;
  sum = sum * bpow(2, mod - 2) % mod;
  cout << sum << endl;
}
