Problems
The Genome of Newton
The Genome of Newton
On a planet Olimpiya a study the genome of inhabitants of the Olympic galaxy is completed. It appeared that the genome which deciphered can be given as a set of integers which can repeat. In presentation of the genome of talented personality among other there is a one which meets one times and determines the number of the certain genetically conditioned talent.
The developed equipment gets presentation to the genome as a set of plurals of numbers. Every plural is set of four numbers \textbf{s}, \textbf{f}, \textbf{a}, \textbf{b}. There are \textbf{a} послідовних successive integers belong to such plural beginning from \textbf{s}, next \textbf{b} numbers is not belonged to the plural, followings and belong again, and etc. All of numbers in a plural are no more then \textbf{f}. For example, a plural (\textbf{s} = \textbf{1}, \textbf{f }= \textbf{10}, \textbf{a }= \textbf{2}, \textbf{b }= \textbf{1}) has numbers: \textbf{1}, \textbf{2}, \textbf{4}, \textbf{5}, \textbf{7}, \textbf{8}, \textbf{10}, and plural (\textbf{s} = \textbf{5}, \textbf{f }= \textbf{50}, \textbf{a }= \textbf{1}, \textbf{b }= \textbf{19}) has numbers: \textbf{5}, \textbf{25}, \textbf{45}.
Write the program, that after presentation to the genome as a set of plurals of numbers will set, whether his proprietor has some genetically conditioned talent, and will define his number.
\InputFile
There is the quantity of plurals \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{10 000}) in a set in the first line of input. Next \textbf{N} lines set plurals. Every plural is set of four numbers - \textbf{s}, \textbf{f}, \textbf{a}, \textbf{b} (\textbf{1} ≤ \textbf{s}, \textbf{f}, \textbf{a}, \textbf{b} < \textbf{10^9}; \textbf{s ≤ f}). It is guaranteed, that no more presentation to the genome contains one number which meets just one time.
\OutputFile
Print the number which meets odd number of times in genome presentation, or \textbf{0}, if such number does not exist.
Input example #1
4 7 59 1 9 7 82 1 49 17 50 1 29 27 27 1 1
Output example #1
37