import java.util.Scanner object Problem296 { def proc(n: Int, hh: Int, mm: Int, cyclemm: Int): Seq[Int] = { val afterhh = (cyclemm * (n - 1) + mm + hh * 60) / 60 % 24 val aftermm = (cyclemm * (n - 1) + mm) % 60 Seq(afterhh, aftermm) } def main(args: Array[String]) { val sc = new Scanner(System.in) val N = sc.nextInt() val H = sc.nextInt() val M = sc.nextInt() val T = sc.nextInt() val result = proc(N, H, M, T) println(result.mkString("\n")) } }