#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
inline int read() {
  register int res = 0, c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  do {
    res = (res * 10) + (c ^ 48);
  } while (c = getchar(), c >= '0' && c <= '9');
  return res;
}
const int mod = 998244353;
int qpow(int n, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
    k >>= 1;
  }
  return res;
}
int main(int argc, char* argv[]) {
  int N = read(), K = read();
  vector<int> s(N);
  for (int i = 0; i < N; i++) {
    s[i] = read();
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == s[(i + 1) % N]) cnt++;
  }
  vector<vector<int>> C(2001, vector<int>(2001));
  C[0][0] = 1;
  for (int i = 1; i <= 2000; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  }
  int rev2 = qpow(2, mod - 2);
  int ans = 0;
  for (int j = 0; j < N - cnt; j++) {
    int now = qpow(K - 2, j);
    now = 1ll * now * C[N - cnt][j] % mod;
    if ((N - cnt - j) & 1) {
      now = 1ll * now * qpow(2, N - cnt - j - 1) % mod;
    } else {
      now = 1ll * now *
            (qpow(2, N - cnt - j) - C[N - cnt - j][(N - cnt - j) >> 1] + mod) %
            mod;
      now = 1ll * now * rev2 % mod;
    }
    ans = (ans + now) % mod;
  }
  ans = 1ll * ans * qpow(K, cnt) % mod;
  printf("%d\n", ans);
  return 0;
}
