Problem:


Score : 300 points

Problem Statement

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 1

3
6 5 1
1 10 1

Sample Output 1

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.

Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
info = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    info.append([c, s, f])
# print(info)

def func(i, low):
    if i == low:
        return info[i][1] + info[i][0]

    return func2(func(i-1, low), info[i][2]) + info[i][0]

def func2(n, f):
    if n <= f:
        return f
    if n % f == 0:
        return n
    else:
        return n//f * f + f

# print(func(n-2, 0))
for i in range(n):
    if i == n-1:
        print(0)
    print(func(n-2, i))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
info = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    info.append([c, s, f])
# print(info)

def func(i, low):
    # print(i, low)
    if i == low:
        # print(info[i][1] + info[i][0])
        return info[i][1] + info[i][0]
    # print(func2(func(i-1, low), info[i][1]))
    return func2(func(i-1, low), info[i][2]) + info[i][0]

def func2(n, f):
    if n <= f:
        return 
    if n % f == 0:
        return n
    else:
        return n//f * f + f

# print(func(n-2, 0))
for i in range(n):
    if i == n-1:
        print(0)
    print(func(n-2, i))

Submission status: Runtime Error

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

SS = [[0]*10**7 for _ in range(N)]
for i, csf in enu(CSF):
    c, s, f = csf
    for j in range(s, 10**6, f):
        SS[i][j] = 1
# print(SS[0][:20])
# print(SS[1][:20])

for i in range(N-1):
    st = i
    sec = 0
    while st < N-1:
        # print('st', st, 'sec', sec)
        # print('st', st)
        if SS[st][sec] == 1:
            sec += CSF[st][0]
            st += 1
        else:
            sec += 1
    print(sec)
print(0)

Submission status: Runtime Error

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

SS = [[0]*10**6 for _ in range(N)]
for i, csf in enu(CSF):
    c, s, f = csf
    for j in range(s, 10**6, f):
        SS[i][j] = 1
# print(SS[0][:20])
# print(SS[1][:20])

for i in range(N-1):
    st = i
    sec = 0
    while st < N-1:
        # print('st', st, 'sec', sec)
        # print('st', st)
        if SS[st][sec] == 1:
            sec += CSF[st][0]
            st += 1
        else:
            sec += 1
    print(sec)
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())

csf = []

for i in range(n - 1):
    c, s, f = map(int, input().split())
    csf.append([c, s, f])

