{"problem":{"name":"Special Trains","description":{"content":"A railroad running from west to east in Atcoder Kingdom is now complete. There are $N$ stations on the railroad, numbered $1$ through $N$ from west to east. Tomorrow, the opening ceremony of the railr","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc084_c"},"statements":[{"statement_type":"Markdown","content":"A railroad running from west to east in Atcoder Kingdom is now complete.\nThere are $N$ stations on the railroad, numbered $1$ through $N$ from west to east.\nTomorrow, the opening ceremony of the railroad will take place.\nOn this railroad, for each integer $i$ such that $1≤i≤N-1$, there will be trains that run from Station $i$ to Station $i+1$ in $C_i$ seconds. No other trains will be operated.\nThe first train from Station $i$ to Station $i+1$ will depart Station $i$ $S_i$ seconds after the ceremony begins. Thereafter, there will be a train that departs Station $i$ every $F_i$ seconds.\nHere, it is guaranteed that $F_i$ divides $S_i$.\nThat is, for each Time $t$ satisfying $S_i≤t$ and $t％F_i=0$, there will be a train that departs Station $i$ $t$ seconds after the ceremony begins and arrives at Station $i+1$ $t+C_i$ seconds after the ceremony begins, where $A％B$ denotes $A$ modulo $B$, and there will be no other trains.\nFor each $i$, find the earliest possible time we can reach Station $N$ if we are at Station $i$ when the ceremony begins, ignoring the time needed to change trains.\n\n## Constraints\n\n*   $1≤N≤500$\n*   $1≤C_i≤100$\n*   $1≤S_i≤10^5$\n*   $1≤F_i≤10$\n*   $S_i％F_i=0$\n*   All input values are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$C_1$ $S_1$ $F_1$\n$:$\n$C_{N-1}$ $S_{N-1}$ $F_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc084_c","tags":[],"sample_group":[["3\n6 5 1\n1 10 1","12\n11\n0\n\nWe will travel from Station $1$ as follows:\n\n*   $5$ seconds after the beginning: take the train to Station $2$.\n*   $11$ seconds: arrive at Station $2$.\n*   $11$ seconds: take the train to Station $3$.\n*   $12$ seconds: arrive at Station $3$.\n\nWe will travel from Station $2$ as follows:\n\n*   $10$ seconds: take the train to Station $3$.\n*   $11$ seconds: arrive at Station $3$.\n\nNote that we should print $0$ for Station $3$."],["4\n12 24 6\n52 16 4\n99 2 2","187\n167\n101\n0"],["4\n12 13 1\n44 17 17\n66 4096 64","4162\n4162\n4162\n0"]],"created_at":"2026-03-03 11:01:14"}}