n, h, m, t = gets.split.map(&:to_i) m += (n - 1) * t extra_hour = 0 if m >= 60 extra_hour = m / 60 m %= 60 puts h + extra_hour, m else puts h, m end