#import <stdio.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
int WAIT(int t, int s, int f){
    int r = t%f;
    return (s>=t) ? s-t : r==0 ? 0 : f-r;
}

int main(){
    int N;
    int C[600] = {0};
    int S[600] = {0};
    int F[600] = {0};
    scanf("%d",&N);
    for(int i=1;i<=N-1;i++){
        int c,s,f;
        scanf("%d %d %d",&c,&s,&f);
        C[i] = c;
        S[i] = s;
        F[i] = f;
    }
    for(int i=1;i<=N-1;i++){
        int t = S[i] + C[i];
        for(int j=i+1;j<=N-1;j++){
            t += WAIT(t,S[j],F[j]) + C[j];
        }
        printf("%d\n",t);
    }
    printf("0\n");
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_639/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_639/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@.str.1 = private unnamed_addr constant [9 x i8] c"%d %d %d\00", align 1
@.str.2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@str = private unnamed_addr constant [2 x i8] c"0\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @WAIT(i32 noundef %t, i32 noundef %s, i32 noundef %f) local_unnamed_addr #0 {
entry:
  %cmp.not = icmp slt i32 %s, %t
  br i1 %cmp.not, label %cond.false, label %cond.true

cond.true:                                        ; preds = %entry
  %sub = sub nsw i32 %s, %t
  br label %cond.end5

cond.false:                                       ; preds = %entry
  %rem = srem i32 %t, %f
  %cmp1 = icmp eq i32 %rem, 0
  %sub4 = sub nsw i32 %f, %rem
  %cond = select i1 %cmp1, i32 0, i32 %sub4
  br label %cond.end5

cond.end5:                                        ; preds = %cond.false, %cond.true
  %cond6 = phi i32 [ %sub, %cond.true ], [ %cond, %cond.false ]
  ret i32 %cond6
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #2 {
entry:
  %N = alloca i32, align 4
  %C = alloca [600 x i32], align 16
  %S = alloca [600 x i32], align 16
  %F = alloca [600 x i32], align 16
  %c = alloca i32, align 4
  %s = alloca i32, align 4
  %f = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #6
  call void @llvm.lifetime.start.p0(i64 2400, ptr nonnull %C) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2400) %C, i8 0, i64 2400, i1 false)
  call void @llvm.lifetime.start.p0(i64 2400, ptr nonnull %S) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2400) %S, i8 0, i64 2400, i1 false)
  call void @llvm.lifetime.start.p0(i64 2400, ptr nonnull %F) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2400) %F, i8 0, i64 2400, i1 false)
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N)
  %0 = load i32, ptr %N, align 4, !tbaa !5
  %cmp.not.not53 = icmp sgt i32 %0, 1
  br i1 %cmp.not.not53, label %for.body, label %for.cond.cleanup10

for.cond7.preheader:                              ; preds = %for.body
  %cmp9.not.not58 = icmp sgt i32 %4, 1
  br i1 %cmp9.not.not58, label %for.body11, label %for.cond.cleanup10

for.body:                                         ; preds = %entry, %for.body
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 1, %entry ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %c) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %s) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %f) #6
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %c, ptr noundef nonnull %s, ptr noundef nonnull %f)
  %1 = load i32, ptr %c, align 4, !tbaa !5
  %arrayidx = getelementptr inbounds [600 x i32], ptr %C, i64 0, i64 %indvars.iv
  store i32 %1, ptr %arrayidx, align 4, !tbaa !5
  %2 = load i32, ptr %s, align 4, !tbaa !5
  %arrayidx3 = getelementptr inbounds [600 x i32], ptr %S, i64 0, i64 %indvars.iv
  store i32 %2, ptr %arrayidx3, align 4, !tbaa !5
  %3 = load i32, ptr %f, align 4, !tbaa !5
  %arrayidx5 = getelementptr inbounds [600 x i32], ptr %F, i64 0, i64 %indvars.iv
  store i32 %3, ptr %arrayidx5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %f) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %s) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %c) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %4 = load i32, ptr %N, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %cmp.not.not = icmp slt i64 %indvars.iv.next, %5
  br i1 %cmp.not.not, label %for.body, label %for.cond7.preheader