ans = []
for i in range(n - 1):
    tmp = csf[i][0] + csf[i][1]
    for j in range(i + 1, n - 1):
        if tmp < csf[j][1]:
            tmp = csf[j][0] + csf[j][1]
        elif (tmp - csf[j][1]) % csf[j][2] == 0:
            tmp += csf[j][0]
        else:
            tmp = ((tmp // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
n = int(input())

csf = []

for i in range(n - 1):
    c, s, f = map(int, input().split())
    csf.append([c, s, f])

ans = []
for i in range(n - 1):
    tmp = csf[i][0] + csf[i][1]
    for j in range(i + 1, n - 1):
        if tmp < csf[j][1]:
            tmp = csf[j][0] + csf[j][1]
        elif (tmp - csf[j][1]) % csf[j][2] == 0:
            tmp += csf[j][0]
        else:
            tmp += ((tmp // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
(n,),*a=[[*map(int,i.split())]for i in open(0)]
ans=[]
for i in range(n-1):
    now=a[i][0]+a[i][1]
    for j in range(i+1,n-1):
        c,s,f=a[j]
        if s==now:
            d=0
        elif s>now:
            d=s-now
        else:
            d=now%f
        now+=c+d
    ans+=[now]  
ans+=[0]    
print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
(n,),*d=[list(map(int,c.split()))for c in open(0)]
for i in range(n-1):t=0;exec("for j in range(i,n-1):c,s,f=d[j];t=[t+(f-t%f)%f,s][t<s]+c")print(t)
print(0)

Submission status: Runtime Error

Solution code:
n=int(input()) #　a1
csf= [list(map(int, input().split())) for i in range(n-1)] #a1 a2 a3 // b1 b2 b3

print(n)
for i in n:
  t=0
  for j in n-1:
    if t<csf[j][1]:
      t=csf[j][1]
    else:
      t=t+csf[j][1]-(t%csf[j][2])
    t+=csf[j][2]
  print(t)

Submission status: Runtime Error

Solution code:
n, *CSF = map(int, open(0).read().split())
A = []
for i in range(0, 3*(n-1), 3):
    t = 0
    for c, s, f in zip(CSF[i::3], CSF[i+1::3], CSF[i+2::3]):
        if t <= s:
            t = s + c
        else:
            t = ceil((t-s) / f) * f + s + c
    A.append(t)
A.append(0)
print(*A, sep='\n')

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
l_li=[]
r_li=[]

for i in range(Q):
  l,r=map(int,input().split())
  l_li.append(l)
  r_li.append(r)
#lからrの区間でacが入っている個数を求める
#「'C' が右隣にあるような 'A' の個数」

#count[l]:最初からlまでの文字で含まれるacの累積和
#lからrまでの区間のacの数はcount[r]-count[l]
count=[0]*N

for i in range(N-1):#DPっぽく解いていく
  if S[i]=="A" and S[i+1]=="C":
    count[i+1]=count[i]+1
  else:
    count[i+1] = count[i]
for i in range(Q):
  print(count[r_li[i]-1]-count[l_li[i]-1])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split()))]
l1=[0]*n
for i in range(n-1):
    l1[i]+=l[i][0]+l[i][1]
    for j in range(1,n-i-1):
        if l1[i]<l[i+j][1]:
            l1[i]-=l1[i]
            l1[i]+=l[i+j][1]
            
        if l1[i]>=l[i+j][1] and (l1[i]-l[i+j][1])%l[i+j][2]!=0:
            l1[i]+=((l[i+j][1]%l[i+j][2])+(l[i+j][2]*l1[i]))%l1[i]
            
        if l1[i]>=l[i+j][1] and (l1[i]-l[i+j][1])%l[i+j][2]==0:
            l1[i]+=l[i+j][0]
    print(l1[i])
print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
T = [0]*N
 
for i in range(N-1):
  C[i], S[i], F[i] = map(int, input().split())

for j in range(N-1):
  T[j] = C[j] + S[j]
  for i in range(j, N-1):
    if T[j] >= S[i+1] or S[i+1] == 0:
      T[j] = T[j] + C[i+1]
    elif T[j] < S[i+1]:
      T[j] = S[i+1]

T[N-1] = 0
for i in range(N):
  print(T[i])

Submission status: Runtime Error

Solution code:
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
T = [0]*N

for i in range(N-1):
  C[i], S[i], F[i] = map(int, input().split())

for j in range(N-1):
	T[j] = C[j] + S[j]
	for i in range(N-2):
  		if T[j] > S[i+1]:
    		T[j] = T[j] + C[i+1]
  		else:
    		T[j] = S[i+1]

T[N-1] = 0
for i in range(N):
  print(T[i])

Submission status: Runtime Error

Solution code:
N = int(input())
C = []
S = []
F = []
T = [0]*N

for i in range(N-1):
  C[i], S[i], F[i] = map(int, input().split())

for j in len(T):
	T[j] = C[j] + S[j]
	for i in range(N-1):
  		if T[j] > S[i+1]:
    		T[j] = T[j] + C[i+1]
  		else:
    		T[j] = S[i+1]

T[N-1] = 0
for i in len(T):
  print(T[i])

Submission status: Runtime Error

Solution code:
def f():
  n=int(input())
  l=(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

long next(long time, long f) {
  if (time % f == 0) return time;
  else return time + f - time % f;
}
int main() {
  int n;cin>>n;
  int c[n-1],f[n-1];
  long s[n-1];
  rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
  
  long time;
  rep(i,n-1) {
    time=s[i];
    rep(j,n-1) {
      if (j<i) continue;
      time = max(s[j], next(time,f[j])) + c[j];
      
    }
    cout << time << endl;
  }
  cout << 0;
}

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]
L=[0]
c=0
for i in range(n-1):
	if s[i]=='A' and s[i+1]=='C':
		c += 1
	L.append(c)
for l,r in lr:
	print(L[r-1]-L[l-1])

Submission status: Runtime Error

Solution code:
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n-1):
  ans = s[i]+c[i]
  for j in range(i+1, n-1):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
