A higher resolution is required to access the IDE

- 34

## Statement

## Goal

**Mahjong**is a tabletop game played using tiles. It features three "number" suits (pins, sous, mans, represented as

https://user-images.githubusercontent.com/5595067/33491135-4ac4b4e6-d6f4-11e7-8df6-038f113fcef9.png

To complete a hand and win, the 13 tiles in your hand are combined with 1 newly drawn tile and must result in one of the following winning configurations:

•

**4 sets**and

**1 pair**, self-explanatory

•

**seven pairs**, where all pairs are distinct (twice the same pair wouldn't qualify)

•

**kokushi musou**: one of each of the

A

**pair**is any of the two same tiles:

A

**set**consists of 3 tiles of the same suit. It can either be a

**run**: 3 number tiles (

**triplet**of any suit, not necessarily numbers, like

So honor tiles (non-numbers, represented by

A single tile can only be counted as part of one set or pair: there is no sharing or reusing.

Given a

`sorted hand`of

`tile`, check whether the

Input

**Line 1:**A

`sequence`of numbers and letters,

`tile`of a number and a letter

In the notation, the numeric value of every tile in a suit comes first, then the suit's letter. Tiles are grouped per suit, so each letters is written at most once. The three numbers suits are ordered from

As you may have gathered from the statement, in this puzzle the honor suit's tiles are represented as digits for ease of parsing and distinction, but they do not behave like numbers.

Output

**Line 1:**

Constraints

14 ≤ length of

length of

`sequence`≤ 17length of

`tile`= 2Example

Input

222888m444p2277z 7z

Output

TRUE

A higher resolution is required to access the IDE

Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!

JOIN US ON DISCORD Online Participants