import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class No0293 { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { int n = in.nextInt(); int h = in.nextInt(); int m = in.nextInt(); int t = in.nextInt(); while (n-- > 1) { m += t; h += m/60; m %= 60; h %= 24; } out.println(h); out.println(m); } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); out.close(); } static void trace(Object... o) { System.out.println(Arrays.deepToString(o));} }