let n = Scanf.scanf " %d" (+) 0
let cs, ss, fs, t, k = Array.(make (n - 1) 0, make (n - 1) 0, make (n - 1) 0, ref 0, ref 0)
let _ = Array.init (n - 1) @@ fun i -> Scanf.scanf " %d %d %d" @@ fun a b c -> cs.(i) <- a; ss.(i) <- b; fs.(i) <- c
let _ = for j = 0 to n - 2 do t := 0; for i = j to n - 2 do k := max 0 @@ (!t - ss.(i) + fs.(i) - 1) / fs.(i); t := ss.(i) + !k * fs.(i) + cs.(i) done; Printf.printf "%d\n" !t done; print_endline "0"