n,h,m,t=map(int,input().split()) m+=t*(n-1) dh,m=divmod(m,60) print(h+dh) print(m)