#include using namespace std; using LL = long long; #define endl '\n' using db = double; template using max_heap = priority_queue; template using min_heap = priority_queue, greater>; constexpr int P = 998244353; using i64 = long long; // assume -P <= x < 2P int norm(int x) { if (x < 0) { x += P; } if (x >= P) { x -= P; } return x; } template T power(T a, LL b) { T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; } struct Z { int x; Z(int x = 0) : x(norm(x)) {} int val() const { return x; } Z operator-() const { return Z(norm(P - x)); } Z inv() const { assert(x != 0); return power(*this, P - 2); } Z &operator*=(const Z &rhs) { x = i64(x) * rhs.x % P; return *this; } Z &operator+=(const Z &rhs) { x = norm(x + rhs.x); return *this; } Z &operator-=(const Z &rhs) { x = norm(x - rhs.x); return *this; } Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); } friend Z operator*(const Z &lhs, const Z &rhs) { Z res = lhs; res *= rhs; return res; } friend Z operator+(const Z &lhs, const Z &rhs) { Z res = lhs; res += rhs; return res; } friend Z operator-(const Z &lhs, const Z &rhs) { Z res = lhs; res -= rhs; return res; } friend Z operator/(const Z &lhs, const Z &rhs) { Z res = lhs; res /= rhs; return res; } friend std::istream &operator>>(std::istream &is, Z &a) { i64 v; is >> v; a = Z(v); return is; } friend std::ostream &operator<<(std::ostream &os, const Z &a) { return os << a.val(); } }; const int N = 1e5 + 100; vector fac(N + 1); vector invfac(N + 1); Z binom(int nn, int mm) { if (nn < mm) return 0; return fac[nn] * invfac[nn - mm] * invfac[mm]; }; void init() // 记得初始化 { fac[0] = 1; for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * i; invfac[N] = 1 / fac[N]; for (int i = N - 1; i >= 0; --i) invfac[i] = invfac[i + 1] * (i + 1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); init(); int n, m; cin >> n >> m; vector a(n + 2); for (int i = 1; i <= n; ++i) cin >> a[i]; int dif = 0; for (int i = 1; i <= n + 1; ++i) dif += (a[i] != a[i - 1]); vector dp(m + 1, vector(n + 2)); dp[0][dif] = 1; for (int i = 1; i <= m; ++i) { for (int j = 0; j <= n + 1; ++j) { int j2 = n + 1 - j; if (j > 0 && j2 > 0) dp[i][j] += dp[i - 1][j] * j * j2; if (j >= 2) dp[i][j - 2] += dp[i - 1][j] * binom(j, 2); if (j2 >= 2) dp[i][j + 2] += dp[i - 1][j] * binom(j2, 2); } } cout << dp[m][0] << endl; return 0; }