Mr. Fantasy likes magic show very much. He does not only like watching magic show, but also like to play magic. This time, he creates a new magic game.
In this game, an assistant is needed. And there should be many boxes numbered 0, 1, 2, 3... When the game begins, the assistant should ask one of the audiences to choose one box and put something into this box. Of course the magician doesn’t know which one is chosen. Then the assistant should request some positive integers from audiences. The assistant will select some numbers and divides them into groups. There are three numbers in each group, represented by U, L and K. The assistant will show the groups of numbers to the magician and the magician can point out which box is chosen.
You may guess out it is the groups of numbers that tells the magician the box number and you are right. However, the calculating method is really complex. For each group of numbers, the magician will get some numbers by formula X = U – K * I (L <= X <= U, I = 0, 1, 2...) and he should remember the times each X appeared. After dealing with all the groups, the X which has appeared odd times is the number of the chosen box. Sometimes the audience won’t put anything into boxes, and there will be no number appeared odd times. The assistant is so clever that at most one number will appear odd times.
As you known now, the method is clear but hard to calculate. So Mr. Fantasy wants you to write a program to calculate this. Can you help him?
Input (Please use standard input, and don’t read or write files.) | |
First line contains one integer M, means there are M groups of numbers. M lines followed, and each line contains three integers, U, L and K. 0< M <20000, 0<= U, L, K < 231
| |
Output (Please use standard output, and don’t read or write files.) | |
One integer represents the chosen box number. If no box has been chosen, you should output “NONE” without double quotation marks. | |
| |
Sample Input | Sample Output |
4 5 1 1 10 6 1 10 1 1 4 4 1 | 4
|
对公式进行转化,由于X = U – K * I,则I =( U – X ) / K ,由于I是整数,因此(U-X)%K=0,而L <= X <= U,可以枚举出所有。
用一个链表记录所有出现的X,并为每个X准备一个位记录其出现的情况。当X出现奇数次,出现记录为TRUE;当X出现偶数次,出现记录为FALSE。