#P2421. [NOI2002] 荒岛野人
[NOI2002] 荒岛野人
Description
The island of Crete is known for its tribes of savages. There are caves arranged in a ring on the island. These caves are numbered clockwise as . There are savages living on the island, initially residing in caves in order. Afterward, each year, the -th savage moves forward clockwise by caves and settles there.
Each savage has a lifespan value , i.e., the number of years they live.
The following four figures describe the first four years on an island with caves and three savages. The initial cave numbers of the three savages are ; the number of caves they move each year are ; and their lifespan values are .

Strangely, although there are many savages, no two savages ever occupy the same cave during their lifetimes, so the island remains peaceful and tranquil. Scientists are curious: what is the minimum number of caves needed to maintain peace on the island?
Input Format
The first line contains an integer (), the number of savages.
Lines to each contain three integers (, ), representing the initial cave number, the number of caves moved each year, and the lifespan value for each savage.
Output Format
Output a single number , the minimum possible number of caves. It is guaranteed that the input has a solution and .
3
1 3 4
2 7 3
3 2 1
6
Hint
, , .
It is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号