Well Off
InterviewTime limit2sMemory limit128 MB
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.
Problem
Thanks to his hard work, John, formerly Johnny, has become a member of the respectable Well Off Club. The club has members, numbered from 1 to . The -th member has a fortune worth . 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 and satisfy one of , , , or .
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 and separated by a space (, ). is the number of club members and is the number of inequalities relating their fortunes.
Each of the next lines contains a sign + or -, an integer (), another sign + or -, and an integer (), separated by single spaces. This encodes the inequality , where each sign is the one written directly before or . It is possible that .
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 , , . In Sample 2, the system is not satisfiable.