n, hour, min, t_min = gets.chomp.split.map &:to_i min += (n - 1) * t_min hour += min / 60 hour %= 24 min %= 60 p hour p min