#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int sum(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(int a, int b) { return (1LL * a * b) % MOD; }
int pw(int a, int b) {
  if (!b) return 1;
  int r = pw(a, b / 2);
  r = mul(r, r);
  if (b % 2) r = mul(r, a);
  return r;
}
int power(int a, int p) {
  if (p == 0) return 1;
  int ans = power(a, p / 2);
  ans = mul(ans, ans);
  if (p & 1) ans = mul(ans, a);
  return ans;
}
struct NTT {
  int N;
  vector<int> perm;
  int mod, root, inv, pw;
  NTT(int mod, int root, int inv, int pw)
      : mod(mod), root(root), inv(inv), pw(pw) {}
  void precalculate() {
    perm.resize(N);
    perm[0] = 0;
    for (int k = 1; k < N; k <<= 1) {
      for (int i = 0; i < k; i++) {
        perm[i] <<= 1;
        perm[i + k] = 1 + perm[i];
      }
    }
  }
  void fft(vector<int> &v, bool invert = false) {
    if (v.size() != perm.size()) {
      N = v.size();
      assert(N && (N & (N - 1)) == 0);
      precalculate();
    }
    for (int i = 0; i < N; i++)
      if (i < perm[i]) swap(v[i], v[perm[i]]);
    for (int len = 2; len <= N; len <<= 1) {
      int factor = invert ? inv : root;
      for (int i = len; i < pw; i <<= 1) {
        factor = mul(factor, factor);
      }
      for (int i = 0; i < N; i += len) {
        int w = 1;
        for (int j = 0; j < len / 2; j++) {
          int x = v[i + j], y = mul(w, v[i + j + len / 2]);
          v[i + j] = sum(x, y);
          v[i + j + len / 2] = sub(x, y);
          w = mul(w, factor);
        }
      }
    }
    if (invert) {
      int n1 = power(N, mod - 2);
      for (int &x : v) x = mul(x, n1);
    }
  }
  vector<int> multiply(vector<int> a, vector<int> b) {
    int n = 1;
    while (n < a.size() + b.size()) n <<= 1;
    a.resize(n);
    b.resize(n);
    fft(a);
    fft(b);
    for (int i = 0; i < n; i++) a[i] = mul(a[i], b[i]);
    fft(a, true);
    return a;
  }
  vector<int> exponentiate(vector<int> v, int p) {
    int sz = p * v.size();
    int n = 1;
    while (n < sz) n <<= 1;
    v.resize(n);
    fft(v);
    for (int i = 0; i < n; i++) v[i] = power(v[i], p);
    fft(v, true);
    return v;
  }
};
NTT ntt(998244353, 15311432, 469870224, 1 << 23);
const int MAXN = 2e5 + 7;
int h[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> h[i];
  int ans = 1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int j = i == 1 ? n : i - 1;
    if (h[j] == h[i]) {
      ans = mul(ans, k);
    } else {
      cnt++;
    }
  }
  int tmp = 0;
  if (cnt > 0) {
    vector<int> poly{1, (k - 2) % MOD, 1};
    vector<int> res = ntt.exponentiate(poly, cnt);
    for (int i = cnt + 1; i < res.size(); i++) {
      tmp = sum(tmp, res[i]);
    }
  }
  ans = mul(ans, tmp);
  cout << ans << "\n";
  return 0;
}
