n=int(input()) h=int(input()) m=int(input()) t=int(input()) m_up=m+t*(n-1) h_up=h+m_up//60 m_up%=60 print(h_up) print(m_up)