#include <bits/stdc++.h>
using namespace std;
long long int arr[200001];
long long int pow1[200001];
long long int pow2[200001];
long long int extgcd(long long int a, long long int b, long long int& x,
                     long long int& y) {
  long long int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
long long int mod_reverse(long long int a) {
  long long int x, y;
  extgcd(a, 998244353, x, y);
  return (998244353 + x % 998244353) % 998244353;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  long long int a = 0;
  long long int b = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i] == arr[i + 1]) {
      b++;
    } else {
      a++;
    }
  }
  if (arr[n] == arr[1]) {
    b++;
  } else {
    a++;
  }
  long long int res1 = 1;
  for (int i = 1; i <= a; i++) {
    res1 = (res1 * k) % 998244353;
  }
  long long int c = 0;
  pow1[0] = 1;
  for (int i = 1; i <= n; i++) {
    pow1[i] = (pow1[i - 1] * (k - 2)) % 998244353;
  }
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pow2[i] = (pow2[i - 1] * (i)) % 998244353;
  }
  long long int res2 = 0;
  int t = 0;
  while (2 * t <= a) {
    long long int tmp = (((pow1[a - 2 * t] * pow2[a]) % 998244353) *
                         mod_reverse(pow2[a - 2 * t])) %
                        998244353;
    tmp = (tmp * mod_reverse(pow2[t])) % 998244353;
    tmp = (tmp * mod_reverse(pow2[t])) % 998244353;
    res2 = res2 + tmp;
    t++;
  }
  res1 = res1 - res2;
  while (res1 < 0) {
    res1 = res1 + 998244353;
  }
  res1 = ((res1)*mod_reverse((long long int)2)) % 998244353;
  for (int i = 1; i <= b; i++) {
    res1 = (res1 * k) % 998244353;
  }
  cout << res1 << "\n";
}
