#P3422. [POI 2005] LOT-A Journey to Mars

[POI 2005] LOT-A Journey to Mars

Description

All space stations on Mars lie on a circle. Byteazar lands at one of the stations and then starts traveling around the circle.

Travel consumes fuel: 11 liter of fuel allows traveling 11 meter. Each station provides a different amount of fuel.

At each station, Byteazar may take all the fuel available there (his fuel tank has no capacity limit). However, if at any moment he runs out of fuel while moving, the trip fails.

Byteazar needs to decide at which station to land so that he can successfully visit all stations and return to his starting station. After landing, he may choose either direction to travel.

Input Format

The first line contains an integer nn, the number of stations. The stations are numbered from 11 to nn.

Then follow nn lines. Each of the next nn lines contains two integers pi,dip_i, d_i. The (i+1)(i + 1)-th line describes station ii, where pip_i is the amount of fuel available at station ii, and did_i is the distance from station ii to station i+1i + 1. For station nn, did_i is the distance from station nn to station 11.

Output Format

Output nn lines, each containing the string TAK or NIE.

If landing at station ii is feasible, print TAK on line ii; otherwise, print NIE.

5
3 1
1 2
5 2
0 1
5 4

TAK
NIE
TAK
NIE
TAK

Hint

Constraints

For 100%100\% of the testdata, 3n1063 \le n \le 10^6, pi0p_i \ge 0, di>0d_i > 0, and di,pi2×109\sum d_i, \sum p_i \le 2 \times 10^9.

Translated by ChatGPT 5