import java.util.*; public class pre { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(),h = s.nextInt(),m = s.nextInt(),t = s.nextInt(); int time = h * 60 + m; int count = 1; while(count < n){ time = time + t; count++; } System.out.println(time/60); System.out.println(time%60); } }