#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma comment(linker, "/STACK:256000000")
#pragma warning(disable : 4996)
using namespace std;
const char el = '\n';
const int inf = 1e9;
const long double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825;
template <typename T>
bool uin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
bool uax(T &a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class iterator>
void output(iterator begin, iterator end, char p = ' ', ostream &out = cout) {
  while (begin != end) {
    out << (*begin) << p;
    begin++;
  }
  out << el;
}
template <class T>
void output(T first, char p = ' ', ostream &out = cout) {
  output(first.begin(), first.end(), p, out);
}
mt19937 rnd(time(NULL));
const int N = 3e5;
long long mod = 998244353;
long long mult(long long a, long long b) { return a * b % mod; }
long long add(long long a, long long b) {
  if (a + b >= mod) return a + b - mod;
  return a + b;
}
long long bin_p(long long a, long long b) {
  if (!b) return 1;
  if (b % 2 == 0) {
    long long cur = bin_p(a, b / 2);
    return mult(cur, cur);
  }
  return mult(a, bin_p(a, b - 1));
}
long long f[N], rev[N];
long long C(long long n, long long k) {
  return mult(mult(f[n], rev[n - k]), rev[k]);
}
int a[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  f[0] = 1;
  for (int i = 1; i < N; ++i) {
    f[i] = mult(f[i - 1], i);
  }
  rev[N - 1] = bin_p(f[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; --i) {
    rev[i] = mult(rev[i + 1], i + 1);
  }
  int n, k;
  std::cin >> n >> k;
  int diff = 0;
  for (int i = 0; i < (int)n; ++i) {
    std::cin >> a[i];
  }
  for (int i = 0; i < (int)n; ++i) {
    diff += (a[i] != a[(i + 1) % n]);
  }
  long long first = bin_p(k, diff);
  for (int t = 0; t + t <= diff; ++t) {
    first = (first - mult(mult(C(diff, t), C(diff - t, t)),
                          bin_p(k - 2, diff - t - t)));
    first = (first % mod + mod) % mod;
  }
  first = mult(first, bin_p(2, mod - 2));
  first = mult(first, bin_p(k, n - diff));
  first = (first % mod + mod) % mod;
  std::cout << first << '\n';
}
