JRNTMRS - Journey to Mars

Byteazar has decided on going to Mars to tour the space stations there being in existence. All Martian space stations lie on a circumference of a circle. Byteazar lands in one of them and then moves around by means of a special vehicle which is powered by an appropriate fuel. A litre of this fuel allows him to travel one meter. However, the provisions of the fuel are meagre, different quantities of it are available in each space station. Byteazar may refuel in the space station he is currently in, though he cannot get more fuel than it is available in that very place (the capacity of his fuel tank is unlimited). This quantity of fuel should allow him to reach the next space station. Byteazar has to decide where to land, so that he can visit all of the space stations. In the end he has to return to the space station in which he has landed. During his journey Byteazar has to travel on the circumference of the circle, constantly in one of the two possible directions.

Task

Write a programme which:

  • reads from the standard input the number of space stations, distances between them and the amount of fuel available in each of them,
  • for each of the space stations checks, whether Byteazar can land there i.e. whether by starting in that very station and travelling in a freely chosen direction he is able to visit all of the space stations and return to his spaceship,
  • writes the outcome to the standard output.

Input

The first line of the standard input contains a single integer N (3 ≤ N ≤ 1,000,000). It denotes the number of space stations on Mars. The space stations are numbered from 1 to N. In the next N lines there is a description of all of the stations and the distances between them. The i + 1st line contains two integers pi and di (pi ≤ 0, di > 0). The first one denotes the amount of fuel (in litres) available in the ith space station. The other denotes the distance (in metres) between the ith and i + 1st space station (obviously dN denotes the distance between the Nth and the 1st space station). The total amount of available fuel, as well as the sum of all distances between the space stations does not exceed 2,000,000,000.

Output

The programme should write N lines to the standard output. The i th line should contain the word TAK (YES is Polish), if Byteazar can land in the i th space station or NIE (NO in Polish) when it is not possible.

Example

For the input data:

5
3 1
1 2
5 2
0 1
5 4

the correct result is:

TAK
NIE
TAK
NIE
TAK

Added by:Krzysztof Lewko
Date:2011-06-28
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:XII POI

hide comments
2020-10-27 21:22:35
Unnecessary use of images for basic math symbols in the first place... Original statement: https://www.oi.edu.pl/old/php/show.php?ac=e152020&module=show&file=zadania/oi12/lot&print=yes .
2020-10-27 20:38:59 David
One way to make it hard to solve is to store image equations on another site, then make the images inaccessible!
2015-10-25 23:20:05 rahul_verma
provide me some tricky cases plz
2013-06-04 20:33:27 Mostafa 36a2
Lots of Fun :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.