Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.

Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of alarms.

Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary.

Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing.


-----Output-----

Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better.


-----Examples-----
Input
1
05:43

Output
23:59

Input
4
22:00
03:21
16:03
09:59

Output
06:37



-----Note-----

In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = []
for i in range(n):
	h, m = map(int, input().split(":"))
	a.append((h + 24) * 60 + m)
	a.append(h * 60  + m)
a.sort()
j = 0
s = 0
ans = 0
for i in range(0, 48 * 60):
	if (j < 2 * n and a[j] == i):
		ans = max(ans, s)
		s = 0
		j += 1
		continue
	else:
		s += 1
h = ans // 60
m = ans % 60
hans = ""
mans = ""
if h < 10:
	hans = "0" + str(h)
else:
	hans = str(h)
if m < 10:
	mans = "0" + str(m)
else:
	mans = str(m)
print(hans + ":" + mans)

import datetime


n = int(input())
dts_i = [[int(y) for y in input().split(':')] for x in range(n)]
dts = []

for h, m in dts_i:
    dts.append(datetime.datetime(2017, 1, 1, h, m))

for h, m in dts_i:
    dts.append(datetime.datetime(2017, 1, 2, h, m))

for h, m in dts_i:
    dts.append(datetime.datetime(2017, 1, 3, h, m))

dts = sorted(dts)
pairs = list(zip(dts, dts[1:]))
lo, hi = max(pairs, key=lambda xy: xy[1] - xy[0])
delta = hi - lo - datetime.timedelta(minutes=1)

hours, remainder = divmod(delta.seconds, 3600)
minutes, seconds = divmod(remainder, 60)

print('{0:02d}:{1:02d}'.format(hours, minutes))


import sys
n=int(input())
if n==1:
    print('23:59')
    return
a=[]
for i in range(n):
    k,b=map(int,input().split(':'))
    a+=[k*60+b]

a=sorted(a)

mn=0
for i in range(1,n):
    mn=max(mn,a[i]-a[i-1])