print(0)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n-1):
  ans = s[i]+c[i]
  for j in range(i+1, n):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
print(0)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
c = []
s = []
f = []
for i in range(n):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n):
  ans = s[i]+c[i]
  for j in range(i+1, n):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]

ans = -(10 ** 7)
stk = []

stk.append([0] * N)

for i in range(10):
    len_stk = len(stk)
    for j in range(len_stk):
        total = 0
        arr = []
        for k in range(N):
            open_cnt = stk[j][k] + f[k][i]
            arr.append(open_cnt)
            total += p[k][open_cnt]
        ans = max(ans, total)
        stk.append(arr)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
c=[0]*n;s=[0]*n;f=[0]*n
for i in range(n):
  c[i],s[i],f[i]=map(int,input().split())
  
for i in range(n):
  ans=0
  for j in range(i,n):
    ans+=c[i]+(s[i]+f[i]-ans)%f[i]
  print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys


read = sys.stdin.buffer.read


def main():
    N = int(input())
    m = map(int, read().split())
    CSF = list(zip(m, m, m))
    tt = []

    for j in range(N-1):
        t = CSF[j][1] + CSF[j][0]
        for i in range(j+1, N-1):
            if t >= CSF[i][1]:
                n = (t - CSF[i][1]) / CSF[i][2]
                t = CSF[i][1] + CSF[i][2] * math.ceil(n)
                t += CSF[i][0]
            else:
                t = CSF[i][1] + CSF[i][0]

        tt.append(t)

    tt.append(0)
    for t in tt:
        print(t)


main()

Submission status: Runtime Error

Solution code:
あ

Submission status: Runtime Error

Solution code:
 import sys
input = sys.stdin.readline
N = int(input().strip())
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
ans = [0] * (N)
for n in range(N-1):
    C, S, F = [int(x) for x in input().strip().split()]
    ans[n] = S + C
    for i in range(n):
        if ans[i] <= S:
            ans[i] = S + C
        elif ans[i] % F == 0:
            ans[i] += C
        else:
            ans[i] = (ans[i] // F + 1) * F + C

for a in ans:
    print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
CSF=[list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
  ans=0
  for c,s,f in CSF[i:]:
    if ans<s:
      ans=s
    else:
      ans+=f-t%f
    ans+=c
  print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-2):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][2]
      ind+=1
    else:
      time+=lst[ind+1][2]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
time=0
ind=0
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-1):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][2]
      ind+=1
    else:
      time+=lst[ind+1][2]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-1):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][2]
      ind+=1
    else:
      time+=lst[ind+1][2]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  for k in range(n-j-1):
    if time<=lst[j+1][1] :
      time=lst[j+1][0]+lst[j+1][1]
    elif (time-lst[j+1][1])%lst[j+1][2]==0:
      time+=lst[j+1][2]
    else:
      time+=lst[j+1][2]+lst[j+1][2]-(time-lst[j+1][1])%lst[j+1][2]
  print(time)
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
station = (tuple(map(int, input().split())) for _ in range(n-1))

