n,h,m,t=map(int,input().split()) print('%d\n%d'%divmod((h*60+m+t*(n-1))%1440,60))