#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int fact[N];
int n, arr[N], k;
int cnt = 0;
int p1, p2, p3;
int fres = 1;
inline int fastpower(int num, int po) {
  fres = 1;
  while (po > 0) {
    if (po & 1) fres = (long long)fres * num % 998244353;
    num = (long long)num * num % 998244353;
    po >>= 1;
  }
  return fres;
}
inline int nck(int n, int k) {
  if (k > n) return 0;
  return (
      (long long)fact[n] *
      fastpower((long long)fact[k] * fact[n - k] % 998244353, 998244353 - 2) %
      998244353);
}
int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = (long long)i * fact[i - 1] % 998244353;
  scanf("%d%d", &n, &k);
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] != arr[(i + 1) % n]) cnt++;
  }
  p3 = k - 2;
  int needed = 0;
  int ans = 0;
  int tmp1, tmp2, tmp3;
  for (int i = 0; i < n; i++) {
    needed = i + 1;
    if (i + needed > cnt) continue;
    tmp1 = nck(cnt, i);
    for (int j = needed; j <= cnt - i; j++) {
      tmp2 = nck(cnt - i, j);
      tmp3 = fastpower(p3, cnt - i - j);
      tmp2 = (long long)tmp2 * tmp3 % 998244353;
      tmp2 = (long long)tmp2 * tmp1 % 998244353;
      tmp2 = (long long)tmp2 * fastpower(k, n - cnt) % 998244353;
      ans += tmp2;
      if (ans >= 998244353) ans -= 998244353;
    }
  }
  cout << ans << endl;
  return 0;
}
