Polish version    English version  
  History of OI -> VI OI 1998/1999 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
VI Olimpiada Informatyczna 1998/1999

Task: GRA
Author:
Polygons

I stage contest  

Two players take part in the game polygons. A convex polygon with n vertices divided by n-3 diagonals into n-2 triangles is necessary. These diagonals may intersect in vertices of the polygon only. One of the triangles is black and the remaining ones are white. Players proceed in alternate turns. Each player, when its turn comes, cuts away one triangle from the polygon. players are allowed to cut off triangles along the given diagonals. The winner is the player who cuts away the black triangle.
NOTE: We call a polygon convex if a segment joining any two points of the polygon is contained in the polygon.

Task

Write a program which: 

  • reads from the text file GRA.IN the description of the polygon,
  • verifies whether the player who starts the game has a winning strategy,
  • writes the result into the file GRA.OUT.

Input

The first line of the input file GRA.IN contains an integer n, 4 <= n <= 50000. This is the number of vertices in the polygon. The vertices of the polygon are numbered, clockwise, from 0 to n-1.
The next n-2 lines comprise descriptions of triangles in the polygon. In the i+1-th line, 1 <= i <= n-2, there are three non-negative integers a, b, c separated by single spaces. Theses are numbers of vertices of the i-th triangle. The first triangle in a sequence is black.

Output

The output file GRA.OUT should have one line with the word:

  • TAK (means "yes" in Polish), if the player, who starts the game has a winning strategy,
  • NIE (means "no" in Polish), if he does not have a winning strategy.

Example

For the input file GRA.IN:

6
0 1 2
2 4 3
4 2 0
0 5 4

the correct answer is the text file GRA.OUT:

TAK

Your program should look for the file GRA.IN in the current directory and produce the output file GRA.OUT in current directory too. The file containing source code of your program should have a name GRA.???, whereas you should put three-letter abbreviation of used programming language name instead of ???. The same program in executable form should be written in file GRA.EXE




Print friendly version