QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 128 MB Total points: 100 Hackable ✓

#16578. Mahjong

Statistics

According to Wikipedia, Mahjong or mah-jongg is a tile-based game that was developed in the 19th century in China and has spread throughout the world since the early 20th century. It's a strategic game and the goal of the game is to draw tiles to form a legal hand with 14 tiles.

In the traditional game of Mahjong, there are many different types of tiles. For each type of tiles, there could be different symbols on it representing different numbers. For example, the graph below lists the same type of tiles, and they represent 1 to 9 respectively.

problem_16578_1.png

To simplify the game for this problem, we invent a generalized Mahjong. In our game, there is only one type of tiles, and the numbers on them are 1, 2, 3, ... to $n$. ($n$ could be larger than 9). For example, when $n = 6$, we have the following 6 tiles of the same type of tile.

problem_16578_2.png

In the generalized Mahjong, there can be an unlimited number of tiles for each symbol, and the number of tiles in each player's hands is unlimited as well. $x$ and $y$ will be given as input to define "Pong" and "Chow", in order to explain what is a legal hand.

  • "Pong" means $x$ tiles of the same symbol (number) on them. For example, the picture below shows one case of "Pong" when $x = 3$, and when $x = 2$. They are 3 tiles of 3, and 2 tiles of 3.
    problem_16578_4.png
  • "Chow" means $y$ suited tiles in sequence. The picture below shows two cases when $y = 3$, and when $y = 2$, and one invalid "Chow" as well. The leftmost is (4, 5, 6), the middle is (7, 8), and the rightmost is (1, 9). The rightmost is not a valid "Chow".
    problem_16578_3.png

A legal hand in the generalized Mahjong means that all tiles in one player's hands are a combination of "Pong"s and "Chow"s without any extra tiles.

The picture below shows a legal hand when $n = 9, x = 3$, and $y = 3$. This is also the first sample test case below.

problem_16578_5.png

The picture below shows how the hand of tiles can be divided into "Pong"s and "Chow"s. It's (1, 1, 1) "Pong", (9, 9, 9) "Pong", (1, 2, 3) "Chow", (4, 5, 6) "Chow", (6, 7, 8) "Chow".

problem_16578_6.png

Now given $n, x, y$, the modified rules explained above, and a hand of tiles, please print Yes if it's a legal hand; otherwise please print out No.

Input

The first line contains three integers, representing $n$ ($1 \leq n \leq 10^3$), $x$, and $y$ ($1 \leq x, y \leq 10^9$).

The second line contains $n$ integers $a_1, \dots, a_n$, where $a_i$ is the number of the $i$th tile.

Output

If the hand of tiles is legal, print \texttt{Yes}, otherwise print \texttt{No}.

Example

Input 1

9 3 3
4 1 1 1 1 2 1 1 3

Output 1

Yes

Input 2

9 3 4
2 1 0 2 2 2 0 1 2

Output 2

No

Subtasks

Subtask 1 (40pts): $n=x=y=3$.

Subtask 2 (30pts): $y=n+1$.

Subtask 3 (30pts): No special restrictions.

For $100\%$ of data, $n \leq 1000$, $1 \leq x,y \leq 10^9$, $0 \le a_i \le 10^9$.

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.