for i in range(n):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        res += max(s - res, (res+f-1)//f*f - res) + c
    print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
lists=[list(map(int,input().split())) for _ in range(n-1)]
lists.append(s)   
for x in range(n):
    nums=x+1
    if nums==n:
        print(0)
    
    else:
        times=0
        while nums<n:
            if times>=lists[nums-1][1]:
                if (times-lists[nums-1][1])%lists[nums-1][2]!=0:
                    a=(times-lists[num-1][1])%lists[nums-1][2]
                    
                times+=lists[nums-1][0]
                nums+=1      
            else:
                times=lists[nums-1][1]
                times+=lists[nums-1][0]   
                nums+=1 
        print(times)

Submission status: Runtime Error

Solution code:
# ABC084C - Special Trains
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    for i in range(n):
        cur = 0
        for c, s, f in A[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        print(cur)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long n, t, j;
    vector<vector<long long>> csf(501, vector<long long>(3, 0));
    
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> csf[i][0] >> csf[i][1] >> csf[i][2];
    
    for(int i = 0; i < n - 1; i++){
        j = i;
        t = 0;
        while(j < n - 1){
            if(t >= csf[j][1])
                t = (long long)ceil((double)t / csf[j][2]) * csf[j][2];
            else
                t = csf[j][1];
            t += csf[j][0];
            j++;
        }
        cout << t << endl;
    }
    
    cout << 0 << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
n = (input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n):
    point = i
    ans = 0
    while point < n-1:
        c, s, f = csf[point][0], csf[point][1], csf[point][2]
        if ans < s:
            ans += s-ans+c
        else:
            if ans%f != 0:
                ans += f-(ans%f)
            ans += c
        point += 1
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%ans[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        elif time % F[j]:
            time += F[j] - (t % F[j])
        time += C[j]
        
    print(time)

Submission status: Runtime Error

Solution code:
n=int(input())
m=[]
for c,s,f in map(int,input().split()):
  m.append(0)
  for i in range(len(m)):
    if m[i]>s:
      m[i]=s+((m[i]-s)//f+((m[i]-s)%f>0))*f+c
    else:#m[i]<=s
      m[i]=s+c
m.append(0)
for i in m:
  print(i)

Submission status: Runtime Error

Solution code:
n = int(input())
C = []
S = []
F = []
for i in range(n-1):
  c,s,f = map(int, input().split())
  C.append(c)
  S.append(s)
  F.append(f)  
  
for i in range(n):
  t = 0
  for j in range(i,n-1):
    if t < S[j]:
      t = S[j]
    elif t % F[j] == 0:
      ;#到着タイミングと発車タイミングが同じなので待ち時間0
    else:
      t = t + F[j] - (t % F[j])  
    t += C[j]
  print(t)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split()))for i in range(n-1)]
for i in range(n-1):
  t=0
  for j in range(j,n-1):
    if t<l[j][1]:
      t=l[j][1]
    if t%l[j][2]!=0:
      t=(t%l[j][2]+1)*l[j][2]
    t+=l[j][0]
  print(t)
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += total_time % f
        # take train
        time += c
        total_time += time
    print(total_time

Submission status: Runtime Error

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(15001 ) :
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Runtime Error

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(10**3):
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Runtime Error

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(10**4):
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Runtime Error

Solution code:

import math
import bisect


prime = [2,3,5,7,11,13,17,19]
for i in range(prime[-1]+2,100,2):

    x = int( math.sqrt(i) )
    x += 1 if x%2 == 0 else 0

    found = False
    for p in prime:
        if p>x:
            break;

        if i % p == 0:
            found = True
                
    if not found:
        prime.append(i)

#print(prime)


q = int(input())
for _ in range(q):
    l, r = map(int,input().split())
    l += 1 if l%2 == 0 else 0

#    print((l,r))

    ans = 0
    for i in range( l , r+1, 2):

        #si = bisect.bisect_left(prime,i)
        xi = bisect.bisect_right(prime, i)
        yi = bisect.bisect_right(prime, (i+1)//2)
        ans += 1 if prime[xi-1] == i and prime[yi-1] == (i+1)//2 else 0

    print(ans)

Submission status: Runtime Error

Solution code:
from math import ceil


def solve(string):
    pass
    n, *csf = map(int, string.split())
    f_list = []
    for c, s, f in csf:
        f_list = [c + ceil((max(_f, s)) / f) * f for _f in f_list]
        f_list.append(c + s)
    f_list.append(0)
    return "\n".join([str(_f) for _f in f_list])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))

Submission status: Runtime Error

Solution code:
n = int(input())
c,s,f = [0]*n,[0]*n,[0]*n
for i in range(n-1):
    c[i],s[i],f[i] = map(int,input().split())
for i in range(n):
    cnt = 0
    j = i
    while j < n-1:
        if cnt <= s[j]:
            cnt += s[j]+c[j]
        else:
            cnt = s[j]+(cnt - s[j])//f[j]+[0,1]((cnt - s[j])%f[j])+c[j]
        j += 1
    print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
csf = []
for i in range(n):
    csf.append(list(map(int,input().split())))


for i in range(n-1):
    time = 0
    for j in  range(i,n-1):
        if time < csf[j][1]:
            time = csf[j][0] + csf[j][1]
        else:
            tmp = (time-csf[j][1])%csf[j][2] +csf[j][0]
            time += tmp
    print(time)

print('0')

Submission status: Runtime Error

Solution code:
n = int(input())
c_list = []
s_list = []
f_list = []
def train(i,c_list=c_list,s_list=s_list,f_list=f_list):
    global ans    
    if s_list[i+1] < ans: 
        ans += (f_list[i+1]-(ans % f_list[i+1])+c_list[i+1])
    elif s_list[i+1] == ans:
        ans += c_list[i+1]
    else:
        ans = s_list[i+1] + c_list[i+1]
    global count
    count += 1
    if count != n-2-i:
        train(i+count,c_list=c_list,s_list=s_list,f_list=f_list)
    else:
        print(ans)
for i in range(n-1):
    c,s,f = map(int, input().split())
    c_list.append(c)
    s_list.append(s)
    f_list.append(f)
for j in range(n-2):
    ans = s_list[j] + c_list[j]
    count = 0
    train(j,c_list=c_list,s_list=s_list,f_list=f_list)    
print(s_list[n-2]+c_list[n-2])
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
c_list = []
s_list = []
f_list = []
def train(i=i,c_list=c_list,s_list=s_list,f_list=f_list):
    global ans    
    if s_list[i+1] < ans: 
        ans += (f_list[i+1]-(ans % f_list[i+1])+c_list[i+1])
    elif s_list[i+1] == ans:
        ans += c_list[i+1]
    else:
        ans = s_list[i+1] + c_list[i+1]
    global count
    count += 1
    if count != n-2-i:
        train(i+count=i+count,c_list=c_list,s_list=s_list,f_list=f_list)
    else:
        print(ans)
for i in range(n-1):
    c,s,f = map(int, input().split())
    c_list.append(c)
    s_list.append(s)
    f_list.append(f)
for j in range(n-2):
    ans = s_list[j] + c_list[j]
    count = 0
    train(j=j,c_list=c_list,s_list=s_list,f_list=f_list)    
print(s_list[n-2]+c_list[n-2])
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
c_list = []
s_list = []
f_list = []
def train(i):
    global ans    
    if s_list[i+1] < ans: 
        ans += (f_list[i+1]-(ans % f_list[i+1])+c_list[i+1])
    elif s_list[i+1] == ans:
        ans += c_list[i+1]
    else:
        ans = s_list[i+1] + c_list[i+1]
    global count
    count += 1
    if count != n-2-i:
        train(i+count)
    else:
        print(ans)
for i in range(n-1):
    c,s,f = map(int, input().split())
    c_list.append(c)
    s_list.append(s)
    f_list.append(f)
for j in range(n-2):
    ans = s_list[j] + c_list[j]
    count = 0
    train(j)    
print(s_list[n-2]+c_list[n-2])
print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N) :
    if j == N-1 :
        print(0)
    else :
        ans = 0
        for j in range(i,N-1) :
            if ans < S[j] :
                ans = S[j]
            if ans % F[j] != 0 :
                ans = (ans//F[j]-1)*F[j]
            ans += C[j]
        print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N) :
    if j == N-1 :
        print(0)
    else :
        ans = 0
        for j in range(i,N-1) :
            if ans < S[j] :
                ans = S[j]
            if ans % F[j] != 0 :
                ans = (ans//F[k]-1)*F[k]
            ans += C[k]
        print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
C = [0 for _ in range(N-1)]
S = [0 for _ in range(N-1)]
F = [0 for _ in range(N-1)]
for i in range(N-1):
	C[i],S[i],F[i] = map(int,input().split())

def f(i):
	s = 0
	while i < N-1:
		# find the fastest train at time s from i stattion.
		if s <= S[i]:
			s = S[i]+C[i]
		else:
			m = (s-S[i]) % F[i]
			if m == 0:
				s = s + C[i]
			else:
				s = s + (F-m) + C[i]
			# we use the fact that F[i] | S[i]
		i += 1
	return s

for i in range(N):
	print(f(i))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 02:27:58 2018

@author: Yuki
"""

N = int(input())
data  = []
for i in range(N-1):
    c, s, f = map(int, input().split())
#    data.append([c, s, f])

def train_time(start_time=0, data_list=[12, 24, 6]):
    if data_list[1] <= start_time:
        return start_time + (data_list[2] - start_time%data_list[2])%data_list[2] + data_list[0]
    else:
        return data_list[1] + data_list[0]

#N = 4
#data = [[12, 24, 6], [52, 16, 4], [99, 2, 2]]

res = []
for i in range(N-1):
    need_time = 0
    for ii in range(i, N-1):
        need_time = train_time(need_time, data[ii])
    res.append(need_time)

for i in range(N-1):
    print(res[i])

Submission status: Runtime Error

Solution code:
n = input('input N: ')

c, s, f = [], [], []
for i in range(int(n) - 1):
    tmp = input('input C, S, F: ').split()
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

# n = 3
# c = [6, 1]
# s = [5, 10]
# f = [1, 1]
# n = 4
# c = [12, 52, 99]
# s = [24, 16, 2]
# f = [6, 4, 2]
# n = 4
# c = [12, 44, 66]
# s = [13, 17, 4096]
# f = [1, 17, 64]

a = [None] * n
for i in reversed(range(int(n))):

    if i == n - 1:
        a[i] = 0
        continue

    ta = s[i] + c[i]
    if i == n - 2:
        a[i] = ta
        continue

    for j in range(i, n - 2):
        nn = j + 1
        if ta <= s[nn]:
            ta = a[nn]
        else:
            yo = ta % f[nn]
            add = 0 if yo == 0 else f[nn] - yo
            ta += add + c[nn]
    a[i] = ta


[print(aa) for aa in a]

Submission status: Runtime Error

Solution code:
 = int(input())
C = []
S = []
F = []
for i in range(N-1):
    C_temp,S_temp,F_temp = map(int,input().split())
    C.append(C_temp)
    S.append(S_temp)
    F.append(F_temp)
ans = S[0]
for i in range(N):
    t = 0
    for j in range(i,N-1):
        if t<S[j]:
            t = S[j]
        elif t%F[j] == 0:
            pass
        else:
            t = t+F[j] -t%F[j]
        t += C[j]
    print(t)

Submission status: Runtime Error

Solution code:
import bisect

def main():
    N = int(input())
    CSF = tuple(tuple(map(int, input().split())) for _ in [0] * (N - 1))

    start = [[] for _ in [0] * N]
    arrival = 50000
    for i, (c, s, f) in enumerate(CSF):
        start[i] = [j for j in range(s, arrival, f)]

    for i in range(N - 1):
        sec = 0
        for j in range(i, N - 1):
            n = bisect.bisect_left(start[j], sec)
            sec = start[j][n] + CSF[j][0]
        print(sec)
    print(0)

main()

Submission status: Runtime Error

Solution code:
import bisect

def main():
    N = int(input())
    CSF = tuple(tuple(map(int, input().split())) for _ in [0] * (N - 1))

    start = [[] for _ in [0] * N]
    for i, (c, s, f) in enumerate(CSF):
        arrival = s + c + 1
        start[i] = [j for j in range(s, arrival, f)]

    for i in range(N - 1):
        sec = 0
        for j in range(i, N - 1):
            n = bisect.bisect_left(start[j], sec)
            sec = start[j][n] + CSF[j][0]
        print(sec)
    print(0)

main()

Submission status: Runtime Error

Solution code:
n = int(input())
c,s,f = [0]*(n-1)
for i in range(n-1): c[i],s[i],f[i] = map(int,input().split())
for j in range(n-1):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)