QOJ.ac

QOJ

حد الوقت: 5 s حد الذاكرة: 512 MB مجموع النقاط: 100

#433. Gacha

الإحصائيات

Card Drawing

Bob likes drawing cards.

Bob recently started playing a card game called "Lord Connection". There are $n$ different characters in the game, numbered $1 \sim n$. When Bob obtains $k$ cards with consecutive numbers, he can form the theoretically strongest lineup.

There are $m$ different cards in the current card pool. Each time Bob draws a card, he has an equal probability of obtaining any card from the pool. If Bob draws a card he already possesses, nothing happens, and the draw opportunity is wasted. Bob is a cautious person, and he wants to know the expected number of draws required to stop drawing once he has obtained $k$ cards with consecutive numbers.

Input

The first line contains two integers $m, k$.

The second line contains $m$ distinct integers $a_1, a_2, \dots, a_m$, representing the characters available in the card pool.

The value $n$ in the problem statement is the maximum value among $a_i$.

Output

Output a single integer representing the expected number of draws modulo $p = 998244353$. That is, if the expected value is represented as an irreducible fraction $\frac{a}{b}$, you need to output an integer $c$ such that $c \times b \equiv a \pmod{p}$.

Examples

Input 1

3 2
1 2 3

Output 1

499122180

Note 1

If the first card drawn is card 2, the expected number of draws is $1 + \frac{3}{2}$; if the first card drawn is card 1 or card 3, the expected number of draws is $1 + 3$. Therefore, the answer is $\frac{1}{3}(1 + \frac{3}{2}) + \frac{2}{3}(1 + 3) = 3.5$.

Input 2

10 2
1 2 3 4 5 7 8 9 11 12

Output 2

839792873

Constraints

  • For the first 10% of data, $m \le 10$.
  • For another 10% of data, $m \le 500$ and $k = m - 1$.
  • For another 10% of data, $m \le 500$ and it is guaranteed that there is exactly one theoretically strongest lineup.
  • For another 10% of data, $m \le 500$ and it is guaranteed that any two possible theoretically strongest lineups are disjoint.
  • For the first 50% of data, $m \le 500$.
  • For the first 70% of data, $m \le 5000$.
  • For another 10% of data, $k = 5$.
  • For another 10% of data, $k = 2000$.
  • For 100% of data, $1 \le m \le 200000$, $1 \le a_i \le 2m$, $2 \le k \le m$. It is guaranteed that there is at least one theoretically strongest lineup (i.e., $k$ cards with consecutive numbers) that can be drawn from the pool.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.