a,b,c,d=gets.split.map &:to_i x=b*60+c+(a-1)*d puts [x/60,x%60]