QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 10

#1380. Problem Selection [C]

Statistics

Preparing the remote rounds of the Potyczki Algorytmiczne competition is quite a challenge for Mateusz. During the competition, participants take part in five rounds, numbered 1 to 5, and in each round, they solve problems from three divisions, called A, B, and C. During each of the first four rounds, one problem appears in each division, and during the last, fifth round, two problems appear in each division. Therefore, it is necessary to invent and prepare eighteen problems and assign them to fifteen different positions, where three positions (5A, 5B, and 5C) must be assigned two problems each. By position, we mean a combination of the round number and the division name.

Mateusz is aware that he cannot simply use any eighteen problems. Their difficulty should match the round and the division in which they appear. Throughout the year, he has collected $n$ ideas for problems. For each of them, he knows which position the problem would be suitable for (and it would not be suitable for any other position).

Mateusz wonders if it is possible to select eighteen of his ideas and assign them to the positions in a correct way. Having access to his notes, help him determine this!

Input

The first line of input contains a single integer $n$ ($1 \le n \le 100$), representing the number of Mateusz's ideas.

The second line contains $n$ words representing the positions for which Mateusz's consecutive problems are suitable. Each of these words consists of exactly two characters: the first character is a digit from the set $\{1, 2, 3, 4, 5\}$, and the second is a letter from the set $\{A, B, C\}$.

Output

The output should contain a single word TAK or NIE, indicating whether it is possible to form a correct set of problems for the remote rounds of Potyczki Algorytmiczne from Mateusz's ideas.

Examples

Input 1

19
3B 4B 5B 4C 5C 3C 1A 5A 5C 3A 5A 2C 1B 2A 5B 5C 2B 1C 4A

Output 1

TAK

Input 2

20
2B 4B 4C 5A 5C 5C 4A 1B 3A 4A 2A 3B 1B 1C 1A 5A 2C 1B 5B 3C

Output 2

NIE

Note

In the first example test, Mateusz has three problem ideas suitable for position 5C. After discarding any one of them, the remaining ideas form a correct set of problems. In the second example test, Mateusz has only one problem suitable for position 5B, so he cannot form a correct set of problems.

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.