#include <bits/stdc++.h>
using namespace std;
template <class T>
void re(T& x) {
  cin >> x;
}
template <class T1, class T2>
void re(pair<T1, T2>& x) {
  re(x.first);
  re(x.second);
}
template <class T>
void re(vector<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T>
void re(deque<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T1, class T2>
pair<T1, T2> mp(T1& x, T2& z) {
  return make_pair(x, z);
}
template <class T>
T cross(complex<T> x, complex<T> z) {
  return (conj(x) * z).imag();
}
template <class T>
T dot(complex<T> x, complex<T> z) {
  return (conj(x) * z).real();
}
template <class T>
void out(vector<T> v, long x = 0) {
  for (long i = x; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
template <class T>
void reset(vector<T>& x, T& z) {
  x.clear();
  x.resize(z);
}
long long mod = 998244353;
long long power(long long x, long long p) {
  if (p == 0) {
    return 1;
  }
  long long z = power(x, p / 2);
  z = (z * z) % mod;
  if (p % 2 == 1) {
    z = (z * x) % mod;
  }
  return z;
}
vector<long long> fact, inv;
void inverse(long x) {
  fact.clear();
  inv.clear();
  fact.resize(x + 1);
  inv.resize(x + 1);
  fact[0] = 1;
  for (long long i = 1; i <= x; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  inv[x] = power(fact[x], mod - 2);
  for (long long i = x - 1; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
}
long long nck(long long n, long long k) {
  long long z = (fact[n] * inv[k]) % mod;
  z = (z * inv[n - k]) % mod;
  return z;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, x, z, ans = 0;
  cin >> n >> k;
  inverse(n);
  vector<long long> v(n);
  re(v);
  z = -1;
  x = 0;
  for (long i = 1; i < n; i++) {
    if (v[i] != v[i - 1]) {
      z = i;
      break;
    }
  }
  if (z != -1) {
    for (long i = z; i < (n + z); i++) {
      if (v[(i % n)] != v[(i - 1) % n]) {
        x++;
      }
    }
  }
  for (long i = 0; i < x; i++) {
    if ((x - i) % 2 == 0) {
      ans += (power(k - 2, i) *
              ((nck(x, i) *
                ((((mod + power(2, x - i) - nck(x - i, (x - i) / 2)) % mod) *
                  power(2, mod - 2)) %
                 mod)) %
               mod)) %
             mod;
    } else {
      ans +=
          (power(k - 2, i) * ((nck(x, i) * power(2, x - i - 1)) % mod)) % mod;
    }
    ans %= mod;
  }
  ans = (ans * power(k, n - x)) % mod;
  cout << ans << endl;
  return 0;
}
