#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 15;
const int Q = 998244353;
int fact[M];
int h[M];
int mul(int a, int b) { return int((1LL * a * b) % Q); }
int mi(int a, int b) { return a - b >= 0 ? a - b : a - b + Q; }
int po(int x, int y) {
  if (y == 0) return 1;
  int t = po(x, y / 2);
  t = mul(t, t);
  if (y & 1) t = mul(t, x);
  return t;
}
int back(int x) { return po(x, Q - 2); }
int c(int n, int k) {
  return mul(mul(fact[n], back(fact[n - k])), back(fact[k]));
}
int main() {
  int n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int p = n;
  for (int i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n]) {
      p--;
    }
  }
  int res = po(k, n);
  for (int i = 0; p - 2 * i >= 0; i++) {
    int x1 = c(p, i);
    int x2 = c(p - i, i);
    int x3 = po(k - 2, p - 2 * i);
    int x4 = po(k, n - p);
    res = mi(res, mul(mul(x1, x2), mul(x3, x4)));
  }
  res = mul(res, back(2));
  cout << res << endl;
  return 0;
}
