409712: GYM103698 B Majhong

Memory Limit:128 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Majhongtime limit per test1 secondmemory limit per test128 megabytesinputstandard inputoutputstandard output

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.

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.

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.
  • "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".

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.

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".

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 Yes, otherwise print No.

ExamplesInput
9 3 3
4 1 1 1 1 2 1 1 3
Output
Yes
Input
9 3 4
2 1 0 2 2 2 0 1 2
Output
No
Note

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$$$.

加入题单

上一题 下一题 算法标签: