#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool vmin(T& a, T b) {
  return (a > b) ? (a = b, true) : (false);
}
template <typename T>
bool vmax(T& a, T b) {
  return (a < b) ? (a = b, true) : (false);
}
template <typename T>
T smax(T x) {
  return x;
}
template <typename T, typename... K>
T smax(T a, const K&... args) {
  return max(a, smax(args...));
}
template <typename T>
T smin(T x) {
  return x;
}
template <typename T, typename... K>
T smin(T a, const K&... args) {
  return min(a, smin(args...));
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& z) {
  os << "(" << z.first << ", " << z.second << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& a) {
  bool isfirst = true;
  os << "{";
  for (auto z : a) {
    if (!isfirst) {
      os << ", ";
    }
    os << z;
    isfirst = false;
  }
  os << '}';
  return os;
}
const int inf = (signed)(~0u >> 2);
const long long llf = (signed long long)(~0ull >> 2);
template <typename T>
int vsize(vector<T>& x) {
  return (signed)x.size();
}
template <typename T>
void discrete(T* a, int* b, int n) {
  vector<T> v(a + 1, a + n + 1);
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; i++)
    b[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
}
const int N = 2e5 + 5;
void exgcd(int a, int b, int& x, int& y) {
  if (!b) {
    x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
}
int inv(int a, int n) {
  int x, y;
  exgcd(a, n, x, y);
  return (x < 0) ? (x + n) : (x);
}
const int Mod = 998244353;
template <const int Mod = ::Mod>
class Z {
 public:
  int v;
  Z() : v(0) {}
  Z(int x) : v(x) {}
  Z(long long x) : v(x % Mod) {}
  friend Z operator+(const Z& a, const Z& b) {
    int x;
    return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
  }
  friend Z operator-(const Z& a, const Z& b) {
    int x;
    return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
  }
  friend Z operator*(const Z& a, const Z& b) { return Z(a.v * 1ll * b.v); }
  friend Z operator~(const Z& a) { return inv(a.v, Mod); }
  friend Z operator-(const Z& a) { return Z(0) - a; }
  Z& operator+=(Z b) { return *this = *this + b; }
  Z& operator-=(Z b) { return *this = *this - b; }
  Z& operator*=(Z b) { return *this = *this * b; }
  friend bool operator==(const Z& a, const Z& b) { return a.v == b.v; }
};
Z<> qpow(Z<> a, int p) {
  Z<> rt = Z<>(1), pa = a;
  for (; p; p >>= 1, pa = pa * pa) {
    if (p & 1) {
      rt = rt * pa;
    }
  }
  return rt;
}
vector<Z<> > fac, _fac;
void init_fac(int n) {
  fac.resize(n + 1);
  _fac.resize(n + 1);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i;
  _fac[n] = ~fac[n];
  for (int i = n; i; i--) _fac[i - 1] = _fac[i] * i;
}
Z<> comb(int n, int m) {
  return (n < m) ? (0) : (fac[n] * _fac[m] * _fac[n - m]);
}
int n, k;
vector<int> h;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  h.resize(n);
  for (auto& x : h) cin >> x;
  Z<> coef = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int cur = h[i], nxt = h[(i + 1) % n];
    if (cur == nxt) {
      coef *= k;
    } else {
      cnt++;
    }
  }
  init_fac(cnt);
  Z<> k2 = Z<>(k) - 2;
  Z<> pw = 1, ans = 0;
  for (int i = 0; i <= cnt; i++) {
    int rest = cnt - i;
    if (rest & 1) {
      ans += pw * comb(cnt, i) * qpow(2, rest - 1);
    } else {
      ans += pw * comb(cnt, i) * (qpow(2, rest) - comb(rest, rest >> 1)) *
             ((Mod + 1) >> 1);
    }
    pw = pw * k2;
  }
  ans *= coef;
  cout << ans.v << '\n';
  return 0;
}
