#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int exp(long long int n, long long int e) {
  if (e == 0) return 1;
  long long int temp = exp((n * n) % MOD, e / 2);
  return e % 2 == 0 ? temp : (temp * n) % MOD;
}
long long int inverse(long long int n) { return exp(n, MOD - 2); }
int LIM = 3e5 + 10;
vector<long long int> factorial(LIM, 1);
vector<long long int> inv(LIM, 1);
long long int choose(long long int n, long long int r) {
  long long int ans = ((factorial[n] * inv[r]) % MOD * inv[n - r]) % MOD;
  return ans;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<long long int> arr(n + 1);
  int a = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (i > 1) a += arr[i] == arr[i - 1];
  }
  a += (arr[1] == arr[n]);
  long long int ans = 0;
  long long int m = n - a;
  for (int i = 0; i < m; i++) {
    long long int temp = (exp(k - 2, i) * choose(m, i)) % MOD;
    long long int prod = -1;
    long long int c = m - i;
    if (c % 2 == 1)
      prod = exp(2, c - 1);
    else
      prod = (((exp(2, c) - choose(c, c / 2) + MOD) % MOD) * inv[2]) % MOD;
    ;
    temp = (temp * prod) % MOD;
    ans = (ans + temp) % MOD;
  }
  ans = (ans * exp(k, a)) % MOD;
  cout << ans << endl;
}
int main() {
  int t;
  t = 1;
  for (int i = 1; i < LIM; i++) {
    factorial[i] = (factorial[i - 1] * i) % MOD;
    inv[i] = inverse(factorial[i]);
  }
  while (t--) {
    solve();
  }
  return 0;
}
