QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 10

#10636. Matches [B]

الإحصائيات

On a Saturday morning, $n$ boys will gather on the "Bajtusie" Sports Club field. Fortunately, the number of boys is even. This allows all the boys to spend their Saturday happily playing soccer.

Bajtazar is the club's coach, and he is responsible for selecting the lineups for the individual matches. Bajtazar knows that the boys love to compete, so he decided to arrange the team lineups in such a way that every two boys have a chance to play against each other in some match (i.e., to play on opposing teams at least once).

Taking the boys' skills into account, Bajtazar has already proposed the team lineups for the next $m$ matches. In each match, all the boys will play, divided into two teams of $n/2$ players each. Help Bajtazar determine whether every pair of boys will play against each other in at least one of the scheduled matches.

Input

The first line of input contains two integers $n$ and $m$ ($4 \le n \le 40\,000$, $1 \le m \le 50$), representing the number of boys and the number of scheduled matches. Each boy has a number written on his jersey—an integer between 1 and $n$. The numbers on the boys' jerseys are pairwise distinct.

Each of the next $m$ lines contains $n$ pairwise distinct integers in the range from 1 to $n$ describing the team lineups for the individual matches. The first $n/2$ numbers in each line are the numbers of the players on the first team, and the second $n/2$ numbers are the numbers of the players on the second team.

Output

Your program should output a single word TAK (YES) or NIE (NO), depending on whether every pair of boys will play against each other in at least one match or not.

Examples

Input 1

6 3
4 6 1 3 5 2
1 4 5 2 3 6
1 2 6 4 5 3

Output 1

TAK

Input 2

6 3
4 6 1 3 5 2
1 4 5 2 3 6
1 2 3 4 5 6

Output 2

NIE

Note

In the first example, every pair of players plays on opposing teams in one match (e.g., players numbered 1 and 6), in two matches (e.g., players 1 and 2), or even in all three matches (e.g., players 1 and 3). In the second example, players numbered 2 and 3 always play on the same team.

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.