import std.stdio, std.conv, std.string, std.range, std.math, std.bigint, std.algorithm; void main() { auto input = readln.split.to!(long[]); auto N = input[0], H = input[1], M = input[2], T = input[3]; auto wakeup = ((H * 60 + M) + T * (N - 1)) % 1440; "%s\n%s".writefln(wakeup / 60, wakeup % 60); }