#line 2 "/root/AtCoder/Halc-Library/Template/Template.hpp" #include using namespace std; #line 8 "/root/AtCoder/Halc-Library/Template/InOut.hpp" inline void scan() {} inline void scan(int32_t &a) { std::cin >> a; } inline void scan(uint32_t &a) { std::cin >> a; } inline void scan(int64_t &a) { std::cin >> a; } inline void scan(uint64_t &a) { std::cin >> a; } inline void scan(char &a) { std::cin >> a; } inline void scan(float &a) { std::cin >> a; } inline void scan(double &a) { std::cin >> a; } inline void scan(long double &a) { std::cin >> a; } inline void scan(std::vector &vec) { for (int32_t i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } } inline void scan(std::string &a) { std::cin >> a; } template inline void scan(std::vector &vec); template inline void scan(std::array &vec); template inline void scan(std::pair &p); template inline void scan(T (&vec)[size]); template inline void scan(std::vector &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::deque &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::array &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::pair &p) { scan(p.first); scan(p.second); } template inline void scan(T (&vec)[size]) { for (auto &i : vec) scan(i); } template inline void scan(T &a) { std::cin >> a; } inline void in() {} template inline void in(Head &head, Tail &...tail) { scan(head); in(tail...); } inline void print() { std::cout << ' '; } inline void print(const bool &a) { std::cout << a; } inline void print(const int32_t &a) { std::cout << a; } inline void print(const uint32_t &a) { std::cout << a; } inline void print(const int64_t &a) { std::cout << a; } inline void print(const uint64_t &a) { std::cout << a; } inline void print(const char &a) { std::cout << a; } inline void print(const char a[]) { std::cout << a; } inline void print(const float &a) { std::cout << a; } inline void print(const double &a) { std::cout << a; } inline void print(const long double &a) { std::cout << a; } inline void print(const std::string &a) { for (auto &&i : a) print(i); } template inline void print(const std::vector &vec); template inline void print(const std::array &vec); template inline void print(const std::pair &p); template inline void print(const T (&vec)[size]); template inline void print(const std::vector &vec) { if (vec.empty()) return; print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::deque &vec) { if (vec.empty()) return; print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::array &vec) { print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::pair &p) { print(p.first); std::cout << ' '; print(p.second); } template inline void print(const T (&vec)[size]) { print(vec[0]); for (auto i = vec; ++i != end(vec);) { std::cout << ' '; print(*i); } } template inline void print(const T &a) { std::cout << a; } inline void out() { std::cout << '\n'; } template inline void out(const T &t) { print(t); std::cout << '\n'; } template inline void out(const Head &head, const Tail &...tail) { print(head); std::cout << ' '; out(tail...); } inline void Yes(bool i = true) { out(i ? "Yes" : "No"); } inline void No(bool i = true) { out(i ? "No" : "Yes"); } inline void Takahashi(bool i = true) { out(i ? "Takahashi" : "Aoki"); } inline void Aoki(bool i = true) { out(i ? "Aoki" : "Takahashi"); } inline void Alice(bool i = true) { out(i ? "Alice" : "Bob"); } inline void Bob(bool i = true) { out(i ? "Bob" : "Alice"); } inline void First(bool i = true) { out(i ? "First" : "Second"); } inline void Second(bool i = true) { out(i ? "Second" : "First"); } inline void Possible(bool i = true) { out(i ? "Possible" : "Impossible"); } inline void Impossible(bool i = true) { out(i ? "Impossible" : "Possible"); } inline void fls() { std::flush(std::cout); } struct IOsetup { IOsetup() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(16); } } iosetup; #line 9 "/root/AtCoder/Halc-Library/Template/Util.hpp" using ll = int64_t; using ld = long double; using ull = uint64_t; using uint = uint32_t; using pll = std::pair; using pii = std::pair; using vl = std::vector; using vvl = std::vector>; using pdd = std::pair; using tuplis = std::array; template using pq = std::priority_queue, std::greater>; constexpr ll LINF = (1LL << 62) - (1LL << 31); constexpr int32_t INF = INT_MAX >> 1; constexpr ll MINF = 1LL << 40; constexpr ld DINF = std::numeric_limits::infinity(); constexpr int32_t MODD = 1000000007; constexpr int32_t MOD = 998244353; constexpr ld EPS = 1e-9; constexpr ld PI = 3.1415926535897932; const ll four[] = {0, 1, 0, -1, 0}; const ll eight[] = {0, 1, 1, 0, -1, -1, 1, -1, 0}; template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } else return false; } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } else return false; } template ll sum(const T &a) { return accumulate(std::begin(a), std::end(a), 0LL); } template ld dsum(const T &a) { return accumulate(std::begin(a), std::end(a), 0.0L); } template auto min(const T &a) { return *min_element(std::begin(a), std::end(a)); } template auto max(const T &a) { return *max_element(std::begin(a), std::end(a)); } #line 1 "/root/AtCoder/Halc-Library/Template/Macro.hpp" #define _overload3(_1, _2, _3, name, ...) name #define _overload4(_1, _2, _3, _4, name, ...) name #define _rep1(i, n) for (int64_t i = 0; i < (n); i++) #define _rep2(i, a, b) for (int64_t i = (a); i < (b); i++) #define _rep3(i, a, b, c) for (int64_t i = (a); i < (b); i += (c)) #define rep(...) _overload4(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__) #define _rrep1(i, n) for (int64_t i = (n) - 1; i >= 0; i--) #define _rrep2(i, a, b) for (int64_t i = (b) - 1; i >= (a); i--) #define rrep(...) _overload3(__VA_ARGS__, _rrep2, _rrep1)(__VA_ARGS__) #define each(i, ...) for (auto&& i : __VA_ARGS__) #define all(i) std::begin(i), std::end(i) #define rall(i) std::rbegin(i), std::rend(i) #define len(x) ((int64_t)(x).size()) #define fi first #define se second #define uniq(x) x.erase(unique(all(x)), std::end(x)) #define vec(type, name, ...) vector name(__VA_ARGS__); #define vv(type, name, h, ...) std::vector> name(h, std::vector(__VA_ARGS__)); #define INT(...) int32_t __VA_ARGS__; in(__VA_ARGS__) #define LL(...) int64_t __VA_ARGS__; in(__VA_ARGS__) #define ULL(...) uint64_t __VA_ARGS__; in(__VA_ARGS__) #define STR(...) std::string __VA_ARGS__; in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; in(__VA_ARGS__) #define LD(...) long double __VA_ARGS__; in(__VA_ARGS__) #define VEC(type, name, size) std::vector name(size); in(name) #define VV(type, name, h, w) std::vector> name(h, std::vector(w)); in(name) #line 3 "/root/AtCoder/Halc-Library/Modint/Modint.hpp" #line 6 "/root/AtCoder/Halc-Library/Modint/Modint.hpp" template struct Modint { uint64_t x; constexpr Modint() noexcept { x = 0; } constexpr Modint(int64_t val) noexcept { x = (val < 0 ? val % (int64_t)(Mod) + Mod : val % Mod); } inline uint64_t _get_mod(uint64_t val) noexcept { const static uint64_t m_inv = (-1ULL) / Mod + 1; uint64_t ret = ((unsigned __int128)(val)*m_inv) >> 64; uint64_t pro = ret * Mod; return (val - pro + (val < pro ? Mod : 0)); } friend std::ostream &operator<<(std::ostream &os, Modint &b) noexcept { return os << b.x; } friend std::istream &operator>>(std::istream &is, Modint &b) noexcept { return is >> b.x; } constexpr uint64_t val() noexcept { return x; } constexpr Modint operator+() noexcept { return (*this); } constexpr Modint operator-() noexcept { return Modint() - (*this); } friend Modint operator+(const Modint lhs, const Modint rhs) noexcept { return Modint(lhs) += rhs; } friend Modint operator-(const Modint lhs, const Modint rhs) noexcept { return Modint(lhs) -= rhs; } friend Modint operator*(const Modint lhs, const Modint rhs) noexcept { return Modint(lhs) *= rhs; } friend Modint operator/(const Modint lhs, const Modint rhs) { return Modint(lhs) /= rhs; } constexpr Modint &operator+=(const Modint rhs) noexcept { x += rhs.x; if (x >= Mod) x -= Mod; return *this; } constexpr Modint &operator-=(const Modint rhs) noexcept { if (x < rhs.x) x += Mod; x -= rhs.x; return *this; } constexpr Modint &operator*=(const Modint rhs) noexcept { x = _get_mod(x * rhs.x); return *this; } friend bool operator==(const Modint lhs, const Modint rhs) noexcept { return lhs.x == rhs.x; } friend bool operator!=(const Modint lhs, const Modint rhs) noexcept { return rhs.x != rhs.x; } constexpr Modint &operator/=(Modint rhs) { return (*this) *= rhs.inv(); } constexpr Modint inv() { int64_t a = (*this).x, b = get_mod(); assert(a != 0); int64_t s = b, t = a; int64_t m0 = 0, m1 = 1; while (t) { int64_t u = s / t; s -= t * u; m0 -= m1 * u; int64_t tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } assert(s == 1); if (m0 < 0) m0 += b; return Modint(m0); } constexpr Modint pow(uint64_t x) noexcept { Modint ret = 1; Modint bin = (*this); while (x) { if (x & 1) ret *= bin; bin *= bin; x >>= 1; } return ret; } static uint64_t get_mod() noexcept { return Mod; } }; template struct ArbitraryModint { uint64_t x; static uint64_t &mod() noexcept { static uint64_t Mod = 0; return Mod; } constexpr ArbitraryModint() noexcept { x = 0; } constexpr ArbitraryModint(int64_t val) noexcept { x = (val < 0 ? val % (int64_t)(get_mod()) + get_mod() : val % get_mod()); } inline uint64_t _get_mod(uint64_t val) noexcept { const static uint64_t m_inv = (-1ULL) / get_mod() + 1; uint64_t ret = ((unsigned __int128)(val)*m_inv) >> 64; uint64_t pro = ret * get_mod(); return (val - pro + (val < pro ? get_mod() : 0)); } friend std::ostream &operator<<(std::ostream &os, ArbitraryModint &b) noexcept { return os << b.x; } friend std::istream &operator>>(std::istream &is, ArbitraryModint &b) noexcept { return is >> b.x; } constexpr uint64_t val() noexcept { return x; } constexpr ArbitraryModint operator+() noexcept { return (*this); } constexpr ArbitraryModint operator-() noexcept { return ArbitraryModint() - (*this); } friend ArbitraryModint operator+(const ArbitraryModint lhs, const ArbitraryModint rhs) noexcept { return ArbitraryModint(lhs) += rhs; } friend ArbitraryModint operator-(const ArbitraryModint lhs, const ArbitraryModint rhs) noexcept { return ArbitraryModint(lhs) -= rhs; } friend ArbitraryModint operator*(const ArbitraryModint lhs, const ArbitraryModint rhs) noexcept { return ArbitraryModint(lhs) *= rhs; } friend ArbitraryModint operator/(const ArbitraryModint lhs, const ArbitraryModint rhs) { return ArbitraryModint(lhs) /= rhs; } constexpr ArbitraryModint &operator+=(const ArbitraryModint rhs) noexcept { x += rhs.x; if (x >= mod()) x -= mod(); return *this; } constexpr ArbitraryModint &operator-=(const ArbitraryModint rhs) noexcept { if (x < rhs.x) x += mod(); x -= rhs.x; return *this; } constexpr ArbitraryModint &operator*=(const ArbitraryModint rhs) noexcept { x = _get_mod(x * rhs.x); return *this; } friend bool operator==(const ArbitraryModint lhs, const ArbitraryModint rhs) noexcept { return lhs.x == rhs.x; } friend bool operator!=(const ArbitraryModint lhs, const ArbitraryModint rhs) noexcept { return rhs.x != rhs.x; } constexpr ArbitraryModint &operator/=(ArbitraryModint rhs) { return (*this) *= rhs.inv(); } constexpr ArbitraryModint inv() { int64_t a = (*this).x, b = get_mod(); assert(a != 0); int64_t s = b, t = a; int64_t m0 = 0, m1 = 1; while (t) { int64_t u = s / t; s -= t * u; m0 -= m1 * u; int64_t tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } assert(s == 1); if (m0 < 0) m0 += b; return ArbitraryModint(m0); } constexpr ArbitraryModint pow(uint64_t x) noexcept { ArbitraryModint ret = 1; ArbitraryModint bin = (*this); while (x) { if (x & 1) ret *= bin; bin *= bin; x >>= 1; } return ret; } static void set_mod(const uint64_t x) noexcept { mod() = x; } static uint64_t get_mod() noexcept { return mod(); } }; template inline void scan(Modint &a) { std::cin >> a.x; } template inline void scan(ArbitraryModint &a) { std::cin >> a.x; } template inline void print(Modint a) { std::cout << a.x; } template inline void print(ArbitraryModint a) { std::cout << a.x; } #line 4 "/root/AtCoder/Halc-Library/Math/ModCombination.hpp" template struct ModCombination { std::vector fact = {1}, rev{1}; ModCombination(uint32_t sz = 0) { fact.reserve(sz+1); rev.reserve(sz+1); } void resize(uint32_t sz) { sz++; if (fact.size() >= sz) return; uint32_t before = fact.size(); fact.resize(sz); rev.resize(sz); for (uint32_t i = before; i < sz; i++) { fact[i] = fact[i - 1] * i; rev[i] = rev[i - 1] / i; } } T comb(int32_t n, int32_t k) { if (n < 0 || k < 0 || n < k) return 0; resize(n); return fact[n] * rev[n - k] * rev[k]; } T perm(int32_t n, int32_t k) { if (n < 0 || k < 0 || n < k) return 0; resize(n); return fact[n] * rev[n - k]; } T multi_comb(int32_t n, int32_t k) { if (k == 0) return 1; return comb(n + k - 1, k); } }; #line 4 "main.cpp" using mint=Modint; ModCombination cb; void solve() { LL(N,K); VEC(ll,A,N); sort(all(A)); mint bef=N; mint ans=0; rep(i,N){ mint now=0; mint inv=cb.comb(N,i+1).inv(); rep(j,N){ ll cnt=max(0L,j-K); if(j==0)cnt+=N; else cnt+=max(0L,N-j-K); now+=cb.comb(cnt,i+1)*inv; /* ll cnt=max(0L,j-K)+(N-1-j); now+=1-(cb.comb(N-1,i)-cb.comb(cnt,i))*inv;*/ } ans+=(bef-now)*A[i]; bef=now; } out(ans*cb.fact[N]); } int main() { solve(); } /*---------------------✂キリトリ線✂----------------------*\ | Coding by hirayuu_At. | | | | ( ゚д゚) | | _(__つ/ ̄ ̄ ̄/_ ∧∧ | | \/ WA / /⌒ヽ) | |  ̄ ̄ ̄ /\ i三 ∪ | | . ∵ ./ ./| 〇三 | | | ∴ \/ / (/~∪ | | (ノ゚Д゚)ノ |/ 三三 終 | | / / 三三 制作・著作 | |  ̄ ̄ ̄ ̄ ̄ ̄ 三三三 ━━━━━━━━━━ | | ⒽⒶⓁⒸ | \*-----------------------✂キリトリ線✂--------------------*/