Problem:
Boring Commercial Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his
only source of entertainment is watching TV. And TV commercial, as usual, are
a big nuisance for him. He can watch any thing on television, but cannot bear
even a single second of commercial. So to prevent himself from the boredom of
seeing the boring commercial, he keeps shuffling through the TV channels, so
that he can watch programs on different channels without seeing even a single
commercial. Given the number of channels, and the duration at which the TV commercials
are showed on each of the channels, you have to write a program which will
print the longest interval for which the lazy student can watch the television by
shuffling between the different channels without ever seeing an TV commercial. For example, consider the simplified situation where there are only three
television channels, and suppose that he is watching TV from 2100 hrs to 2400
hrs. Suppose that the commercials are displayed at following time on each of
the channels.  Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330  Channel 2: 2130 to 2200, 2330 to 2400  Channel 3: 2100 to 2130, 2330 to 2400  Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3
from 2130 to 2330, and then Channel 1 from 2330 to 2400. Input The input will consist of several cases. In each case, the first line of the input
will be n, the number of channels, which will then be followed by p and q, the
time interval between which he will be watching the TV. It will be followed by
2n lines, giving the time slots for each of the channels. For each channel, the
first line will be k, the number of commercial slots, and it will then be followed
by 2k numbers giving the commercial slots in order. The input will be terminated by values 0 for each of n, p, q. This case should
not be processed. Output For each case, you have to output the maximum duration (in minutes) for which
he can watch television without seeing any commercial. Sample Input 1 2100 2400
1
2130 2200
3 2100 2400
3
2100 2130 2200 2230 2300 2330
2
2130 2200 2330 2400
2
2100 2130 2330 2400
0 0 0 Output for the Sample Input 120
180

Solution (Python):
def cv(t):
	return t/100*60+t%100

while 1:
	n,p,q = map(int,raw_input().split())
	if n==0: break
	v=[0]*1440
	for i in range(n):
		k = int(raw_input())
		a = map(int,raw_input().split())
		for j in range(k):
			for l in range(cv(a[::2][j]),cv(a[1::2][j])):
				v[l]+=1
	m=c=0
	for i in range(cv(p),cv(q)):
		c=c+1 if v[i]<n else 0
		m=max(m,c)
	print m

Solution (Python):
def get():
	return map(int,raw_input().split())
def cv(t):
	return t/100*60+t%100
while 1:
	n,p,q=get()
	if n==0: break
	v=[0]*1440
	for i in range(n):
		k=get()[0]; a=get()
		for j in range(k):
			for l in range(cv(a[::2][j]),cv(a[1::2][j])):
				v[l]+=1
	m=c=0
	for i in range(cv(p),cv(q)):
		c=(c+1)*(v[i]<n)
		m=max(m,c)
	print m

Solution (Python):
def tt(o,t):
    om=o%100
    oh=o/100
    tm=t%100
    th=t/100
    return tm-om+(th-oh)*60
    

while(1):
    [c,s,e]=[int(x) for x in raw_input().split()]
    if c==0:
        break
    else:
        cmlist=[]
        timelist=[s]
        state=2**c-1
        oldtime=s
        oldstate=0
        ans=0
        temptv=0
        for i in range(c):
            numofcom=int(raw_input())
            aa=[int(x) for x in raw_input().split()]
            cmlist.append(aa)
            timelist=timelist+aa
        timelist.append(e)
        timelist=sorted(list(set(timelist)))
        for time in timelist:
            for i in range(c):
                if len(cmlist[i])>0:
                    if cmlist[i][0]==time:
                        state=state^(2**i)
                        cmlist[i].pop(0)
            if oldstate!=0:
                temptv=temptv+tt(oldtime,time)
            else:
                ans=max(ans,temptv)
                temptv=0
            oldtime=time
            oldstate=state
            
        ans=max(ans,temptv)
        print ans

Solution (Python):

    

def chang(x):
    h = x / 100
    m= x%100
    return h * 60 + m

while 1:
    (ch,st,en) = map(int, raw_input().split())
    if(ch==0 and st ==0 and en ==0):break
    hours = [0]*(chang(2400)+1)
    for i in range(ch):
        line = raw_input()
        tms = map(int, raw_input().split())
        for ti in tms[0::2]:
            hours[chang(ti)] += 1
            
        for tim in tms[1::2]:
            hours[chang(tim)] -=1
            
    
    spn = 0
    checker = 0
    maxspn = 0
    for t in range(chang(st),chang(en)):
        if(checker < ch and hours[t] + checker >= ch):
            if(spn > maxspn):maxspn = spn
            spn=0
        checker += hours[t]
        if(checker < ch):spn+=1
    if(spn > maxspn):maxspn = spn
    
    print maxspn

