from fractions import Fraction
import datetime
x, d = input().split()
h, m, s = map(int, x.split(':'))
if d == 'PM':
h += 12
h %= 12
# t = int(8 * 3600 + (3600 * (h - 8) + 60 * m + s) / 239 * 240)
# h1 = t // 3600
# m1 = (t - 3600 * h1) // 60
# s1 = t - 3600 * h1 - 60 * m1
print(h, m, s)
t0 = 3600 * h + 60 * m + s
t = t0 - 8 * 3600 if t0 > 8 * 3600 else 24 * 3600 - (8 * 3600 - t0)
d = t // 239
print(t0, t, d)
t1 = datetime.datetime(2000, 1, 1, 8, 0, 0) + datetime.timedelta(seconds = d * 239)
print(t1.strftime("%I:%M:%S %p"))
time = datetime.datetime(2000, 1, 1, 8, 0, 0) + datetime.timedelta(seconds = d * 240)
print(time.strftime("%I:%M:%S %p"))
To embed this program on your website, copy the following code and paste it into your website's HTML: