This page is still under construction.

Parts of this page are still being built. What you see may change.

Polygons

Time limit1sMemory limit128 MB

Summary
A convex polygon is triangulated, one triangle is black; players alternately cut off an ear triangle, and whoever removes the black triangle wins. Decide if the first player wins.
Level

Hard8 of 10

Topics
Game theory, Tree, DFS, Greedy
Solved
No attempts yet

Problem

Two players play the game of polygons. You are given a convex polygon with nn vertices that has been divided by n−3n-3 pairwise non-crossing diagonals into n−2n-2 triangles. The diagonals meet only at vertices of the polygon. One of the triangles is black and all of the others are white.

The players move in alternating turns. On a turn, the current player cuts exactly one triangle away from the current polygon along a diagonal. The only triangle that may be cut off is one that has a diagonal as one of its sides and two sides of the current polygon as its other two sides; cutting it removes that triangle from the polygon. The player who cuts away the black triangle wins.

A polygon is convex if the segment joining any two of its points lies entirely inside the polygon.

Write a program that reads the description of the polygon and decides whether the player who moves first has a winning strategy.

Input

The first line contains an integer nn, the number of vertices of the polygon (4≤n≤500004 \le n \le 50000). The vertices are numbered clockwise from 00 to n−1n-1.

Each of the next n−2n-2 lines describes one triangle. The ii-th of these lines (1≤i≤n−21 \le i \le n-2) contains three non-negative integers aa, bb, cc separated by single spaces, the numbers of the vertices of the ii-th triangle. The triangle given first is the black one.

Output

Print a single line containing TAK if the player who moves first has a winning strategy, or NIE otherwise. (TAK and NIE mean 'yes' and 'no' in Polish.)

Examples4

  1. Example 1

    Input
    6
    0 1 2
    2 4 3
    4 2 0
    0 5 4
    
    Expected output
    TAK
    
  2. Example 2

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

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

    Input
    6
    0 2 3
    0 1 2
    0 3 4
    0 4 5
    
    Expected output
    TAK