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