import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int h =sc.nextInt(); int m =sc.nextInt(); int t =sc.nextInt(); int ans1 = 0; int ans2 = 0; int x = h * 60 * 60 + m * 60; for(int i = 0 ; i < n - 1 ; i++) { x += t * 60; } x %= 3600 * 24; ans1 = x / 3600; ans2 = (x - ans1 * 3600) / 60; System.out.println(ans1); System.out.println(ans2); } }