#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % 998244353;
  if (c >= 0) return c;
  return c + 998244353;
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
void Add(long long &pos, long long val) { pos = mod(pos + val); }
long double EPS = 1E-9;
long long po(long long i, long long p) {
  if (p == 0)
    return 1;
  else {
    i = mod(i);
    if (p == 1) return i;
    if (p % 2 == 0) return po(mod(i * i), p / 2);
    return mod(i * po(i, p - 1));
  }
}
long long bunbo(long long n) { return po(n, 998244353 - 2); }
long long kai[400004];
long long kai2[400004];
void calc() {
  kai[0] = 1;
  kai2[0] = 1;
  for (long long i = 1; i <= 400004 - 1; i++) {
    kai[i] = mod(kai[i - 1] * i);
  }
  kai2[400004 - 1] = po(kai[400004 - 1], 998244353 - 2);
  for (long long i = 400004 - 2; i >= 0; i--) {
    kai2[i] = mod(kai2[i + 1] * (i + 1));
  }
}
long long comb(long long n, long long k) {
  if (n < k) return 0;
  if (n == 0) return 1;
  return mod(mod(kai[n] * kai2[n - k]) * kai2[k]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  calc();
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << "\n";
    return 0;
  }
  long long h[n];
  for (long long i = 0; i <= n - 1; i++) cin >> h[i];
  long long c = 0;
  for (long long i = 0; i <= n - 1; i++) {
    bool f = h[i] == h[(i + 1) % n];
    if (!f) c++;
  }
  long long sum = 0;
  for (long long i = 0; i <= c; i++) {
    long long res = mod(comb(c, i) * po(k - 2, i));
    if ((c - i) % 2 == 1) {
      res = mod(res * po(2, c - i));
      res = mod(res * bunbo(2));
    } else {
      res = mod(res * (po(2, c - i) - comb(c - i, (c - i) / 2)));
      res = mod(res * bunbo(2));
    }
    Add(sum, res);
  }
  long long ans = mod(sum * po(k, n - c));
  cout << mod(ans) << "\n";
  return 0;
}
