class Yukicoder def initialize n, l = gets.chomp.split.map(&:to_i) time = 0 current = 0 cross = [] n.times do x, w, t = gets.chomp.split.map(&:to_i) cross << [x,w,t] end cross.each do |c| x, w, t = *c time += (x - current) current = x if (time/t).even? if (t - time%t) < w time += (t - time%t) + t + w else time += w end else time += (t - time%t) + w end current = x + w end puts time + (l - current) end end Yukicoder.new