n,h,m,t=gets.split.map(&:to_i) m+=(n-1)*t h+=m/60 m%=60 h%=24 p h,m