#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename C, typename T = decay<decltype(*begin(declval<C>()))>,
          typename enable_if<!is_same<C, string>::value>::type * = nullptr>
ostream &operator<<(ostream &os, const C &c) {
  bool f = true;
  os << "[";
  for (const auto &x : c) {
    if (!f) os << ", ";
    f = false;
    os << x;
  }
  return os << "]";
}
template <typename T>
void debug(string s, T x) {
  cerr << s << " = " << x << "\n";
}
template <typename T, typename... Args>
void debug(string s, T x, Args... args) {
  cerr << s.substr(0, s.find(',')) << " = " << x << " | ";
  debug(s.substr(s.find(',') + 2), args...);
}
template <int MOD>
struct ModInt {
  long long v;
  ModInt(long long _v = 0) {
    v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
    if (v < 0) v += MOD;
  }
  ModInt &operator+=(const ModInt &other) {
    v += other.v;
    if (v >= MOD) v -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt &other) {
    v -= other.v;
    if (v < 0) v += MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt &other) {
    v = v * other.v % MOD;
    return *this;
  }
  ModInt &operator/=(const ModInt &other) { return *this *= inverse(other); }
  bool operator==(const ModInt &other) const { return v == other.v; }
  bool operator!=(const ModInt &other) const { return v != other.v; }
  friend ModInt operator+(ModInt a, const ModInt &b) { return a += b; }
  friend ModInt operator-(ModInt a, const ModInt &b) { return a -= b; }
  friend ModInt operator*(ModInt a, const ModInt &b) { return a *= b; }
  friend ModInt operator/(ModInt a, const ModInt &b) { return a /= b; }
  friend ModInt operator-(const ModInt &a) { return 0 - a; }
  friend ModInt power(ModInt a, long long b) {
    ModInt ret(1);
    while (b > 0) {
      if (b & 1) ret *= a;
      a *= a;
      b >>= 1;
    }
    return ret;
  }
  friend ModInt inverse(ModInt a) { return power(a, MOD - 2); }
  friend ostream &operator<<(ostream &os, const ModInt &m) { return os << m.v; }
};
const int MAX = 2e5 + 5;
ModInt<998244353> fact[MAX], inv[MAX];
ModInt<998244353> choose(int n, int k) {
  if (k < 0 || n < k) return 0;
  return fact[n] * inv[k] * inv[n - k];
}
void preprocess() {
  fact[0] = 1;
  for (int i = 1; i < MAX; i++) fact[i] = fact[i - 1] * i;
  inv[MAX - 1] = inverse(fact[MAX - 1]);
  for (int i = MAX - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  preprocess();
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  if (k == 1) {
    cout << "0\n";
    return 0;
  }
  int spots = 0;
  for (int i = 0; i < n; i++)
    if (h[i] != h[(i + 1) % n]) spots++;
  ModInt<998244353> ret = 0;
  for (int z = 0; z <= spots; z++) {
    ModInt<998244353> eq = 0;
    if ((spots - z) % 2 == 0) {
      eq = choose(spots - z, (spots - z) / 2);
    } else {
      eq = 0;
    }
    ModInt<998244353> tot = power(ModInt<998244353>(2), spots - z);
    tot -= eq;
    tot /= 2;
    ret += tot * choose(spots, z) * power(ModInt<998244353>(k - 2), z);
  }
  ret *= power(ModInt<998244353>(k), n - spots);
  cout << ret << "\n";
  return 0;
}
