list1 =list(map(int, input().split())) N = list1[0] H = list1[1] M = list1[2] T = list1[3] A = (N-1)*5 print(H + A // 60) print(A-(A// 60)+M)