mn=max(mn,24*60-a[n-1]+a[0])
mn-=1
s=''
if(mn//60<10): s+='0'
s+=str(mn//60)
s+=':'
if(mn%60<10): s+='0'
s+=str(mn%60)
print(s)

n = int(input())
day = 24 * 60
v = []
for i in range(n) :
    s = input()
    h = int(s[0]) * 10 + int(s[1])
    m = int(s[3]) * 10 + int(s[4])
    tim = h * 60 + m
    v.append(int(tim))
    v.append(int(tim + day))
    v.append(int(tim + day + day))
v.sort()
ans = 0
for i in range (len(v)) :
    if i > 0:
        ans = max(ans, v[i] - v[i - 1] - 1)
m = ans % 60
h = ans // 60
print(str(h // 10) + str(h % 10) + ':' + str(m // 10) +  str(m % 10))

n = int(input())
a = []

for i in range(n):
    str = input()
    h = int(str[0:2]) * 60
    m = int(str[3:5])
    a.append(h + m)

a.sort()

mx = 0

for i in range(n - 1):
    if mx < ((-a[i] + a[i + 1]) - 1):
        mx = ((-a[i] + a[i + 1]) - 1)
if mx < (1440 + a[0] - a[n - 1] - 1):
    mx = 1440 + a[0] - a[n - 1] - 1

if (mx // 60) < 10:
    print('0',end='')
    
print(mx // 60,end='')

print(':',end='')

if (mx % 60) < 10:
    print('0',end='')

print(mx % 60)


n=int(input())
h=[0] * n
m=[0] * n
for i in range(0,n) :
    h[i],m[i]=map(int,input().split(':'))
for i in range(0,n) :
    for j in range(i,n) :
        if h[j]<h[i] or (h[j]==h[i] and m[j]<m[i]) :
            t=h[j]
            h[j]=h[i]
            h[i]=t
            t=m[j]
            m[j]=m[i]
            m[i]=t
mxh=0
mxm=0
for i in range(0,n) :
    if i==n-1 :
        nowh=h[0]+24-h[i]
        nowm=m[0]-m[i]-1
        if nowm < 0 :
            nowh=nowh-1
            nowm=nowm+60
        if mxh<nowh or (mxh==nowh and mxm<nowm) :
            mxh=nowh
            mxm=nowm
    else :
        nowh=h[i+1]-h[i]
        nowm=m[i+1]-m[i]-1
        if nowm < 0 :
            nowh=nowh-1
            nowm=nowm+60
        if mxh<nowh or (mxh==nowh and mxm<nowm) :
            mxh=nowh
            mxm=nowm
print('%02d:%02d'%(mxh,mxm))

n = int(input())
x = []
for i in range (n):
    a, b = map(int, (input().split(':')))
    x.append(a*60 + b);
x = sorted(x)
x.append(x[0] + 24*60)
m = 0
for i in range(n):
    m = max(m, x[i+1] - x[i]-1)
x = str(m // 60)
y = str(m % 60)
if len(x) < 2:
    x = '0' + x
if len(y) < 2:
    y = '0' + y
s = x + ':' + y
print(s)

n = int(input())
s = ['.'] * n
mx = 0
for i in range(n):
    s[i] = input()
if n == 1:
    print('23:59')
else:
    s = sorted(s)
    for i in range(n):
        i1 = i
        i2 = (i + 1) % n
        col1 = int(s[i1][0:2]) * 60 + int(s[i1][3:5])
        col2 = int(s[i2][0:2]) * 60 + int(s[i2][3:5])
        if col1 > col2:
            if mx < col2 + 60 * 24 - col1 - 1:
                mx = col2 + 60 * 24 - col1 - 1
        else:
            if mx < col2 - col1 - 1:
                mx = col2 - col1 - 1
    print((mx // 60) // 10, (mx // 60) % 10, ':', (mx % 60) // 10, (mx % 60) % 10, sep = '')
 


n=int(input())
a=[0]*1000
for i in range(n):
    s=input()
    t1=s[0]+s[1]
    t2=s[3]+s[4]
    a[i]=60*int(t1)+int(t2)
for i in range(n):
    for j0 in range(i,n-1):
        j=n+i-2-j0
        if (a[j]>a[j+1]):
            q=a[j+1]
            a[j+1]=a[j]
            a[j]=q
a[n]=24*60+a[0]
mx=a[0]
for i in range(n):
    mx=max(mx,a[i+1]-a[i]-1)
q1=(mx//60)
q2=(mx%60)
if q1==0:
    s1="00"
elif q1<10:
    s1="0"+str(q1)
else:
    s1=str(q1)

if q2==0:
    s2="00"
elif q2<10:
    s2="0"+str(q2)
else:
    s2=str(q2)
print(s1+":"+s2)


n = int(input())
t = []
for i in range(n):
    t.append(tuple(map(int, input().split(':'))))

ans = 0

t.sort()
t = t + [(v[0]+24, v[1]) for v in t]

for i in range(len(t)-1):
    #print(t[i+1][0] - t[i][0])*60+(t[i+1][1] - t[i][1])
    ans = max(ans, (t[i+1][0] - t[i][0])*60+(t[i+1][1] - t[i][1]) - 1)


print('{}:{}'.format(str(ans//60).rjust(2, '0'), str(ans%60).rjust(2, '0')))

n = int(input())
p = list()
for i in range(0, n):
    g, o = list(map(int, input().split(':')))
    p.append(g * 60 + o)
p.sort()
answ = 1440 - p[n - 1] + p[0]
for i in range(1, n):
    answ = max(answ, p[i] - p[i - 1])
k = str()
answ = answ - 1
if (answ // 60 < 10):
    k = k + "0" + str(answ // 60) + ":"
else:
    k = k + str(answ // 60) + ":"
if (answ % 60 < 10):
    k = k + "0" + str(answ % 60)
else:
    k = k + str(answ % 60)
print(k)


n = int(input())
time = [None] * n
for i in range(n):
	t = input()
	h, m = t.split(':')
	h, m = int(h), int(m)
	num = h*60 + m
	time[i] = num
time.sort()
time.append(time[0] + 1440)
ans = (time[1] - time[0] - 1)
for i in range(i+1):
    ans = max(ans, time[i+1] - time[i] - 1)
print('{:02d}:{:02d}'.format(*divmod(ans, 60)))
    



n = int(input())
alarms = []
for i in range (n):
    line = [int(x) for x in input().strip().split(':')]
    alarms.append(line[0] * 60 + line[1])
alarms = sorted(alarms)
tmp = [1440 + x for x in alarms]
alarms += tmp
ans = 0
for i in range(1, len(alarms)):
    if (i > 0):
        ans = max(ans, alarms[i] - alarms[i - 1] - 1)
print("%02d:%02d" % (ans // 60, ans % 60))

n = int(input())
times = [0] * 2880
for _ in range(n):
    hh, mm = map(int, input().split(':'))
    t = hh * 60 + mm
    times[t] = 1
    times[t + 1440] = 1

i = 0
res = -1
while i < 1440:
    for j in range(i, i + 1440):
        if times[j] == 1:
            break
    res = max(res, j - i)
    i = j + 1
hh, mm = divmod(res, 60)
print('{:02d}:{:02d}'.format(hh, mm))

n = int(input())
arr = []
for i in range(n):
    h, m = map(int, input().split(':'));
    cur = h * 60 + m;
    arr.append(cur)
arr.sort()
arr.append(24 * 60 + arr[0])
maxx = 0
for i in range(1, len(arr)):
    maxx = max(maxx, arr[i] - arr[i - 1] - 1)
m = maxx % 60
h = maxx // 60
if (h < 10):
    print(0, end ='');
print(h, ':', sep = '', end = '')
if (m < 10):
    print(0, end = '')
print(m)

our = []
for i in range(int(input())):
    s = input()
    our.append(int(s[0:2]) * 60 + int(s[3:]))
our.sort()
our.append(our[0] + 24 * 60)

res = 0
for i in range(len(our) - 1):
    res = max(res, our[i + 1] - our[i])

res -= 1
hour = str(res // 60)
minute = str(res % 60)
if len(hour) < 2:
    hour = '0' + hour
if len(minute) < 2:
    minute = '0' + minute
print(hour + ':' + minute)

def formatted_number(number):
	if (number < 10):
		return "0" + str(number)

	return str(number)


def print_max_duration(time):
	hh = time // 60
	mm = time - hh * 60

	print(formatted_number(hh)+":"+formatted_number(mm))


def parse_minutes(time):
	hh = int(time[0:2])
	mm = int(time[3:])
	return hh * 60 + mm

def main():
	n = int(input())

	arr = []

	for i in range(n):
		arr.append(parse_minutes(input()))

	arr = sorted(arr)

	max_duration = 0
	for i in range(n - 1):
		max_duration = max(max_duration, arr[i + 1] - arr[i] - 1)

	max_duration = max(max_duration, (24 * 60 - arr[n - 1] - 1) + arr[0])
	print_max_duration(max_duration)



def __starting_point():
	main()
__starting_point()

n = int(input())
a = []
def mem(kek):
    return (int(kek[0])*10 + int(kek[1]))*60 + int(kek[3])*10 + int(kek[4])
def lol(kek):
    h = str(kek//60)
    m = str(kek%60)
    ans = ""
    if (len(h)<2): ans+="0"
    ans+=h
    ans+=":"
    if (len(m)<2): ans+="0"
    ans+=m
    return ans
delt = 60*24
for i in range(n):
    st = input()
    a.append(mem(st))
    a.append(mem(st)+delt )
    a.append(mem(st)+2*delt)

a = sorted(a)
ans = 0
for i in range(1,len(a)):
    ans = max(ans, a[i] - a[i-1] - 1)
print(lol(ans))


n = int(input())
times = []
for _ in range(n):
    time = str(input())
    times.append((int(time[:2]), int(time[3:])))

times.sort()

def to_minutes(a):
    return 60*a[0] + a[1]

def to_hours(a):
    return (a // 60, a % 60)

def pad(a):
    return ('0' if a < 10 else '') + str(a)

longest = 0
for i in range(1, n):
    longest = max(longest, to_minutes(times[i]) - to_minutes(times[i - 1]))

longest = max(longest, 60*24 + to_minutes(times[0]) - to_minutes(times[n - 1]))

longest -= 1

hours, minutes = to_hours(longest)


print(pad(hours), ':', pad(minutes), sep='')

def f(x):
	if x < 10:
		return "0" + str(x)
	return str(x)

n = int(input())
times = []
for i in range(0, n):
	s = input()
	times.append(60 * int(s[0:2]) + int(s[3:5]))
	times.append(60 * 24 + 60 * int(s[0:2]) + int(s[3:5]))
times.sort()
ans = times[1] - times[0] - 1
for i in range(1, len(times)):
	ans = max(ans , times[i] - times[i - 1] - 1) 
print("{}:{}".format(f(ans // 60), f(ans % 60)))

n=int(input())
a=[]
for i in range(n):
    h,m=map(int,input().split(':'))
    a+=[h*60+m]
a.sort()
a+=[a[0]+24*60]
ans=-1
for i in range(n):
    ans=max(ans,a[i+1]-a[i]-1)
h,m=ans//60,ans%60
if h<10:
    print(0,end='')
print(h,end=':')
if m<10:
    print(0,end='')
print(m,end='')


b = int(input())
times = []
line = ""
a = b
while a > 0:
    a-=1
    curr_time = input().split(":")
    times.append(int(curr_time[0])*60+int(curr_time[1]))
times.sort()
times.append(times[0]+24*60)
max_delta = 0
if times[0] > max_delta:
    max_delta = times[0]
for it in range(1,b+1):
    if times[it] - times[it - 1] > max_delta:
        max_delta = times[it] - times[it-1] - 1
if max_delta // 60 < 10:
    first = "0"+str(max_delta // 60)
else:
    first = str(max_delta // 60)
if max_delta - 60 * (max_delta // 60) < 10:
    second = "0"+str(max_delta - 60 * (max_delta // 60))
else:
    second = str(max_delta - 60 * (max_delta // 60))
print(first + ":" + second)

def dist(a, b):
    minsa = int(a.split(':')[0]) * 60 + int(a.split(':')[1])
    minsb = int(b.split(':')[0]) * 60 + int(b.split(':')[1])
    return minsb - minsa - 1


def ldist(a, b):
    minsa = (int(a.split(':')[0]) + 24) * 60 + int(a.split(':')[1])
    minsb = int(b.split(':')[0]) * 60 + int(b.split(':')[1])
    return minsa - minsb - 1
    

a = int(input())
x = []
for i in range(a):
    t = input()
    x.append(t)
x = sorted(x)
ans = 0
for i in range(0, len(x) - 1):
    r = dist(x[i], x[i + 1])
    ans = max(r, ans)

ans = max(ans, ldist(x[0], x[len(x) - 1]))
# print(ldist(x[0], x[len(x) - 1]))

h = ans // 60
m = ans - (h * 60)
if (h < 10):
    if (m < 10):
        print("0" + str(h) + ":0" + str(m))
    else:    
        print("0" + str(h) + ":" + str(m))
else:
    if (m < 10):
        print(str(h) + ":0" + str(m))
    else:    
        print(str(h) + ":" + str(m))


n = int(input())
minutes = []
for i in range(n):
    s = input()
    minutes.append(int(s[:-3]) * 60 + int(s[-2:]))
minutes.sort()

max = 0
for i in range(0, n - 1):
    cur = minutes[i + 1] - minutes[i] - 1;
    
    if cur > max:
        max = cur

cur = 24*60 - (minutes[-1] - minutes[0]) - 1
if cur > max:
    max = cur

hours = max // 60
minutes = max - hours * 60

h_str = str(hours)
if len(h_str) < 2:
    h_str = "0" + h_str
    
m_str = str(minutes)
if len(m_str) < 2:
    m_str = "0" + m_str
    
print(h_str+":"+m_str)

n = int(input())

alarms = []

for i in range(n):
    h, m = list(map(int, input().split(':')))
    t = h * 60 + m
    alarms.append(t)
    
alarms.sort()

# print(alarms)
alarms.append(alarms[0] + 24 * 60)
mx = -1
for i in range(1, len(alarms)):
    if (mx < alarms[i] - alarms[i - 1]):
        mx = alarms[i] - alarms[i - 1]
mx -= 1
print('{:02d}:{:02d}'.format(mx // 60, mx % 60))