/* -*- coding: utf-8 -*- * * 3391.cc: No.3391 Line up Dominoes - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 10000; const int MAX_M = 10000; const int MOD = 998244353; /* typedef */ template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator-() const { return MI(MOD - v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI; /* global variables */ int as[MAX_N], ls[MAX_N], rs[MAX_N]; mi dp[2][MAX_N + 1]; /* subroutines */ /* main */ int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", as + i); sort(as, as + n); for (int i = 0; i < n; i++) { ls[i] = lower_bound(as, as + n, as[i] - k) - as; rs[i] = upper_bound(as, as + n, as[i] + k) - as; } fill(dp[0], dp[0] + n + 1, 1); int cur = 0, nxt = 1; for (int i = 1; i < m; i++) { fill(dp[nxt], dp[nxt] + n + 1, 0); for (int j = 0; j < n; j++) { auto dj = dp[cur][j]; dp[nxt][ls[j]] += dj; dp[nxt][rs[j]] -= dj; } for (int j = 0; j < n; j++) dp[nxt][j + 1] += dp[nxt][j]; swap(cur, nxt); } mi sum = 0; for (int j = 0; j < n; j++) sum += dp[cur][j]; printf("%d\n", (int)sum); return 0; }