def main(): N,H,M,T = map(int, input().split()) minute = H*60 + M + (N-1)*T print(minute // 60) print(minute % 60) if __name__ == '__main__': main()