N,H,M,T=gets.split.map(&:to_i) M+=(N-1)*T H+=M/60 M%=60 H%=24 puts H,M