for.cond.cleanup10:                               ; preds = %for.cond.cleanup20, %entry, %for.cond7.preheader
  %puts = call i32 @puts(ptr nonnull dereferenceable(1) @str)
  call void @llvm.lifetime.end.p0(i64 2400, ptr nonnull %F) #6
  call void @llvm.lifetime.end.p0(i64 2400, ptr nonnull %S) #6
  call void @llvm.lifetime.end.p0(i64 2400, ptr nonnull %C) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #6
  ret i32 0

for.body11:                                       ; preds = %for.cond7.preheader, %for.cond.cleanup20
  %indvars.iv66 = phi i64 [ %indvars.iv.next67, %for.cond.cleanup20 ], [ 1, %for.cond7.preheader ]
  %indvars.iv61 = phi i64 [ %indvars.iv.next62, %for.cond.cleanup20 ], [ 2, %for.cond7.preheader ]
  %6 = phi i32 [ %10, %for.cond.cleanup20 ], [ %4, %for.cond7.preheader ]
  %arrayidx13 = getelementptr inbounds [600 x i32], ptr %S, i64 0, i64 %indvars.iv66
  %7 = load i32, ptr %arrayidx13, align 4, !tbaa !5
  %arrayidx15 = getelementptr inbounds [600 x i32], ptr %C, i64 0, i64 %indvars.iv66
  %8 = load i32, ptr %arrayidx15, align 4, !tbaa !5
  %add = add nsw i32 %8, %7
  %indvars.iv.next67 = add nuw nsw i64 %indvars.iv66, 1
  %9 = sext i32 %6 to i64
  %cmp19.not.not55 = icmp slt i64 %indvars.iv.next67, %9
  br i1 %cmp19.not.not55, label %for.body21.preheader, label %for.cond.cleanup20

for.body21.preheader:                             ; preds = %for.body11
  %wide.trip.count = zext i32 %6 to i64
  br label %for.body21

for.cond.cleanup20:                               ; preds = %WAIT.exit, %for.body11
  %t.0.lcssa = phi i32 [ %add, %for.body11 ], [ %add30, %WAIT.exit ]
  %call34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %t.0.lcssa)
  %10 = load i32, ptr %N, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %cmp9.not.not = icmp slt i64 %indvars.iv.next67, %11
  %indvars.iv.next62 = add nuw nsw i64 %indvars.iv61, 1
  br i1 %cmp9.not.not, label %for.body11, label %for.cond.cleanup10

for.body21:                                       ; preds = %for.body21.preheader, %WAIT.exit
  %indvars.iv63 = phi i64 [ %indvars.iv61, %for.body21.preheader ], [ %indvars.iv.next64, %WAIT.exit ]
  %t.056 = phi i32 [ %add, %for.body21.preheader ], [ %add30, %WAIT.exit ]
  %arrayidx23 = getelementptr inbounds [600 x i32], ptr %S, i64 0, i64 %indvars.iv63
  %12 = load i32, ptr %arrayidx23, align 4, !tbaa !5
  %cmp.not.i = icmp slt i32 %12, %t.056
  br i1 %cmp.not.i, label %cond.false.i, label %cond.true.i

cond.true.i:                                      ; preds = %for.body21
  %sub.i = sub nsw i32 %12, %t.056
  br label %WAIT.exit

cond.false.i:                                     ; preds = %for.body21
  %arrayidx25 = getelementptr inbounds [600 x i32], ptr %F, i64 0, i64 %indvars.iv63
  %13 = load i32, ptr %arrayidx25, align 4, !tbaa !5
  %rem.i = srem i32 %t.056, %13
  %cmp1.i = icmp eq i32 %rem.i, 0
  %sub4.i = sub nsw i32 %13, %rem.i
  %cond.i = select i1 %cmp1.i, i32 0, i32 %sub4.i
  br label %WAIT.exit

WAIT.exit:                                        ; preds = %cond.true.i, %cond.false.i
  %cond6.i = phi i32 [ %sub.i, %cond.true.i ], [ %cond.i, %cond.false.i ]
  %arrayidx28 = getelementptr inbounds [600 x i32], ptr %C, i64 0, i64 %indvars.iv63
  %14 = load i32, ptr %arrayidx28, align 4, !tbaa !5
  %add29 = add i32 %cond6.i, %t.056
  %add30 = add i32 %add29, %14
  %indvars.iv.next64 = add nuw nsw i64 %indvars.iv63, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next64, %wide.trip.count
  br i1 %exitcond.not, label %for.cond.cleanup20, label %for.body21
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #5

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nofree nounwind }
attributes #6 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
