#P4403. Unique Odd Evaluation Spot

    ID: 17649 Type: Default 1000ms 256MiB

Unique Odd Evaluation Spot

Unique Odd Evaluation Spot

During a teaching evaluation period, student Qin Teng observes that the evaluation team is organized into N groups. Each group of team members is arranged along the road from the dormitory to the teaching building, forming an arithmetic sequence. A group is completely described by three integers S, E and D. In a group, team members are located at positions:

[ S,; S+D,; S+2D,; \dots,; S+K; \text{where}; S+K \le E ; \text{and}; S+(K+1)D > E. ]

Qin Teng has discovered that if there is a position on the road where an odd number of evaluation team members stand, he can use that position as a breakthrough point to reach the teaching building. Although such a situation is extremely rare by design, if it happens it will occur at most at one location.

Your task is to determine whether such a position exists. If so, output the position and the number of team members at that position; otherwise, output NOTHING.

inputFormat

The first line contains an integer N (N ≥ 1), the number of groups.

Each of the following N lines contains three integers: S, E and D, which describe a group. It is guaranteed that for any valid input, if there is a position with an odd number of members, then it is unique.

Note: S, E and D define an arithmetic progression: S, S+D, S+2D, …, where the largest term does not exceed E.

outputFormat

If there exists a position on the road where the number of evaluation team members is odd, output two space‐separated integers: the position and the number of team members at that position. Otherwise, output the string NOTHING.

sample

3
2 10 2
2 10 2
5 5 1
5 1