Under construction

Still being built. Things may change

Well Off

Interview

Time limit2sMemory limit128 MB

Summary
Given pairwise inequalities of the form plus or minus x_i plus or minus x_j greater than 0, decide whether some assignment of fortunes satisfies all of them.
Level

Medium5 of 10

Topics
Graph, DFS
Solved
No attempts yet

Problem

Thanks to his hard work, John, formerly Johnny, has become a member of the respectable Well Off Club. The club has nn members, numbered from 1 to nn. The ii-th member has a fortune worth xix_i. These can be arbitrary numbers, including negative ones. Club membership is for life. Neither impoverishment nor even bankruptcy results in an ousting.

The members enjoy comparing their assets, but they never state the numbers directly. Instead, they hold a conversation that establishes whether xix_i and xjx_j satisfy one of xi+xj>0x_i + x_j > 0, xi−xj>0x_i - x_j > 0, −xi+xj>0-x_i + x_j > 0, or −xi−xj>0-x_i - x_j > 0.

Johnny heard many such inequalities at the club today, but he suspects some members are lying. Write a program that reads the inequalities he heard, determines whether they can all be true at once, that is, whether some set of fortunes satisfies all of them simultaneously, and prints the answer to standard output.

Input

The first line contains two integers nn and mm separated by a space (1≤n≤100 0001 \le n \le 100\,000, 1≤m≤500 0001 \le m \le 500\,000). nn is the number of club members and mm is the number of inequalities relating their fortunes.

Each of the next mm lines contains a sign + or -, an integer ii (1≤i≤n1 \le i \le n), another sign + or -, and an integer jj (1≤j≤n1 \le j \le n), separated by single spaces. This encodes the inequality ±xi±xj>0\pm x_i \pm x_j > 0, where each sign is the one written directly before ii or jj. It is possible that i=ji = j.

Output

Print a single word on the only line of output. Print TAK if the system of inequalities is satisfiable, and NIE otherwise.

Hint

In Sample 1, the system is satisfiable, for example with x1=3x_1 = 3, x2=2x_2 = 2, x3=1x_3 = 1. In Sample 2, the system is not satisfiable.

Examples2

  1. Example 1

    Input
    3 3
    + 1 - 2
    - 3 + 1
    + 2 - 3
    
    Expected output
    TAK
    
  2. Example 2

    Input
    3 3
    + 1 - 2
    + 3 - 1
    + 2 - 3
    
    Expected output
    NIE