Solution (Python):
while True:
    n,s,e = input().split()
    n = int(n)
    s = int(s)
    e = int(e)
    if not n+s+e:
        break
    s = s//100*60+s%100
    e = e//100*60+e%100
    t = [0]*(60*24+1)
    for i in range(n):
        m = int(input())
        g = input().split()
        j = 0
        for o in g:
            a = int(o)
            if j%2:
                t[a//100*60+a%100] += 1
            else:
                t[a//100*60+a%100] -= 1
            j += 1
    cnt = n
    ans = 0
    ma = -1
    for i in range(e):
        cnt += t[i]
        if i < s:
            continue
        if cnt:
            ans += 1
        else:
            if ma < ans:
                ma = ans
            ans = 0
    print(ma if ma > ans else ans)

Solution (Python):



def convert_time(n):
    return (n/100)*60 + n%100


def kyotsu(cm1,cm2):
    result = []
    for i in range(len(cm2)/2):
        
        for j in range(len(cm1)/2):
            stt = max(cm2[i*2],cm1[j*2])
            edt = min(cm2[i*2+1],cm1[j*2+1])
            if edt - stt > 0:
                result.append(stt)
                result.append(edt)

    return result


while 1:
    cond = [int(r) for r in raw_input().split()]
    if cond[0]==cond[1]==cond[2]==0: 
        break

    
    start = convert_time(cond[1])
    end = convert_time(cond[2])

    cms = []
    
    for i in range(cond[0]):
        n = int(raw_input()) 
        input = [convert_time(int(r)) for r in raw_input().split()]
        j=0
        cmstmp = []
        while j < n:
            st = input[2*j]
            ed = input[2*j+1]
            if not i:
                cms.append(st)
                cms.append(ed)
            else:
                cmstmp.append(st)
                cmstmp.append(ed)
            j += 1
        if i > 0:
            cms = kyotsu(cms,cmstmp)


    
    cms = [start] + cms + [end]
    print max([cms[i*2+1]-cms[i*2] for i in range(len(cms)/2)])

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

while True:
    n, p, q = map(int, raw_input().split())
    if n == p == q == 0:
        break
    T = [0 for i in range(2401)]
    for loop in range(n):
        k = input()
        ts = map(int, raw_input().split())
        for i in range(k):
            T[ts[i * 2]] += 1
            T[ts[i * 2 + 1]] -= 1
    cnt = 0
    S = 0
    ans = 0
    for i in range(24):
        for j in range(60):
            t = i * 100 + j
            if p <= t < q:
                cnt += T[t]
                if cnt < n:
                    S += 1
                else:
                    ans = max(ans, S)
                    S = 0
    ans = max(ans, S)
    print ans

Solution (Python):
conv = lambda t: (t // 100)*60 + (t % 100)
while 1:
    N, P, Q = map(int, input().split())
    if N == P == Q == 0:
        break
    P = conv(P); Q = conv(Q)
    CM = [0]*(Q-P+1)
    for i in range(N):
        k = int(input())
        *T, = map(int, input().split())
        for s, t in zip(T[::2], T[1::2]):
            s = conv(s); t = conv(t)
            CM[s-P] += 1
            CM[t-P] -= 1
    cnt = ans = 0
    for i in range(Q-P):
        CM[i+1] += CM[i]
        if CM[i] < N:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, cnt)
    print(ans)

Solution (Python):



import sys
from sys import stdin
input = stdin.readline

def d2t(d):	return (d//100)*60 + (d%100)

while True:
	n, p, q = map(int, input().split())
	if n == 0: break
	tbl = [0]*1500
	p, q = d2t(p), d2t(q)
	for i in range(n):
		k = 2*int(input())
		a = list(map(int, input().split()))
		for j in range(0, k, 2):
			t1, t2 = d2t(a[j]), d2t(a[j+1])
			for t in range(t1, t2): tbl[t] += 1
	ans = k = 0
	for t in range(p, q):
		if tbl[t] < n: k += 1
		elif k > 0: 
			if k > ans: ans = k
			k = 0
	if k > ans: ans = k
	print(ans)