Problem list
Log in
#icpc00284 · ICPC NCPC 2021

Locust Locus

Bronze I 5.0 s 2048 MB

There are two different species of periodical cicadas that only appear from hibernation every $13$ and $17$ 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.

Input

The first line of input contains a single integer $k$ ($1 \le k \le 99$), the number of pairs of periodical cicadas. Then follow $k$ lines, each containing three integers $y$, $c_1$ and $c_2$ ($1800 \le y \le 2021$, $1 \le c_1, c_2 \le 99$), the year this pair was last observed and cycle lengths for the first and second species, respectively. You may assume that none of the $k$ pairs reappears earlier than $2022$.

Output

Output the first year a pair reappears.

Example 1

Input
3
1992 13 17
1992 14 18
2001 5 7
Output
2036

Example 2

Input
2
2020 2 3
2019 3 4
Output
2026
Source
ICPC NCPC 2021
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code