#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
string direc = "URDL";
const long long MOD2 = (long long)998244353 * (long long)998244353;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int fac[2135], inv[2135];
void initfac(int n) {
  fac[0] = inv[0] = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    fac[i] = (long long)fac[i - 1] * i % 998244353;
    inv[i] = fastPow(fac[i], 998244353 - 2);
  }
}
int C(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int h[2135];
void fmain(int tid) {
  scanf("%d%d", &n, &k);
  for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", h + i);
  initfac(n);
  int a = 0, b = 0;
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    if (h[i] == h[(i + 1) % n])
      a++;
    else
      b++;
  }
  int ans = 0;
  for (int same = 0; same < b; same++) {
    int ways = (long long)C(b, same) * fastPow(k - 2, same) % 998244353;
    int change = b - same;
    if (change & 1) {
      addmod(ans, fastPow(2, change - 1) * ways % 998244353);
    } else {
      long long tt = fastPow(2, change) - C(change, change / 2);
      tt = tt * inv[2] % 998244353;
      addmod(ans, tt * ways % 998244353);
    }
  }
  ans = fastPow(k, a) * ans % 998244353;
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
