#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "}";
  return os;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 1e6 + 10, mod = 998244353;
int fact[N], invfact[N];
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int mul(int x, int y) { return (((long long)x) * y) % mod; }
inline int powr(int a, long long b) {
  int x = 1 % mod;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
void pre() {
  fact[0] = invfact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
  invfact[N - 1] = inv(fact[N - 1]);
  for (int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
  assert(invfact[1] == 1);
}
inline int C(int n, int k) {
  if (n < k || k < 0) return 0;
  return mul(fact[n], mul(invfact[k], invfact[n - k]));
}
int h[N];
int main() {
  pre();
  int n, k;
  scanf("%d", &(n));
  scanf("%d", &(k));
  vector<vector<int> > vec;
  for (int i = 0; i < n; i++) {
    scanf("%d", &(h[i]));
    h[i]--;
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  int ans = 1;
  int t = 0;
  for (int i = 0; i < n; i++) {
    int a = h[i], b = h[(i + 1) % n];
    if (a != b) {
      t++;
    } else
      ans = mul(ans, k);
  }
  int ALL = powr(k, n);
  int pw = 1;
  int sm = 0;
  for (int i = 0; i <= t; i++) {
    if ((t - i) % 2 == 0) {
      sm = add(sm, mul(C(t, i), mul(pw, C(t - i, (t - i) / 2))));
    }
    pw = mul(pw, k - 2);
  }
  printf("%d\n", mul(inv(2), sub(ALL, mul(ans, sm))));
}
