import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Stream; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] NHMT = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int n = NHMT[0]; int h = NHMT[1]; int m = NHMT[2]; int t = NHMT[3]; System.out.println((h + (m + (n - 1) * t) / 60) % 24); System.out.println((m + (n - 1) * t) % 60); } }