Viruses

Time Limit:1000ms Memory Limit:64000KiB
Accepted:0 Submitted:0
Viruses

POI VII Stage 1 Problem 2

Viruses

Binary Viruses Investigation Committee detected, that certain sequences of zeroes and ones are codes of viruses. The committee isolated a set of all the virus codes. A sequence of zeroes and ones is called safe, if any of its segments (i.e. sequence of consecutive elements) is not a virus code. The committee is aiming at finding, whether an infinite, safe sequence of zeroes and ones exists.

Example

For a set of codes {011, 11, 00000}, the sample infinite safe sequence is 010101... . For a set of codes {01, 11, 00000} an infinite safe sequence of zeroes and ones does not exist.

Task

Write a program, which:

  • reads virus codes from the text file WIR.IN,
  • determines, whether an infinite, safe sequence of zeroes and ones exists
  • writes the result to the text file WIR.OUT.

Input

The first line of the input file WIR.IN consists of one integer n standing for the number of all virus codes. Each of the next n lines consists of one non-empty word composed from 0s and 1s - a virus code. The total length of all words does not exceed 30000.

Output

In the first and the only line of the output file WIR.OUT one should find a word:

  • TAK - if an infinite, safe sequence of zeroes and ones exists.
  • NIE - otherwise.

Sample Input

3
01 
11 
00000

Sample Output

NIE
SubmitStatistics

SOJ is designed and developed by Wilbur Ding and Liang Sun. ©All Rights Reserved 2009-2012.