Under construction

Still being built. Things may change

Impossible Design

Time limit1sMemory limit128 MB

Summary
Given the circle order of a permutation of 0 to N-1, decide whether chords drawn between every pair at height x+y ever intersect.
Level

Medium6 of 10

Topics
Geometry, Combinatorics, Array
Solved
No attempts yet

Problem

NN pillars stand on a circle. Each pillar carries one integer between 00 and N−1N-1, and no integer is written twice.

For every pair of integers (x,y)(x, y) with 0≤x<y≤N−10 \le x < y \le N-1, you join the pillar that carries xx and the pillar that carries yy with one rod. The rod is parallel to the ground and floats at height x+yx+y. Assume the pillars are tall enough.

If two rods overlap, the rods cannot be placed this way. Decide whether two rods overlap before you place any of them.

Input

The first line contains the number of pillars NN. (2≤N≤1 000 0002 \le N \le 1\,000\,000)

The second line contains the numbers written on the pillars, given in the order you meet them while walking around the circle in one direction. The sequence is a permutation of 0,1,…,N−10, 1, \dots, N-1.

Output

Print TAK if two rods overlap, and NIE otherwise.

Examples2

  1. Example 1

    Input
    4
    0 1 2 3
    
    Expected output
    NIE
    
  2. Example 2

    Input
    4
    0 1 3 2
    
    Expected output
    TAK