#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V>& x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T& x) {
  int f = 0;
  cerr << '{';
  for (auto& i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void pre() {}
const long long mod = (119 << 23) + 1, root = 3;
long long modpow(long long a, long long e) {
  if (e == 0) return 1;
  long long x = modpow(a * a % mod, e >> 1);
  return e & 1 ? x * a % mod : x;
}
void ntt(long long* x, long long* temp, long long* roots, int N, int skip) {
  if (N == 1) return;
  int n2 = N / 2;
  ntt(x, temp, roots, n2, skip * 2);
  ntt(x + skip, temp, roots, n2, skip * 2);
  for (int i = 0; i < (N); ++i) temp[i] = x[i * skip];
  for (int i = 0; i < (n2); ++i) {
    long long s = temp[2 * i], t = temp[2 * i + 1] * roots[skip * i];
    x[skip * i] = (s + t) % mod;
    x[skip * (i + n2)] = (s - t) % mod;
  }
}
void ntt(vector<long long>& x, bool inv = false) {
  long long e = modpow(root, (mod - 1) / (int)(x).size());
  if (inv) e = modpow(e, mod - 2);
  vector<long long> roots((int)(x).size(), 1), temp = roots;
  for (int i = 1; i <= ((int)(x).size() - 1); ++i)
    roots[i] = roots[i - 1] * e % mod;
  ntt(&x[0], &temp[0], &roots[0], (int)(x).size(), 1);
}
vector<long long> conv(vector<long long> a, vector<long long> b) {
  int s = (int)(a).size() + (int)(b).size() - 1;
  if (s <= 0) return {};
  int L = s > 1 ? 32 - __builtin_clz(s - 1) : 0, n = 1 << L;
  if (s <= 200) {
    vector<long long> c(s);
    for (int i = 0; i < ((int)(a).size()); ++i)
      for (int j = 0; j < ((int)(b).size()); ++j)
        c[i + j] = (c[i + j] + a[i] * b[j]) % mod;
    return c;
  }
  a.resize(n);
  ntt(a);
  b.resize(n);
  ntt(b);
  vector<long long> c(n);
  long long d = modpow(n, mod - 2);
  for (int i = 0; i < (n); ++i) c[i] = a[i] * b[i] % mod * d % mod;
  ntt(c, true);
  c.resize(s);
  return c;
}
vector<vector<long long> > g;
vector<long long> solve(int l, int r) {
  if (l == r) return g[l];
  int m = (l + r) / 2;
  vector<long long> a = solve(l, m);
  vector<long long> b = solve(m + 1, r);
  return conv(a, b);
}
int a[200009];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  pre();
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n); ++i) {
    if (a[i] == a[(i + 1) % n]) {
      g.push_back({0, k, 0});
    } else {
      g.push_back({1, k - 2, 1});
    }
  }
  vector<long long> ans = solve(0, n - 1);
  long long fns = 0;
  for (int i = n + 1; i <= (2 * n); ++i) fns += ans[i];
  cout << (fns % mod + mod) % mod;
  return 0;
}
