QOJ.ac

QOJ

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

#10660. Orienteering [B]

统计

Byteman is organizing an orienteering competition. Participants will be given a map that indicates checkpoints, and they are to visit each one of them in a given order. By the traditions of Byteland, the route has to be a closed loop. An appropriate area has been found and the route planned accordingly. However, the starting point, which will be the first and the last to visit, and the race direction are yet to be chosen.

Byteman decided that every part of the race should not be more difficult than a previous one. He walked the entire way noting stage difficulty between every two consecutive checkpoints as positive integer numbers. The higher the number is, the more difficult the corresponding part of the route. Your task is to check whether there exist such starting point and race direction, that Byteman's constraint is satisfied.

Input Format

The first line of the standard input contains an integer $ n $ (2 ≤ $ n $ ≤ 100 000) denoting the number of all checkpoints on the route. The checkpoints are numbered from 1 to $ n $. In the second line, there is a sequence of $ n $ integers $ t_{i} $ (1 ≤ $ t_{i} $ ≤ 1 000 000 000), in which $ i $-th number describes difficulty of the stage between checkpoints $ i $ and $ i $ + 1, except for $ t_{n} $, which denotes the difficulty of the stage between checkpoints $ n $ and 1.

Output Format

In the first line of the standard output your program should output "TAK" (meaning yes, without the quotes), if there is a starting point and race direction satisfying Byteman's condition, and "NIE" (meaning no) otherwise.

Example

Input

5
3 8 10 1 3

Output

TAK

Notes

In the first example Byteman may set the starting point in the fourth checkpoint (i.e., at the end of the stage with difficulty 10) and the competitors can start the race going towards the third checkpoint. The consecutive stages on their way will have difficulties equal to 10, 8, 3, 3 and 1. In the second example no solution exists.

problem_10660_1.gif

The route of the orienteering competition in the first example. The circles contain the numbers of checkpoints, and the numbers next to the edges represent the difficulties of the stages in the route. The arrows in the picture show valid starting point and race direction.

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.