n,h,m,t = map(int, input().split()) sum = (n-1)*t sum_h = sum//60 sum_t = sum%60 print(m + sum_h) print(t + sum_t)