QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#15269. Super Mahjong

Statistics

Many people know how to play Mahjong, and of course, some do not. Hehe, that's okay; I will briefly introduce the rules of Mahjong here:

Standard Mahjong has three types of tiles: Dots, Bamboo, and Characters. Each type has numbers 1–9, and there are four of each identical tile. For example, there are 4 of each 1-Dot through 9-Dot, 1-Bamboo through 9-Bamboo, and 1-Character through 9-Character, totaling $36 \times 3 = 108$ tiles. To win (a "Hu"), a player must have 14 tiles in their hand, consisting of several "sets" (a set is either three consecutive tiles of the same type or three identical tiles) plus one "pair." Of course, if the hand consists entirely of pairs, it is called "Seven Pairs," which is also a winning hand. The image below shows an example of three consecutive tiles.

Example of three consecutive tiles.

Determining whether someone has won is obviously a trivial algorithm. A high school informatics group, who are super Mahjong fans, decided to transform standard Mahjong into "Super Mahjong."

In Super Mahjong, there is no distinction between Dots, Bamboo, and Characters. The number on each tile can be from 1 to 100, and there are 100 of each type of tile. Additionally, it is very flexible: players can hold as many tiles as they want in their hand. How exciting!

Exciting as it may be, how do you win with so many tiles?

Super Mahjong rules state that a player wins if their hand consists of several "sets" (a set is either one each of three consecutive numbered tiles, or three or four identical numbered tiles) plus one pair of identical tiles.

As an informatics competition contestant, please write a program for this Super Mahjong fan to determine whether a hand can win.

Input

The first line of the input contains an integer $N$ ($N \le 100$), representing the number of times Super Mahjong is played.

The next $N$ lines each contain 100 integers $a_1 \dots a_{100}$, describing the quantity of each type of tile in the hand for each game. $a_i$ represents the number of tiles with the number $i$ ($0 \le a_i \le 100$).

Output

Output $N$ lines. If the hand can win, output Yes; otherwise, output No. Note that Yes and No are case-sensitive!

Examples

Input 1

3
2 4 0 0 0 0 0 ... 0 (98 zeros in total)
2 4 2 0 0 0 0 ... 0 (97 zeros in total)
2 3 2 0 0 0 0 ... 0 (97 zeros in total)

Output 1

Yes
Yes
No

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.