package yukicoder; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { String[] box = buff.readLine().split(" "); int n = Integer.parseInt(box[0]); int h = Integer.parseInt(box[1]); int m = Integer.parseInt(box[2]); int t = Integer.parseInt(box[3]); int sleep = (n-1) * t; h += (m + sleep) / 60; m = (m + sleep) % 60; h %= 24; System.out.println(h + "\n" + m); } catch (Exception e) { e.getStackTrace(); } } }