Locust Locus
면접 대비시간 제한1초메모리 제한1024 MB
마지막 목격 연도 y와 주기 c1, c2가 주어진 여러 쌍에 대해 2021년 이후 두 주기가 동시에 돌아오는 가장 빠른 해를 구한다.
문제
There are two different species of periodical cicadas that only appear from hibernation every and years, respectively. Your old grandpa tells you that he saw them simultaneously back in '92. You start pondering how many years you have to wait until you see them again. You collect information about other pairs of periodical cicadas and when they were last observed to find out when the next simultaneous appearance is.
Given several different pairs of cicadas and their last simultaneous appearance, find the next year that one of the pairs reappears.
입력
The first line of input contains a single integer (), the number of pairs of periodical cicadas. Then follow lines, each containing three integers , and (, ), the year this pair was last observed and cycle lengths for the first and second species, respectively. You may assume that none of the pairs reappears earlier than .
출력
Output the first year a pair reappears.