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.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.