#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long maxn = 1e13;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << 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...);
}
long long n, k, t;
deque<int> que;
vector<long long> fac;
long long gcdExtended(long long a, long long b, long long* x, long long* y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return -1;
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long mult(long long a, long long b) {
  return ((a % 998244353) * (b % 998244353)) % 998244353;
}
long long power(long long a, long long k) {
  if (k == 0) {
    return 1;
  }
  if (k % 2 == 1) {
    return mult(a, power(a, k - 1));
  }
  return power(mult(a, a), k / 2);
}
long long comb(long long t, long long i) {
  long long den = mult(fac[i], fac[t - i]);
  return mult(modInverse(den, 998244353), fac[t]);
}
long long sub(long long a, long long b) {
  return a - b > 0 ? a - b : 998244353 + a - b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    que.push_back(a);
  }
  int size = que.size();
  t = n;
  for (int i = 0; i < size; i++) {
    long long fro = que.front();
    que.pop_front();
    que.push_back(fro);
    if (fro == que.front()) {
      t--;
    }
  }
  fac.resize(n + 1);
  fac[0] = 1;
  fac[1] = 1;
  for (long long i = 2; i <= n; i++) {
    fac[i] = (mult(fac[i - 1], i));
  }
  long long coff = power(k, n - t);
  long long inv = modInverse(2, 998244353);
  long long fin = 0;
  for (int i = 0; i <= t - 1; i++) {
    long long coff1 = power(k - 2, i);
    long long coff2 = comb(t, i);
    long long coff3 = 0;
    if ((t - i) % 2 == 1) {
      coff3 = power(2, t - i - 1);
    } else {
      coff3 = mult(sub(power(2, t - i), comb(t - i, (t - i) / 2)), inv);
    }
    fin += mult(mult(coff1, coff2), coff3);
    fin %= 998244353;
    __f("i, coff1, coff2, coff3, coff, fin", i, coff1, coff2, coff3, coff, fin);
  }
  fin = mult(fin, coff);
  cout << fin << "\n";
}
