Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
87 - ZOJ Monthly, February 2010 - E
Mahjong

Time Limit: 1 Second      Memory Limit: 32768 KB

Mahjong is a favorite pastime in China. It can be played either with a set of mahjong tiles or a set of mahjong playing cards (sometimes spelled "kards" to distinguish them from the list of standard hands used in American mahjong). One brand of mahjong cards calls these Mhing. Playing cards are often used when travelling, as they take up less space and are lighter than their tile counterparts;however, they are usually of a lower quality. In this article, "tile" will be used to denote both playing cards and tiles.

There are many variations of mahjong. In many places, players often observe one version and are either unaware of other variations or claim that different versions are incorrect. Here, we are using the 13-tile version.

In order to simplify the problem. We only consider 13 tiles of Suit Character (named as each tile represents ten thousand coins, or one hundred strings of one hundred coins):

We use a single integer (1 to 9) to represent a tile (Character 1 to 9) in this problem.

In this simplified problem, consider below melds only(refer to Mahjong - Wikipedia for complete description):

  • A Pong, or Pung, is a set of three identical tiles.
    For example: 9 9 9; 7 7 7;
  • A Chow is a meld of three suited tiles in sequence.
    For example: 1 2 3; 3 4 5; 7 8 9; 5 6 7;
  • An Eye is the pair, while not a meld (and thus cannot be declared or formed with a discard, except if completing the pair completes the hand), is the final component to the standard hand. It consists of any two identical tiles.
    For example: 1 1; 7 7;

A player wins by creating a standard mahjong hand, which consists of a certain number of melds (four for 13-tile version) and a single Eye.

Your task is to figure out which tile can make you win according to 13 tiles you already have.

Note that you can't have more than 4 tiles with a same number at any time.

Input

Multi cases (no more than 25). Process to the end.

Each case has a single line containing 13 integers, which are tiles you already have.

Output

For each case, output tiles that can make you win in one line(sorted, smaller first), separated by one space. There is always a solution.

Sample Input

1 3 4 4 4 4 5 6 6 7 7 7 8

Sample Output

2

Author: WU, Jun
Source: ZOJ Monthly, February 2010
Submit    Status