#!/usr/bin/env python
#coding:UTF-8

N,H,M,T = map(int,raw_input().split())
calc = (N - 1) * T

H = H + int(calc / 60)
M = M + int(calc % 60)

print H
print M