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 railroad will take place.
On 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.
The 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.
Here, it is guaranteed that F_i divides S_i.
That 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.
For 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.

-----Constraints-----
 - 1≤N≤500
 - 1≤C_i≤100
 - 1≤S_i≤10^5
 - 1≤F_i≤10
 - S_i％F_i=0
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

-----Output-----
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

-----Sample Input-----
3
6 5 1
1 10 1

-----Sample Output-----
12
11
0

We will travel from Station 1 as follows:
 - 5 seconds after the beginning: take the train to Station 2.
 - 11 seconds: arrive at Station 2.
 - 11 seconds: take the train to Station 3.
 - 12 seconds: arrive at Station 3.
We will travel from Station 2 as follows:
 - 10 seconds: take the train to Station 3.
 - 11 seconds: arrive at Station 3.
Note that we should print 0 for Station 3.
[{"code": "def LIHW(h):\n    return [list(map(int, input().split())) for _ in range(h)]\n\n\nN = int(input())\nX = LIHW(N-1)\n\nfor i in range(N-1):\n    time = [0]*N\n    time[i] = X[i][1]+X[i][0]\n    for j in range(i+1, N-1):\n        if time[j-1] <= X[j][1]:\n            time[j] = X[j][1]+X[j][0]\n        else:\n            if (time[j-1]-X[j][1]) % X[j][2] == 0:\n                time[j] = time[j-1] + X[j][0]\n            else:\n                time[j] = time[j-1] + X[j][0]+X[j][2] - \\\n                    ((time[j-1]-X[j][1]) % X[j][2])\n    print(time[j])\nprint(0)", "passed": true, "time": 0.24, "memory": 14064.0, "status": "done"}, {"code": "N = int(input())\n\nCSF = []\nfor _ in range(N-1):\n  C, S, F = map(int, input().split())\n  CSF.append((C, S, F))\n\ndef cnt(x):\n  ret = 0\n  for i in range(x, N-1):\n    C, S, F = CSF[i]\n    if ret < S:\n      ret = S\n      ret += C\n    else:\n      ret = -(-ret//F)*F\n      ret += C\n  return ret\n\nfor x in range(N):\n  print(cnt(x))", "passed": true, "time": 0.25, "memory": 14252.0, "status": "done"}, {"code": "N = int(input())\nCSF = [list(map(int, input().split())) for i in range(N - 1)]\nans = []\nfor i in range(N - 1):\n    temp = 0\n    for j in range(i, N - 1):\n        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]\n        if temp <= s:\n            temp += s - temp\n            temp += temp % f\n        else:\n            temp += (f - ((temp - s) % f)) % f\n        temp += c\n    ans.append(temp)\nfor i in range(N - 1):\n    print((ans[i]))\nprint((0))\n", "passed": true, "time": 0.15, "memory": 14136.0, "status": "done"}, {"code": "n = int(input())\nl = [list(map(int,input().split())) for i in range(n-1)]\nc,s,f = [list(i) for i in zip(*l)]\nfor _ in range(n-1):\n    ans = 0\n    for i in range(_,n-1):\n        if ans < s[i]:\n            ans = s[i]\n        elif ans % f[i] == 0:\n            pass\n        else:\n            ans += f[i] - (ans % f[i])\n        ans += c[i]\n    print(ans)\nprint(0)", "passed": true, "time": 0.18, "memory": 14228.0, "status": "done"}, {"code": "n = int(input())\ncsf = [list(map(int,input().split())) for _ in range(n-1)]\n\nfor i in range(n):\n    time = 0\n    while True:\n        if i == n-1:\n            print(time)\n            break\n        if csf[i][1] <= time and time%csf[i][2] == 0:\n            time += csf[i][0]\n        elif csf[i][1] > time:\n            time = csf[i][1] + csf[i][0]\n        else:\n            time += csf[i][2] - time%csf[i][2] + csf[i][0]\n        i += 1", "passed": true, "time": 0.15, "memory": 14132.0, "status": "done"}, {"code": "N = int(input())\nC = [0] * N\nS = [0] * N\nF = [0] * N\n\nfor i in range(N-1):\n    C[i], S[i], F[i] = map(int, input().split())\n\ndef arrive(st):\n    time = C[st] + S[st]\n    for i in range(st + 1, N-1):\n        if time <= S[i]:\n            time = C[i] + S[i]\n        else:\n            if time % F[i] != 0:\n                time = time + C[i] + (F[i] - time % F[i])\n            else:\n                time = time + C[i]\n    return time\n\nfor i in range(N-1):\n    print(arrive(i))\nprint(\"0\")", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\nT = [0]*n\nc,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)\n \nfor i in range(n-1):\n\tc[i],s[i],f[i] = map(int,input().split())\n\nfor\ti in range(n-1):\n\tT[i] = s[i] + c[i]\n\tfor j in range(i+1,n-1):\n\t\tif T[i] > s[j]:\n\t\t\tT[i] = -((-T[i]//f[j]))*f[j] + c[j]\n\t\telse:\n\t\t\tT[i] = s[j] + c[j]\n\tprint(T[i])\nprint(0)", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "n=int(input())\nt=[]\nfor i in range(n-1):\n  t.append(list(map(int,input().split())))\n\n\nfor i in range(n):\n  s=0\n  for j in range(i,n-1):\n    s=max(t[j][1],((s-1)//t[j][2]+1)*t[j][2])+t[j][0]\n  print(s)", "passed": true, "time": 0.16, "memory": 14144.0, "status": "done"}, {"code": "N = int(input())\nC = []\nS = []\nF = []\nfor _ in range(N-1):\n    c, s, f = map(int, input().split())\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\nfor i in range(N):\n    t = 0\n    for j in range(i, N-1):\n        if t < S[j]:\n            t = S[j]\n        elif t % F[j] != 0:\n            t += F[j]-t%F[j]\n        t += C[j]\n    print(t)", "passed": true, "time": 0.29, "memory": 14088.0, "status": "done"}, {"code": "N = int(input())\n\nx = []\nfor i in range(N - 1):\n    c, s, f = list(map(int, input().split()))\n    x.append([c, s, f])\n\nans = []\nfor i in range(N - 1):\n    t = x[i][0] + x[i][1]\n    for j in range(i + 1, N - 1):\n        if t % x[j][2] == 0:\n            t = max(t, x[j][1])\n        else:\n            t = max(t + (x[j][2] - t % x[j][2]), x[j][1])\n        t += x[j][0]\n    ans.append(t)\nans.append(0)\n\nfor i in range(N):\n    print((ans[i]))\n", "passed": true, "time": 0.15, "memory": 14104.0, "status": "done"}, {"code": "from math import ceil\n\nn = int(input())\ncs = []\nss = []\nfs = []\n\nfor _ in range(n-1):\n    c, s, f = map(int, input().split())\n    cs.append(c)\n    ss.append(s)\n    fs.append(f)\n\nfor i in range(n):\n    t = 0\n    for j in range(i, n-1):\n        if t < ss[j]:\n            t = ss[j]\n        t = ceil(t / fs[j]) * fs[j]\n        t += cs[j]\n    print(t)", "passed": true, "time": 0.15, "memory": 14232.0, "status": "done"}, {"code": "n = int(input())\ncsf = []\nfor i in range(n - 1):\n    csf.append(list(map(int, input().split())))\nfor i in range(n):\n    t = 0\n    for j in range(n - i - 1):\n        c, s, f = (csf[i + j][k] for k in range(3))\n        t = (max(t - 1, s - 1) // f + 1) * f + c\n    print(t)", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "N = int(input())\nC = [list(map(int,input().split())) for _ in range(N-1)]\n\nfor i in range(N-1):\n    now = 0\n    for j in range(i,N-1):\n        now = max(C[j][1], -(-now//C[j][2])*C[j][2])\n        now += C[j][0]\n    print(now)\nprint(0)", "passed": true, "time": 0.2, "memory": 14272.0, "status": "done"}, {"code": "N = int(input())\nCSF = [[] for T in range(0,N-1)]\nfor TN in range(0,N-1):\n    CSF[TN] = [int(T) for T in input().split()]\nfor TN in range(0,N):\n    Time = 0\n    for TT in range(TN,N-1):\n        if Time>=CSF[TT][1]:\n            Time += CSF[TT][0] + (CSF[TT][2]-(Time%CSF[TT][2]))%CSF[TT][2]\n        else:\n            Time += CSF[TT][0] + (CSF[TT][1]-Time)\n    print(Time)", "passed": true, "time": 0.14, "memory": 14244.0, "status": "done"}, {"code": "N = int(input())\nCSF = [ list(map(int,input().split(\" \"))) for _ in range(N - 1)]\n\nfor i in range(N):\n    Time = 0\n    for j in range(i, N - 1):\n        c, s, f = CSF[j]\n        Time = max(Time, s)\n        if Time % f != 0:\n            Time += (f - Time % f)\n        Time += c\n\n    print(Time)", "passed": true, "time": 0.24, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\nc = []\ns = []\nf = []\nfor i in range(n-1):\n  c_, s_ , f_ = map(int, input().split())\n  c.append(c_)\n  s.append(s_)\n  f.append(f_)\n  \nfor i in range(n-1):\n  res = s[i] + c[i]\n  for j in range(i+1, n-1):\n    if res >= s[j]:\n      if (res-s[j]) % f[j] == 0:\n        res = res + c[j] + ((res - s[j]) % f[j])\n      else:\n        res = res + c[j] + f[j] - ((res-s[j])%f[j])\n    else:\n      res = s[j] + c[j]\n  print(res)\nprint(0)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n = int(input())\ngraph =[]\ntime = 0\nfor i in range(n-1):\n    c,s,f = map(int,input().split())\n    graph.append([i,c,s,f])\n\ndef shortest_path(start,end,times):\n    if start == end:\n        return times\n    elif times<=graph[start][2]:\n        times = (graph[start][2]+graph[start][1])\n        return shortest_path(start+1,end,times)\n    elif times%graph[start][3]==0:\n        times += (graph[start][1])\n        return shortest_path(start+1,end,times)\n    else:\n        times = times+graph[start][3]-times%graph[start][3]+graph[start][1]\n        return shortest_path(start+1,end,times)\n\n\nfor i in range(n):\n    print(shortest_path(i,n-1,0))", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "n = int(input())\nstations = []\nfor i in range(n-1):\n    stations.append(list(map(int, input().split())))\n\nans = [0]\ntime_matrix = [[0] * n for i in range(n)]\nfor i in range(n):\n    for j in range(i+1):\n        if i < n-1:\n            if time_matrix[i][j] % stations[i][2] == 0:\n                waiting = 0\n            else:\n                waiting = stations[i][2] - (time_matrix[i][j] % stations[i][2])\n            time_matrix[i+1][j] = max(time_matrix[i][j] + stations[i][0] + waiting, stations[i][0] + stations[i][1])\n\nfor i in range(n):\n    print((time_matrix[n-1][i]))\n", "passed": true, "time": 0.15, "memory": 14292.0, "status": "done"}, {"code": "n = int(input())\nc_s_f = []\nfor i in range(n - 1):\n    line = list(map(int, input().split()))\n    c_s_f.append(line)\n\nfor i in range(n - 1):\n    t = c_s_f[i][0] + c_s_f[i][1]\n    for j in range(i + 1, n - 1):\n        if t <= c_s_f[j][1]:\n            t = c_s_f[j][1] + c_s_f[j][0]\n        else:\n            t = (t + c_s_f[j][2] - 1) // c_s_f[j][2] * \\\n                c_s_f[j][2] + c_s_f[j][0]\n    print(t)\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "n = int(input())\ncsf = [list(map(int,input().split())) for _ in range(n-1)]\n\nfor i in range(n):\n    time = 0\n    while True:\n        if i == n-1:\n            print(time)\n            break\n        if time < csf[i][1]:\n            time = csf[i][1] + csf[i][0]\n        else:\n            if time%csf[i][2] == 0:\n                time += csf[i][0]\n            else:\n                time += csf[i][0] + csf[i][2] -  time%csf[i][2]\n        i += 1\n", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}, {"code": "N=int(input())\nC,S,F=map(list,zip(*[list(map(int,input().split())) for i in range(N-1)]))\nr=[0]*N\nfor i in range(N-2,-1,-1):\n    x=S[i]+C[i]\n    for j in range(i+1,N-1):\n        x=S[j]+C[j] if x<S[j] else -(-x//F[j])*F[j]+C[j]\n    r[i]=x\nprint(*r,sep='\\n')", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "N=int(input())\nC=[list(map(int,input().split())) for _ in range(N-1)]\n\nfor i in range(N-1):\n    c,s,f=C[i]\n    ans=s+c\n    for j in range(i+1,N-1):\n        nc,ns,nf=C[j]\n        # print('D',ans,nc,ns,nf,(ans-ns)%nf)\n        ans=max(ans,ns)\n        m=(ans-ns)%nf\n        if m!=0:ans+=nf-m\n        # print('D',ans,nc,ns,nf,(ans-ns)%nf)\n        ans+=nc\n    print(ans)\nprint(0)", "passed": true, "time": 0.14, "memory": 14092.0, "status": "done"}, {"code": "import sys\n\n\nstdin = sys.stdin\ndef ns(): return stdin.readline().rstrip()\ndef ni(): return int(stdin.readline().rstrip())\ndef nm(): return list(map(int, stdin.readline().split()))\ndef nl(): return list(map(int, stdin.readline().split()))\n\n\ndef main():\n    n = ni()\n    C = []\n    S = []\n    F = []\n    for i in range(n - 1):\n        c, s, f = nm()\n        C.append(c)\n        S.append(s)\n        F.append(f)\n    for i in range(n - 1):\n        time = 0\n        for j in range(i, n - 1):\n            if time <= S[j]:\n                time = S[j] + C[j]\n            else:\n                time = time + (F[j] - (time - S[j]) % F[j]) % F[j] + C[j]\n        print(time)\n    print((0))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14072.0, "status": "done"}, {"code": "n = int(input())\n\nC, S, F = [], [], []\nfor i in range(n-1):\n    c,s,f = map(int, input().split())\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\nfor i in range(n-1):\n    # \u5404i\u99c5\u304b\u3089\u767a\u8eca\u3059\u308b\u5217\u8eca\u3092\u3059\u3079\u3066\u8abf\u3079\u308b\n    t = 0\n    for j in range(i,n-1):\n        if S[j]>t:\n            t = S[j]\n        \n        if (t-S[j])%F[j]==0:\n            t += C[j]\n        else:\n            t += F[j] - (t-S[j])%F[j] + C[j]\n\n        if j==n-2:\n            print(t)\nprint(0)", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "N=~-int(input())\nC=[list(map(int,input().split())) for _ in range(N)]\n\nfor i in range(N):\n p,q,r=C[i]\n A=q+p\n for j in range(i+1,N):\n  c,s,f=C[j]\n  if A<s:A=s\n  m=(A-s)%f\n  if m!=0:A+=f-m\n  A+=c\n print(A)\nprint(0)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Fri Oct  2 01:57:07 2020\n\n@author: liang\n\"\"\"\nimport math\n\nN = int(input())\nStations = list()\nfor i in range(N-1):\n    C, S, F = map(int,input().split())\n    Stations.append((C,S,F))\n\ndef solve(n,time):\n    if n == N-1:\n        return time\n    C, S, F = Stations[n]\n    tmp = max(S+C, math.ceil(time/F)*F+C)\n    return solve(n+1,tmp)\n\nfor i in range(N):\n    print(solve(i,0))", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "n=int(input());A=[0]*n\nfor i in range(1,n):\n  c,s,f=map(int,input().split())\n  for j in range(i):A[j]=max(-A[j]//f*-f,s)+c\nprint(*A,sep=\"\\n\")", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "#!/usr/bin/env python\n\nn = int(input())\nc = [0 for _ in range(n-1)]\ns = [0 for _ in range(n-1)]\nf = [0 for _ in range(n-1)]\nfor i in range(n-1):\n    c[i], s[i], f[i] = list(map(int, input().split()))\n\nt = [[-1 for _ in range(n)] for _ in range(n-1)]\n\nfor i in range(n-1):\n    t[i][i] = s[i]\n\nfor i in range(n-1):\n    for j in range(i, n): \n        if i != j:\n            t[i][j] = t[i][j-1]+c[j-1]\n            if j == n-1:\n                break\n            if t[i][j]-t[j][j] <= 0:\n                t[i][j] = t[j][j]\n            else:\n                if (t[i][j]-t[j][j])%f[j] != 0:\n                    t[i][j] = t[j][j] + ((t[i][j]-t[j][j])//f[j]+1) * f[j]\n\n\n#print('t =', t)\n\n# output \nfor i in range(n-1):\n    print((t[i][n-1]))\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "n = int(input())\ncsf = [list(map(int, input().split())) for _ in range(n-1)]\nans = []\nfor i in range(n-1):\n    time = 0\n    for p in range(i, n - 1):\n        c, s, f = csf[p]\n        if s >= time:\n            time = s+c\n        else:\n            d = time - s\n            time = s + f * (-(-d // f)) + c\n    ans.append(time)\n\nans.append(0)\n\nfor i in range(n):\n    print((ans[i]))\n", "passed": true, "time": 0.24, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\n\nnow = 0\nans = [0] * (n)\nCSF = [list(map(int, input().split())) for _ in range(n - 1)]\nfor i in range(n - 1):\n    now = 0\n    for j in range(n - i - 1):\n        c, s, f = CSF[i + j]\n        if now <= s:\n            now = s\n        else:\n            now = f * ((now + f - 1) // f)\n        now += c\n    ans[i] = now\n\nprint((\"\\n\".join(map(str, ans))))\n", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}, {"code": "n = int(input())\nc = []\ns = []\nf = []\nfor _ in range(n-1):\n    _c, _s, _f = list(map(int, input().split()))\n    c.append(_c)\n    s.append(_s)\n    f.append(_f)\n\nans = 0\n\nfor i in range(n):\n    ans = 0\n    for j in range(i, n-1):\n        if ans < s[j]:\n            ans = s[j] + c[j]\n        elif ans % f[j] == 0:\n            ans += c[j]\n        else:\n            ans += f[j] - ans%f[j] + c[j]\n\n    print(ans)\n", "passed": true, "time": 0.24, "memory": 14076.0, "status": "done"}, {"code": "N = int(input())\nCSF = [[0] * 3 for i in range(N-1)]\n\nfor i in range(N-1):\n    c, s, f = list(map(int, input().split()))\n    CSF[i][0] = c\n    CSF[i][1] = s\n    CSF[i][2] = f\n\nfor i in range(N-1):\n    now = CSF[i][1]+CSF[i][0]\n    for j in range(i+1, N-1):\n        # 1\u672c\u76ee\u306e\u524d\u306a\u30891\u672c\u76ee\u307e\u3067\u5f85\u3064\n        if now <= CSF[j][1]:\n            now += CSF[j][0]+(CSF[j][1]-now)\n\n        # 1\u672c\u76ee\u4ee5\u964d\u306a\u3089\u5f85\u3061\u6642\u9593\u3068\u79fb\u52d5\u6642\u9593\u3092\u52a0\u7b97\u3059\u308b\n        else:\n            while (now - CSF[j][1]) % CSF[j][2] != 0:\n                now += 1\n            now += CSF[j][0]\n    print(now)\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n = int(input())\ninp = []\nfor i in range(n-1):\n    inp.append(list(map(int, input().split())))\n\nfor i in range(n-1):\n    total = 0\n    for j in range(i, n-1):\n        if total < inp[j][1]:\n            total = inp[j][1]\n        while total % inp[j][2] != 0:\n            total += 1\n        total += inp[j][0]\n    print(total)\nprint((0))\n            \n\n\n\n", "passed": true, "time": 0.21, "memory": 14064.0, "status": "done"}, {"code": "n=int(input())\nyo=[]\nfor _ in range(n-1):\n  a=list(map(int,input().split()))\n  yo.append(a)\n  \ndef ans(x):\n  if x==n-1:\n    return 0\n  else:\n    t=0\n    for i in range(x,n-1):\n      if t<=yo[i][1]:\n        t=yo[i][1]+yo[i][0]\n      else:\n        s=t-yo[i][1]\n        if s%yo[i][2]==0:\n          t=t+yo[i][0]\n        else:\n          mo=s%yo[i][2]\n          t=t+yo[i][2]-mo+yo[i][0]\n    return t\n    \nfor j in range(n):\n  print((ans(j)))\n        \n", "passed": true, "time": 0.5, "memory": 14172.0, "status": "done"}, {"code": "N = int(input())\ncsf = [list(map(int,input().split())) for i in range(N-1)]\nfor i in range(N-1):\n    ans = csf[i][1]+csf[i][0]\n    for j in range(i+1,N-1):\n        if ans <= csf[j][1]:\n            ans = csf[j][1]\n        else:\n            f = ans%csf[j][2]\n            if f != 0:\n                ans += csf[j][2]-f\n        ans += csf[j][0]\n    print(ans)\nprint(0)", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "n=int(input())\nl=[]\nfor _ in range(n-1):\n  c,s,f=map(int,input().split())\n  for i,t in enumerate(l):\n    if t>s: t=-(-t//f)*f\n    else: t=s\n    l[i]=t+c\n  l+=[s+c]\nfor i in l+[0]:\n  print(i)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "import math\n\nn = int(input())\ncL = []\nsL = []\nfL = []\nfor i in range(n - 1):\n    c, s, f = map(int, input().split(\" \"))\n    cL.append(c)\n    sL.append(s)\n    fL.append(f)\n\nans = 0\nfor i in range(n - 1):\n    sm = 0\n    for j in range(i, n - 1):\n        c = cL[j]\n        s = sL[j]\n        f = fL[j]\n        if sm < s:\n            sm = s + c\n            continue\n        df = f - (sm - s) % f\n        if df == f:\n            df = 0\n        sm += c + df\n    print(sm)\nprint(0)", "passed": true, "time": 0.22, "memory": 14340.0, "status": "done"}, {"code": "N=int(input())\ncsf=[list(map(int,input().split()))for _ in range(N-1)]\ni=0\nwhile i<N:\n    ans=0\n    j=i\n    while j<N-1:\n        c,s,f=list(csf[j])\n        ans=max(ans,s)\n        if ans%f:\n            ans+=f-ans%f\n        ans+=c\n        j+=1\n    print(ans)\n    i+=1", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "N = int(input())\nlis = [[0, 0, 1]]\nfor i in range(N - 1):\n    C, S, F = list(map(int, input().split()))\n    lis.append([C, S, F])\n\n# i \u99c5\u30b9\u30bf\u30fc\u30c8 \u306e\u96fb\u8eca\nfor i in range(N):\n    C, S_ij, F = 0, 0, 1\n    for j in range(i + 1, N):  # j \u99c5\u306b\u7740\u304f\n        C, S, F = lis[j]\n        S = max(S, S_ij)  # max\uff08j \u99c5\u306e\u30b9\u30bf\u30fc\u30c8\u6642\u9593\u3001 ij \u9593\u306e\u6642\u9593\uff09\n        S_ij = C + ((S - 1) // F + 1) * F\n    print(S_ij)\n", "passed": true, "time": 0.15, "memory": 14172.0, "status": "done"}, {"code": "def solve():\n    n = int(input())\n    csf = [list(map(int,input().split())) for _ in range(n-1)]\n    \n    for i in range(n):\n        time = 0\n        while True:\n            if i == n-1:\n                print(time)\n                break\n            if time < csf[i][1]:\n                time = csf[i][1] + csf[i][0]\n            else:\n                if time%csf[i][2] == 0:\n                    time += csf[i][0]\n                else:\n                    time += csf[i][0] + csf[i][2] -  time%csf[i][2]\n            i += 1\n\ndef __starting_point():\n    solve()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "N = int(input())\nl = []\nfor i in range(N-1):\n  c, s, f = map(int, input().split())\n  l.append([c, s, f])\n  \nfor i in range(N-1):\n  time = l[i][1] + l[i][0]\n  for j in range(i+1, N-1):\n    if time-l[j][1] >= 0:\n      wait = time % l[j][2]\n      if wait == 0:\n        time += l[j][0]\n      else:\n        time += l[j][2] - wait + l[j][0]\n    else:\n      time = l[j][1] + l[j][0]\n  print(time)\nprint(0)", "passed": true, "time": 0.18, "memory": 14308.0, "status": "done"}, {"code": "# import itertools\nimport math\n# from functools import reduce\n# import sys\n# sys.setrecursionlimit(500*500)\n# import numpy as np\n# from collections import deque\n# import heapq\n\n# \u5165\u529b\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# H, N = map(int, input().split())\n# A = list(map(int, input().split()))\n# A = list(map(lambda x: int(x)*(-1), input().split()))\n# B = list(map(int, input().split()))\ncsf = [list(map(int,input().split())) for _ in range(N-1)]\n# S = input()\n\n# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n# edges = [list(map(int,input().split())) for _ in range(N - 1)]\n# tree = [[] for _ in range(N + 1)]\n\n# for edge in edges:\n#     tree[edge[0]].append(edge[1])\n#     tree[edge[1]].append(edge[0])\n\n# depth = [-1] * (N + 1)\n# depth[1] = 0\n# count = [0] * (N + 1)\n\n# for i in range(Q):\n#     p, x = map(int, input().split())\n#     count[p] += x\n\n# def dfs(tree, s):\n#     for l in tree[s]:\n#         if depth[l[0]] == -1:\n#             depth[l[0]] = depth[s] + 1\n#             dfs(tree, l[0])\n# dfs(tree, 1)\n\n# \u7d20\u56e0\u6570\u5206\u89e3\n# def factorization(n):\n#     arr = []\n#     temp = n\n#     for i in range(2, int(-(-n**0.5//1))+1):\n#         if temp%i==0:\n#             cnt=0\n#             while temp%i==0:\n#                 cnt+=1\n#                 temp //= i\n#             arr.append([i, cnt])\n#     if temp!=1:\n#         arr.append([temp, 1])\n#     if arr==[]:\n#         arr.append([n, 1])\n#     return arr\n\n# \u7d04\u6570\u5217\u6319\n# def make_divisors(n):\n#     lower_divisors , upper_divisors = [], []\n#     i = 1\n#     while i*i <= n:\n#         if n % i == 0:\n#             lower_divisors.append(i)\n#             if i != n // i:\n#                 upper_divisors.append(n//i)\n#         i += 1\n#     return lower_divisors + upper_divisors[::-1]\n\n# bfs\n# tree = [[] for _ in range(N + 1)]\n# edges = [list(map(int,input().split())) for _ in range(M)]\n\n# for edge in edges:\n#     tree[edge[0]].append(edge[1])\n#     tree[edge[1]].append(edge[0])\n\n# depth = [-1] * (N + 1)\n# depth[1] = 0\n\n# d = deque()\n# d.append(1)\n\n# ans = [0] * (N + 1)\n# while d:\n#  v = d.popleft()\n#  for i in tree[v]:\n#    if depth[i] != -1:\n#      continue\n#    depth[i] = depth[v] + 1\n#    ans[i] = v\n#    d.append(i)\n\n# # ans = depth[2:]\n# print('Yes')\n# print(*ans[2:], sep=\"\\n\")\n\n# def gcd_list(numbers):\n#     return reduce(math.gcd, numbers)\n\n# # \u9ad8\u901f\u7d20\u56e0\u6570\u5206\u89e3\u6e96\u5099\n# MAXN = 10**6+10\n# sieve = [i for i in range(MAXN+1)]\n# p = 2\n# while p*p <= MAXN:\n#     if sieve[p] == p:\n#         for q in range(2*p, MAXN+1, p):\n#             if sieve[q] == q:\n#                 sieve[q] = p\n#     p += 1\n\n\nfor i in range(N):\n    t = 0\n    for j in range(i, N - 1):\n        if csf[j][1] >= t:\n            t = csf[j][1] + csf[j][0]\n            # print(i, j, t)\n        else:\n            t = csf[j][1] + math.ceil((t - csf[j][1]) / csf[j][2]) * csf[j][2] + csf[j][0]\n            # print(i, j, t)\n    print(t)", "passed": true, "time": 0.15, "memory": 14192.0, "status": "done"}, {"code": "n=int(input())\nc,s,f=[],[],[]\nfor _ in range(n-1):\n    x,y,z=map(int,input().split())\n    c.append(x)\n    s.append(y)\n    f.append(z)\n\nfor i in range(n-1):\n    temp=s[i]+c[i]\n    for j in range(i+1,n-1):\n        if temp<=s[j]: temp=s[j]+c[j]\n        else:\n            if (temp-s[j])%f[j]==0: temp+=c[j]\n            else:\n                k=(temp-s[j])//f[j]+1\n                temp=s[j]+k*f[j]+c[j]\n    print(temp)\nprint(0)", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "N= int(input())\nli = [list(map(int,input().split())) for _ in range(N-1)]\n\nfor i in range(N-1):\n    ci,si,fi = li[i]\n    time = si+ci\n    for j in range(i+1,N-1):\n        cj,sj,fj = li[j]\n        if time%fj != 0:\n            time = ((time//fj)+1)*fj\n        #print(i,time)\n        if time < sj:\n            time = sj\n        time += cj\n    print(time)\nprint(0)", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "n = int(input())\nC = []\nS = []\nF = []\nfor _ in range(n-1):\n    c, s, f = map(int, input().split())\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\ndef f(n, s, f):\n    if n <= s:\n        return s\n    if n % f == 0:\n        return n\n    else:\n        return n // f * f + f\n\nfor i in range(n-1):\n    now = S[i] + C[i]\n    for j in range(i+1, n-1):\n        now = f(now, S[j], F[j]) + C[j]\n    print(now)\nprint(0)", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "N=int(input())\nl=[0]*N\nfor i in range(N-1):\n c,s,f=map(int,input().split())\n l[i]=c+s\n for j in range(i):\n  l[j]=max(l[j],s,-(-l[j]//f)*f)+c\n\nfor i in l:print(i)", "passed": true, "time": 0.28, "memory": 14304.0, "status": "done"}, {"code": "N=int(input())\nCSF=[list(map(int,input().split())) for _ in range(N-1)]\nfor j in range(N):\n    t=0\n    for i in range(j,N-1):\n        if t<CSF[i][1]:\n            t=CSF[i][1]\n        else:\n            x=(t-1)//CSF[i][2]+1\n            t=CSF[i][2]*x\n        t+=CSF[i][0]\n    print(t)\n", "passed": true, "time": 0.18, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\ncost = [0]*n\nstart = [0]*n\nfreaq = [0]*n\ndp = [[0]*n for _ in range(n)]\n\nfor i in range(n-1):\n    cost[i],start[i],freaq[i] = map(int,input().split())\n    dp[i][i] = start[i]\n\nfreaq[n-1] = 1\n\nt = 0\n\nfor i in range(n-1):\n    for j in range(i+1):\n        t = dp[j][i]\n        t += cost[i]\n        if t%freaq[i+1] != 0:\n            t += freaq[i+1] - t%freaq[i+1]\n        t = max(t,start[i+1])\n        dp[j][i+1] = t\n\nfor i in range(n):\n    print(dp[i][n-1])", "passed": true, "time": 0.14, "memory": 14096.0, "status": "done"}, {"code": "n = int(input())\nc = [0] * n\ns = [0] * n\nf = [0] * n\nfor i in range(n - 1):\n    c[i], s[i], f[i] = map(int, input().split())\n\nans = [0] * n\nfor i in range(n - 1):\n    for j in range(i, n - 1):\n        if ans[i] < s[j]:\n            ans[i] = s[j]\n        elif ans[i] % f[j] > 0:\n            ans[i] += f[j] - ans[i] % f[j]\n        ans[i] += c[j]\n\nfor i in range(n):\n    print(ans[i])", "passed": true, "time": 0.14, "memory": 14148.0, "status": "done"}, {"code": "n = int(input())\ncsf = [list(map(int, input().split())) for _ in range(n-1)]\n\nfor i in range(n-1):\n    t = 0\n    for c,s,f in csf[i:]:\n        if s > t:\n            # \u59cb\u767a\u3092\u5f85\u3064\n            t = s\n        else:\n            # \u6b21\u767a\u3092\u5f85\u3064\n            t += (s-t) % f\n        t += c\n    print(t)\nprint(0)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "n=int(input())\ncsf=[]\nfor i in range(n-1):\n    c,s,f=list(map(int,input().split()))\n    csf.append([c,s,f])\n\nfor i in range(n):\n    t=0\n    for j in range(i,n-1):\n        c,s,f=csf[j]\n        if t<=s:\n            t = s + c\n        else:\n            if t%f==0: w=0\n            else: w=f-t%f\n            t = t + w + c\n    print(t)\n", "passed": true, "time": 0.14, "memory": 14056.0, "status": "done"}, {"code": "def jikan(now_t,i):\n    if i==n:\n        return now_t\n    else:\n        if now_t<=s[i]:\n            now_t = s[i]\n        else:\n            tmp1 = now_t//f[i]\n            if now_t%f[i]!=0:\n                now_t = (tmp1+1)*f[i]\n        tmp = jikan(now_t+c[i],i+1)\n        return tmp\n\nn = int(input())\nc,s,f = [0],[0],[0]\nfor i in range(n-1):\n    ci,si,fi = list(map(int,input().split()))\n    c.append(ci)\n    s.append(si)\n    f.append(fi)\n#print(c,s,f)\nfor i in range(1,n+1):\n    print((jikan(0,i)))\n", "passed": true, "time": 0.14, "memory": 14168.0, "status": "done"}, {"code": "from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb\nfrom itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement\nfrom collections import deque,defaultdict,Counter\nfrom bisect import bisect_left,bisect_right\nfrom operator import itemgetter\nfrom heapq import heapify,heappop,heappush\nfrom queue import Queue,LifoQueue,PriorityQueue\nfrom copy import deepcopy\nfrom time import time\nimport string\nimport sys\nsys.setrecursionlimit(10 ** 7)\ndef input() : return sys.stdin.readline().strip()\ndef INT()   : return int(input())\ndef MAP()   : return map(int,input().split())\ndef LIST()  : return list(MAP())\n\nn = INT()\nls = []\nfor i in range(n-1):\n    c, s, f = MAP()\n    ls.append([c, s, f])\nfor i in range(n-1):\n    ans = 0\n    for j in range(i, n-1):\n        ans = max(ans, ls[j][1])\n        ans = ls[j][0] + ( ans + ls[j][2] - 1 )// ls[j][2] * ls[j][2]\n    print(ans)\nprint(0)", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "N=int(input())\nC=[list(map(int,input().split())) for _ in range(N-1)]\n\nfor i in range(N-1):\n c,s,f=C[i]\n A=s+c\n for j in range(i+1,N-1):\n    nc,ns,nf=C[j]\n    if A<ns:A=ns\n    elif (A-ns)%nf!=0:A+=nf-(A-ns)%nf\n    A+=nc\n print(A)\nprint(0)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "import math\nimport sys\n\n\nMAX_N = 500\n\n\nN = int(input())\nC = []\nS = []\nF = []\nfor _ in range(N - 1):\n    c, s, f = [int(x) for x in input().split()]\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\nif N == 1:\n    print((0))\n    return\n\nfor i in range(N - 1):\n    t = S[i] + C[i]\n    for j in range(i + 1, N - 1):\n        t = max(S[j], int(math.ceil(t / F[j])) * F[j]) + C[j]\n    print(t)\nprint((0))\n", "passed": true, "time": 0.23, "memory": 14220.0, "status": "done"}, {"code": "N=int(input())\nC=[]\nS=[]\nF=[]\nfor i in range(N-1):\n    CSF=list(map(int,input().split()))\n    C.append(CSF[0])\n    S.append(CSF[1])\n    F.append(CSF[2])\n\nans=[0]*(N)\n\nfor i in range(N-1):\n    t=0\n\n    for j in range(i,N-1):\n        m=-(-t//F[j])*F[j]\n        t=max(S[j],m)\n        t+=C[j]\n    \n    ans[i]=t\n\nprint(*ans,sep='\\n')", "passed": true, "time": 0.14, "memory": 14168.0, "status": "done"}, {"code": "import sys\nimport math\nimport itertools\nimport collections\nfrom collections import deque\nfrom collections import defaultdict\n\nsys.setrecursionlimit(1000000)\nMOD = 10 ** 9 + 7\nMOD2 = 998244353\nINF = float('inf')\ninput = lambda: sys.stdin.readline().strip()\n\nNI = lambda: int(input())\nNMI = lambda: map(int, input().split())\nNLI = lambda: list(NMI())\nSI = lambda: input()\n\ndef main():\n    N = NI()\n    CSF = [NLI() for _ in range(N-1)]\n    CSF.append([0,0,1])\n\n    \n    for n in range(N-1):\n        time = CSF[n][1]\n        \n        for m in range(n,N-1):\n            time += CSF[m][0]\n            if time < CSF[m+1][1]:\n                time = CSF[m+1][1]\n            else:\n                if time % CSF[m+1][2] != 0:\n                    time = ((time//CSF[m+1][2])+1)*CSF[m+1][2]\n        print(time)\n    print(0)\n\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "n = int(input())\ntimetable = [list(map(int, input().split())) for _ in range(n - 1)]\n\ndef nextstn(t, stn):\n    if t >= timetable[stn][1]:\n        return (((t + timetable[stn][2] - 1) // timetable[stn][2]) * timetable[stn][2]) + timetable[stn][0]\n    else:\n        return timetable[stn][1] + timetable[stn][0]\n\nfor i in range(n - 1):\n    current_stn = i\n    laps = 0\n    while current_stn < n - 1:\n        laps = nextstn(laps, current_stn)\n        current_stn += 1\n    print(laps)\nelse:\n    print(0)", "passed": true, "time": 0.15, "memory": 14180.0, "status": "done"}, {"code": "import sys\n\ninput_methods=['clipboard','file','key']\nusing_method=0\ninput_method=input_methods[using_method]\n\ntin=lambda : map(int, input().split())\nlin=lambda : list(tin())\nmod=1000000007\n\n#+++++\n\ndef cc(al):\n\tret = 0\n\tfor (c, s, f) in al:\n\t\tif ret <= s:\n\t\t\tret = s+c\n\t\telse:\n\t\t\tst = ((ret + f-1)//f)*f\n\t\t\tret = st + c\n\tprint(ret)\n\t\t\n\ndef main():\n\tn = int(input())\n\t#if n==4:\n\t#\treturn 1/0\n\t#b , c = tin()\n\t#s = input()\n\tal = [lin() for _ in range(n-1)]\n\tfor i in range(n):\n\t\tcc(al[i:])\n\t\n\t\n\t\n#+++++\nisTest=False\n\ndef pa(v):\n\tif isTest:\n\t\tprint(v)\n\t\t\ndef input_clipboard():\n\timport clipboard\n\tinput_text=clipboard.get()\n\tinput_l=input_text.splitlines()\n\tfor l in input_l:\n\t\tyield l\n\ndef __starting_point():\n\tif sys.platform =='ios':\n\t\tif input_method==input_methods[0]:\n\t\t\tic=input_clipboard()\n\t\t\tinput = lambda : ic.__next__()\n\t\telif input_method==input_methods[1]:\n\t\t\tsys.stdin=open('inputFile.txt')\n\t\telse:\n\t\t\tpass\n\t\tisTest=True\n\telse:\n\t\tpass\n\t\t#input = sys.stdin.readline\n\t\t\t\n\tret = main()\n\tif ret is not None:\n\t\tprint(ret)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "def main():\n    import sys\n    input = lambda:sys.stdin.readline().strip()\n    \n    N = int(input())\n    #C:\u6240\u8981\u6642\u9593,S:\u958b\u59cb\u5f8c,F:\u9593\u9694\n    CSF = [list(map(int,input().split())) for _ in range(N-1)]\n\n    for i in range(N):\n        t = 0\n        for c,s,f in CSF[i:]:\n            if t<=s:\n                t=s\n            else:\n                t=((t-s)//f if (t-s)%f==0 else (t-s)//f+1)*f+s\n            t+=c\n        print(t)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14172.0, "status": "done"}, {"code": "N = int(input())\nstation = [list(map(int, input().split())) for _ in range(N - 1)]\n\nlst = []\n\nfor i in range(N - 1):\n    c, s, f = station[i]\n\n    for j in range(len(lst)):\n        a = lst[j]\n\n        if a >= s:\n            if a % f == 0:\n                a += c\n            else:\n                a += (f - a % f) + c\n        else:\n            a = s + c\n\n        lst[j] = a\n\n    lst.append(s + c)\n\n\nlst.append(0)\nfor a in lst:\n    print(a)\n", "passed": true, "time": 0.68, "memory": 14288.0, "status": "done"}, {"code": "N=int(input())\nCSF=[list(map(int,input().split())) for _ in range(N-1)]\nfor j in range(N):\n    t=0\n    for i in range(j,N-1):\n        if t<CSF[i][1]:\n            t=CSF[i][1]\n        else:\n            x=(t-1)//CSF[i][2]+1\n            t=CSF[i][2]*x\n        t+=CSF[i][0]\n    print(t)", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "def resolve():\n    '''\n    code here\n    '''\n    N = int(input())\n    starts = [[int(item) for item in input().split()] for _ in range(N-1)]\n\n    for i in range(N):\n        temp_time = 0\n        if i == N-1:\n            print((0))\n        else:\n            for j in range(i,N-1):\n                c, s, f = starts[j]\n                if temp_time <= s:\n                    temp_time = s\n\n                if temp_time % f == 0:\n                    pass\n                else:\n                    temp_time = (temp_time // f + 1) * f\n            \n                temp_time += c\n            print(temp_time)\n\n\ndef __starting_point():\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14120.0, "status": "done"}, {"code": "N = int(input())\nT = 0\nt = 0\nans = []\nfor i in range(N-1):\n    C, S, F = list(map(int, input().split()))\n    for j in range(len(ans)):\n        if ans[j] <= S:\n            ans[j] = S+C\n        elif ans[j]%F != 0:\n            ans[j] = ans[j]+F-(ans[j] % F)+C\n        else:\n            ans[j] += C\n    ans.append(S+C)\nfor a in ans:\n    print(a)\nprint((0))\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "N = int(input())\nC, S, F = [], [], []\n\nfor _ in range(N-1):\n    c, s, f = map(int, input().split())\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\nfor station in range(N):\n    now = station\n    time = 0\n\n    while now < N-1:\n        if time < S[now]:\n            time = S[now] + C[now]\n        else:\n            if time % F[now] == 0:\n                time += C[now]\n            else:\n                wait_time = F[now] - (time % F[now])\n                time += wait_time + C[now]\n\n        now += 1\n\n    print(time)", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "n=int(input())\ncsf = [list(map(int,input().split())) for i in range(n-1)]\nans1=[]\nfor j in range(n-1):\n  requ_time=csf[j][1]+csf[j][0]\n  for i in range(j,n-1):\n    if i!=j:\n      if requ_time <= csf[i][1]:\n        requ_time+=(csf[i][0]+(csf[i][1]-requ_time))\n  #elif requ_time > csf[i][1] and csf[i][0]+csf[1] > requ_time:\n      else:\n        requ_time+=(csf[i][0]+(csf[i][2]-(requ_time-csf[i][1])%csf[i][2])%csf[i][2])\n  ans1.append(requ_time)\nfor i in ans1:\n  print(i)\nprint((0))\n", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "n=int(input())\nl=[0]*n\nfor i in range(1,n):\n  c,s,f=map(int,input().split())\n  for j in range(i):\n    l[j]=max(-l[j]//f*-f,s)+c\nfor i in l: print(i)", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "import sys\n\nN = int(sys.stdin.readline())\n\nstations = []\nfor _ in range(N-1):\n    c, s, f = map(int, sys.stdin.readline().split())\n    stations.append((c, s, f))\n\nfor i in range(N-1):\n    t = 0\n    for j in range(i, N-1):\n        c, s, f = stations[j]\n        if t <= s:\n            t = s + c\n        else:\n            tmp = t - s\n            t = s + f * ((tmp - 1) // f + 1) + c\n\n    print(t)\nprint(0)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "import math\ndef main():\n    n=int(input())\n    csf=[list(map(int,input().split())) for _ in range(n-1)]\n    for i in range(n):\n        if i == n-1:\n            print(0)\n        else:\n            t=0\n            for c,s,f in csf[i:]:\n                t = max(s,t)\n                t = math.ceil(t/f)*f+c\n                #print(\"start:\", i, t)\n            print(t)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14072.0, "status": "done"}, {"code": "N = int(input())\ncsf = [list(map(int, input().split())) for _ in range(N-1)]\nans = [None]*N\nans[-1] = 0\nfor i in range(N-1):\n    now = 0\n    for j in range(i,N-1):\n        if now <= csf[j][1]:\n            now = csf[j][1]\n        else:\n            t  = (now - csf[j][1] + csf[j][2]-1)//csf[j][2]\n            now = csf[j][1] + t*csf[j][2]\n        now += csf[j][0]\n    ans[i] = now\n[print(a) for a in ans]", "passed": true, "time": 0.15, "memory": 14264.0, "status": "done"}, {"code": "N = int(input())\ncsf = [list(map(int, input().split())) for i in range(N - 1)]\n\nfor i in range(N):\n    ans = 0\n    for c, s, f in csf[i::]:\n        if ans <= s:\n            ans = s\n        else:\n            if ans % f == 0:\n                pass\n            else:\n                ans = (ans // f + 1) * f\n        ans += c\n    print(ans)\n", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}, {"code": "def est_time(sta,N,csf_list):\n  SUM = 0\n  for i in range(sta,N):\n    if i == sta:\n      SUM += csf_list[i-1][0] + csf_list[i-1][1]\n    else:\n      if SUM >= csf_list[i-1][1]:\n        SUM = ((SUM+csf_list[i-1][2]-1) // csf_list[i-1][2])*csf_list[i-1][2]\n        SUM += csf_list[i-1][0]\n      else:\n        SUM = csf_list[i-1][1]\n        SUM += csf_list[i-1][0]\n  return SUM\n\nN=int(input())\ncsf_list=[tuple(map(int,input().split())) for _ in range(N-1)]\n\nfor i in range(N):\n  print(est_time(i+1,N,csf_list))", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "N = int(input())\nCls = [0]\nSls = [0]\nFls = [0]\nlsans = []\nfor i in range(1,N):\n    c,s,f = map(int,input().split())\n    Cls.append(c)\n    Sls.append(s)\n    Fls.append(f)\nfor i in range(1,N):\n    t = 0\n    for j in range(i,N):\n        if t < Sls[j]:\n            t = Sls[j] + Cls[j]\n        elif t%Fls[j] == 0:\n            t += Cls[j]\n        else:\n            t += Fls[j]-(t%Fls[j])+Cls[j]\n    lsans.append(t)\nlsans.append(0)\nfor i in lsans:\n    print(i)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n    N, *CSF = map(int, read().split())\n    train = [0] * (N - 1)\n    for i, t in enumerate(zip(*[iter(CSF)] * 3)):\n        train[i] = t\n\n    ans = [0] * N\n    for i in range(N - 1):\n        t = 0\n        for c, s, f in train[i:]:\n            if t < s:\n                t = s + c\n            else:\n                t += f - ((t - 1) % f + 1) + c\n        ans[i] = t\n\n    ans[N - 1] = 0\n    print(*ans, sep='\\n')\n    return\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "import sys\n\nN = int(sys.stdin.readline())\n\nstations = []\nfor _ in range(N-1):\n    c, s, f = map(int, sys.stdin.readline().split())\n    stations.append((c, s, f))\n\nfor i in range(N-1):\n    t = 0\n    for j in range(i, N-1):\n        c, s, f = stations[j]\n        if t <= s:\n            t = s + c\n        else:\n            tmp = t - s\n            t = s + f * ((tmp - 1) // f + 1) + c\n\n    print(t)\nprint(0)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\nimport math\nsys.setrecursionlimit(10**6)\nn = int(input())\n\ncsf = [list(map(int, input().split())) for i in range(n-1)]\n\nfor i in range(n-1):\n    csf_tmp = csf[i:]\n\n    c, s, f = csf_tmp[0]\n\n    t = c+s\n    for j in range(1, len(csf_tmp)):\n        c, s, f = csf_tmp[j]\n\n        if t <= s:\n            t = s\n        else:\n            mod = (t-s) % f\n            if mod != 0:\n                t += f-mod\n        # print(t)\n        t += c\n        # print(t)\n    print(t)\n    # print()\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "n = int(input())\nans = [0] * n\n\nfor i in range(1, n):\n    c, s, f = list(map(int, input().split()))\n\n    for j in range(i):\n        ans[j] = max(ans[j], s)\n        ans[j] = ((ans[j]+f-1)//f) * f\n        ans[j] += c\n\nfor a in ans:\n    print(a)", "passed": true, "time": 0.14, "memory": 14080.0, "status": "done"}, {"code": "n = int(input())\nroute, ans = [], []\nfor i in range(n-1):\n    a = list(map(int, input().split()))\n    route.append(a)\n\nfor i in range(n-1):\n    c = route[i][0]+route[i][1]\n    for j in range(i+1, n-1):\n        if c < route[j][1]:\n            c = route[j][0]+route[j][1]\n        elif (c-route[j][1])%route[j][2] == 0:\n            c += route[j][0]\n        else:\n            c += route[j][0]+route[j][2]-(c-route[j][1])%route[j][2]\n    ans.append(c)\nans.append(0)\nfor i in ans:\n    print(i)\n", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "N = int(input())\nC = [0]*(N-1)\nS = [0]*(N-1)\nF = [0]*(N-1)\nfor TN in range(0,N-1):\n    C[TN],S[TN],F[TN] = (int(T) for T in input().split())\nfor TN in range(0,N):\n    Time = 0\n    for TS in range(TN,N-1):\n        if Time>=S[TS]:\n            Time += C[TS]+(F[TS]-(Time%F[TS]))%F[TS]\n        else:\n            Time += C[TS]+(S[TS]-Time)\n    print(Time)", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\nT = [0]*n\nc,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)\n \nfor i in range(n-1):\n\tc[i],s[i],f[i] = map(int,input().split())\n\nfor\ti in range(n-1):\n\tT[i] = s[i] + c[i]\n\tfor j in range(i+1,n-1):\n\t\tif T[i] > s[j]:\n\t\t\tT[i] += (-T[i])%f[j] + c[j]\n\t\telse:\n\t\t\tT[i] = s[j] + c[j]\n\tprint(T[i])\nprint(0)", "passed": true, "time": 0.14, "memory": 14104.0, "status": "done"}, {"code": "n=int(input())\ncsf=[tuple(map(int,input().split())) for _ in range(n-1)]\n\narrtime=lambda i,cs: max(csf[i][2]*(cs//csf[i][2]+(cs%csf[i][2]>0)),csf[i][1])+csf[i][0]\nfor i in range(n-1):\n  arrivN=csf[i][1]\n  for j in range(i,n-1):\n    arrivN=arrtime(j,arrivN)\n  print(arrivN)\nprint(0)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "n = int(input())\ncl = []\nsl = []\nfl = []\n\nfor _ in range(n-1):\n    c,s,f = list(map(int,input().split()))\n    cl += [c]\n    sl += [s]\n    fl += [f]\n\n        \n\nfor i in range(n):\n    time = 0\n    while True:\n        if i==n-1:\n            print(time)\n            break\n        if sl[i]<=time and time%fl[i]==0:\n            time += cl[i]\n        elif sl[i]>time:\n            time = sl[i] +cl[i]\n        else: #sl[i]<=time and time%fl[i]!=0\n            time += fl[i] - time%fl[i] +cl[i]\n        i += 1\n    \n\n", "passed": true, "time": 0.55, "memory": 14308.0, "status": "done"}, {"code": "n=int(input())\nnum=[]\nfor i in range(n-1):\n    num.append(list(map(int,input().split())))\nfor i in range(n-1):\n    ans=0\n    for j in range(i,n-1):\n        if ans<=num[j][1]:\n            ans=num[j][1]\n        else:\n            ans=num[j][1]+((-((ans-num[j][1])//-num[j][2]))*num[j][2])\n        ans+=num[j][0]\n    print(ans)\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "N = int(input())\nC = [0] * (N-1)\nS = [0] * (N-1)\nF = [0] * (N-1)\nfor i in range(N-1):\n    C[i], S[i], F[i] = map(int,input().split())\n\nfor i in range(N):\n    t = 0\n    for j in range(i,N - 1):\n        if t < S[j]:\n            t = S[j]\n        elif t % F[j] == 0:\n            pass\n        else:\n            t = t + F[j] - (t % F[j])\n        t += C[j]\n    print(t)", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "#!/usr/bin/env python\n# coding: utf-8\n\n# In[18]:\n\n\nN = int(input())\ncsf = []\nfor _ in range(N-1):\n    csf.append(list(map(int, input().split())))\n\n\n# In[19]:\n\n\nfor i in range(N):\n    if i < N-1:\n        t = csf[i][1]\n        for i in range(i,N-1):\n            c,s,f = csf[i]\n            if t >= s:\n                if t%f == 0:\n                    t += c\n                else:\n                    t = (-(-t//f))*f+c\n            else:\n                t = s+c\n        print(t)\n    else:\n        print((0))\n\n\n# In[ ]:\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "import math\nN = int(input())\n\nC = []\nS = []\nF = []\nfor _ in range(N - 1):\n    c, s, f = list(map(int, input().split()))\n    C.append(c)\n    S.append(s)\n    F.append(f)\n\n\nfor i in range(N - 1):\n    count = 0\n    count += S[i]\n    count += C[i]\n    for j in range(i + 1, N - 1):\n        if count < S[j]:\n            count = S[j]\n        else:\n            count = math.ceil((count - S[j]) / F[j]) * F[j] + S[j]\n        count += C[j]\n    print(count)\nprint((0))\n", "passed": true, "time": 0.24, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\nls = [list(map(int,input().split())) for _ in range(n-1)]\ndef culc(nt,p):\n    if nt == 0:\n        if p != n-1:\n            nt = ls[p][1] + ls[p][0]\n            culc(nt,p+1)\n        else:\n            print((0))\n    else:\n        if p != n-1:\n            if nt >= ls[p][1]:\n                m = (nt - ls[p][1])//ls[p][2]\n                if (nt - ls[p][1])%ls[p][2] != 0:\n                    m += 1\n                nt = ls[p][1] + ls[p][2]*m + ls[p][0]\n                culc(nt,p+1)\n            else:\n                nt = ls[p][1] + ls[p][0]\n                culc(nt,p+1)\n        else:\n            print(nt)\nfor i in range(n):\n    culc(0,i)\n\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "import math\n\nN = int(input())\nCSF = [list(map(int, input().split())) for _ in range(N - 1)]\n\nfor i in range(N):\n    t = 0\n\n    for c, s, f in CSF[i:]:\n        # \u5f85\u3061\u6642\u9593\n        if t < s:\n            t = s\n        else:\n            t = math.ceil((t - s) / f) * f + s\n\n        # i -> i+1\u306b\u79fb\u52d5\n        t += c\n\n    print(t)\n", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}, {"code": "import sys\nmod=10**9+7 ; inf=float(\"inf\")\nfrom math import sqrt, ceil\nfrom collections import deque, Counter, defaultdict #\u3059\u3079\u3066\u306ekey\u304c\u7528\u610f\u3055\u308c\u3066\u308b defaultdict(int)\u3067\u521d\u671f\u5316\ninput=lambda: sys.stdin.readline().strip()\nsys.setrecursionlimit(11451419)\nfrom decimal import ROUND_HALF_UP,Decimal  #\u5909\u63db\u5f8c\u306e\u672b\u5c3e\u6841\u30920\u30840.01\u3067\u6307\u5b9a\n  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))\nfrom functools import lru_cache\nfrom bisect import bisect_left as bileft, bisect_right as biright\n#\u30e1\u30e2\u5316\u518d\u5e30def\u306e\u5192\u982d\u306b\u6bce\u56de @lru_cache(maxsize=10**10)\n#\u5f15\u6570\u306blist\u306f\u3060\u3081\n#######\u3053\u3053\u307e\u3067\u30c6\u30f3\u30d7\u30ec#######\n#\u30bd\u30fc\u30c8\u3001\"a\"+\"b\"\u3001\u518d\u5e30\u306a\u3089Python3\u306e\u65b9\u304c\u3044\u3044\n#######\u3053\u3053\u304b\u3089\u5929\u3077\u3089########\n\nn=int(input())\nA=[list(map(int,input().split())) for i in range(n-1)]\nfor i in range(n):\n    if i==n-1:print((0));return\n    now=0\n    for l in A[i:]:\n        c,s,f =l \n        now=max(now,s)\n        for plus in range(0,101):\n            if (now+plus)% f==0:\n                now+=plus\n                break\n        now+=c\n    print(now)\n\n", "passed": true, "time": 0.24, "memory": 14096.0, "status": "done"}, {"code": "n = int(input())\ncsf = [tuple(map(int, input().split())) for _ in range(n - 1)]\n\nfor i in range(n - 1):\n    c, s, f = csf[i]\n    a = s + c\n    now = i\n    for j in range(i + 1, n - 1):\n        nc, ns, nf = csf[j]\n        # next = ns + nf * x\n        if a <= ns:\n            a = ns\n        else:\n            x = (a - ns + nf - 1) // nf\n            a = ns + nf * x\n        a += nc\n\n    print(a)\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14080.0, "status": "done"}, {"code": "n=int(input())\nC=[]\nS=[]\nF=[]\nfor i in range(n-1):\n\tc,s,f=list(map(int, input().split()))\n\tC.append(c)\n\tS.append(s)\n\tF.append(f)\n\ndef d(x,t): #\u99c5x\u6642\u9593\uff54\u3067\u79fb\u52d5\u3059\u308b\u306e\u306b\u304b\u304b\u308b\u6642\u9593\n\tif S[x]>=t:\n\t\treturn C[x]+S[x]-t\n\telse:\n\t\tif (t-S[x])%F[x]==0:\n\t\t\treturn C[x]\n\t\telse:\n\t\t\treturn C[x]+F[x]-(t-S[x])%F[x]\n\nfor i in range(n-1):\n\tx=i\n\tans=0\n\tfor j in range(x,n-1):\n\t\tans+=d(j,ans)\n\t\tx=+1\n\tprint(ans)\nprint((0))\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}]