P2593 [ZJOI2006] Super Mahjong
Description
Many people know how to play Mahjong; of course, some do not. Don’t worry, here is a brief introduction to the rules.
In standard Mahjong, there are three suits: "Tong", "Suo", and "Wan". Each suit has numbers $1\sim9$, and there are four copies of each identical tile. For example, `1Tong`\~`9Tong`, `1Suo`\~`9Suo`, and `1Wan`\~`9Wan` each have $4$ copies, so there are $36\times 3=108$ tiles in total. When someone wins, each player has $14$ tiles. A winning hand consists of several melds (either three consecutive tiles of the same suit, or three identical tiles), plus one pair. Of course, if the hand consists entirely of pairs, called “Seven Pairs”, it is also a winning hand. The figure below shows an example of three in sequence.

To judge whether someone can win, an obviously naive algorithm would do. A Mahjong fanatic from a middle school informatics club thought about it and decided to modify standard Mahjong into Super Mahjong.
In Super Mahjong, there is no distinction between suits. The number on each tile can be $1\sim100$, and there are $100$ copies of each number. What’s more, players are free to hold as many tiles as they like. Exciting!
Exciting as it is, how do you form a winning hand with many tiles?
Super Mahjong defines that a hand is winning if the tiles can be partitioned into several melds (one meld can be three consecutive numbers, one tile each; or three or four identical numbers also count as one meld), plus one pair of identical tiles.
As an informatics contestant, please write a program to determine whether the player can win.
Input Format
The first line contains an integer $N(N\le 100)$, indicating that Super Mahjong was played $N$ times.
The next $N$ lines each contain $100$ numbers $a_1 \dots a_{100}$, describing the counts of each tile number in that round. $a_i$ means there are $a_i$ tiles with number $i$. $(0\le a_i\le 100)$
Output Format
Output $N$ lines. Print `Yes` if it is a winning hand; otherwise print `No`. Note the case of `Yes` and `No`.
Explanation/Hint
Translated by ChatGPT 5