#include <bits/stdc++.h>
using namespace std;
template <typename T>
string to_string(const vector<T>& vc, int w) {
  if (vc.empty()) return "";
  if (w + 1 == vc.size()) return to_string(vc[w]);
  return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
template <typename T>
string to_string(const vector<T>& vc) {
  return "{" + to_string(vc, 0) + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
class DebugStream {
} LOG;
template <typename T>
DebugStream& operator<<(DebugStream& s, const T&) {
  return s;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20,
          bs = 29;
long long fastPow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return ret;
}
long long twop[maxN], kp[maxN], fac[maxN][2];
long long ncr(int n, int k) {
  if (k > n) return 0;
  return fac[n][0] * fac[k][1] % MOD * fac[n - k][1] % MOD;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, cnd = 1;
  cin >> n >> k;
  if (k == 1) {
    cout << "0\n";
    return 0;
  }
  vector<long long> arr(n);
  for (auto& el : arr) cin >> el;
  int ct = 0;
  for (int i = 0; i < n; i++) {
    int nxt = (i + 1) % n;
    if (arr[i] != arr[nxt])
      ct++;
    else
      cnd = cnd * k % MOD;
  }
  n = ct;
  fac[0][0] = 1;
  for (long long i = 1; i <= n; i++) fac[i][0] = fac[i - 1][0] * i % MOD;
  fac[n][1] = fastPow(fac[n][0], MOD - 2);
  for (long long i = n - 1; i >= 0; i--)
    fac[i][1] = fac[i + 1][1] * (i + 1) % MOD;
  twop[0] = kp[0] = 1;
  for (int i = 1; i <= n; i++) {
    twop[i] = twop[i - 1] * 2 % MOD;
    kp[i] = kp[i - 1] * (k - 2) % MOD;
  }
  auto fn = [&](int w) {
    long long ovr = twop[w];
    if (w % 2 == 0) ovr = (ovr + MOD - ncr(w, w / 2)) % MOD;
    long long ent = ovr * fac[2][1] % MOD;
    return ent;
  };
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans + ncr(n, i) * fn(i) % MOD * kp[n - i]) % MOD;
  ans = ans * cnd % MOD;
  cout << ans << '\n';
}
