Problem:


Osaki

大崎

English text is not available in this practice contest.

山手線は東京 23 区内に敷設されている環状鉄道路線である．総路線距離は 34.5km であり，1 周にはおよそ 1 時間を要する．駅は全部で 29 駅存在する．ラインカラーはウグイス色である．ピーク時の混雑率は 200% を超え，日本の鉄道路線の中で最も混雑している路線の 1 つである．最も混雑する時間帯では 3 分に 1 本の列車が走っており，東京に初めて来た人々はその光景に驚くものである．

鉄子さんは山手線を愛してやまない生粋の鉄道好きである．ある日，彼女は愛読書である JR 時刻表を読みながら次の疑問に至った．「山手線では一日に何台の車両が使われているのだろう？」

彼女は時刻表から運行に最低限必要な車両の台数を割り出そうとした．しかし，列車の本数が非常に多かったので，彼女一人の力では到底数え切れそうにない．そこで彼女は優秀なプログラマーであるあなたに助けを求めた．

あなたの仕事は与えられた時刻表から山手線の運行に要する車両の最低台数を求めるプログラムを書くことである．山手線は環状路線であることから，その時刻表は便宜上「大崎駅」を始発駅および終着駅として表記されることが多い．そのため，彼女から渡された時刻表にも各列車の大崎駅における発時刻および着時刻のみが記されている．

なお，実際の山手線では起こりえないが，状況設定を簡単にするため，ここでは大崎駅の到着直後に列車が大崎駅を出発可能であると考えることにする．また，鉄子さんが写した時刻に誤りがあったり，鉄子さんの妄想によって勝手に加えられた列車が時刻表に紛れ込んだりしている場合もあるが，あなたはそれらを見抜くことができないので，あくまでも書かれたとおりの時刻に対して台数を求めなければならない．

きちんと動作するプログラムを書けば，彼女が列車内デートに誘ってくれるかもしれない．もっとも，誘いに乗るか断るかはあなた次第であるが．

Input

入力は複数のデータセットから構成される．各データセットは次の形式になっている．

n

hh:mm:ss hh:mm:ss

hh:mm:ss hh:mm:ss

...

hh:mm:ss hh:mm:ss

1 行目の整数 n は時刻表に含まれる列車の本数である．この値は 10,000 を超えないことが保証されている．2 行目から n + 1 行目までの n 行には各列車の大崎駅の発時刻および着時刻がこの順番で与えられ，発時刻と着時刻の間は 1 つの空白で区切られている．各時刻は hh:mm:ss の形式で表現され，hh が時，mm が分，ss が秒を表している．それぞれの値の範囲は 0 ≦ hh < 24, 0 ≦ mm < 60, 0 ≦ ss < 60である．これらの数値は全て 2 桁となるように，必要に応じて先頭に 0 が付け加えられている．

夜の 24:00 をまたいで運行されるような列車は含まれない．したがって，常に発時刻は常に着時刻よりも前の時刻である．

入力の終了は n = 0 によって示される．これはデータセットには含まれない．

Output

各データセットに対して，最低限必要となる車両の台数を 1 行に出力しなさい．

Sample Input

3
05:47:15 09:54:40
12:12:59 12:13:00
16:30:20 21:18:53
6
00:00:00 03:00:00
01:00:00 03:00:00
02:00:00 03:00:00
03:00:00 04:00:00
03:00:00 05:00:00
03:00:00 06:00:00
0
 

Output for the Sample Input

1
3



Sample input:
3
05:47:15 09:54:40
12:12:59 12:13:00
16:30:20 21:18:53
6
00:00:00 03:00:00
01:00:00 03:00:00
02:00:00 03:00:00
03:00:00 04:00:00
03:00:00 05:00:00
03:00:00 06:00:00
0


Sample output:
1
3

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

def conv(l):
    #l.reverse()
    ret = 0
    for e in l:
        ret = ret*60+e
    return ret

while True:
    N = int(sys.stdin.readline())
    if N == 0:
        exit()
    a = tuple(tuple(sys.stdin.readline().split()) for _ in range(N)) # multi line with single param
    a = [[conv(list(map(int,s.split(":")))), conv(list(map(int,e.split(":"))))] for s,e in a]

    N = 24*60*60
    imos = [0]*(N+1)

    for s,e in a:
        imos[s] += 1
        if e < N+1 : imos[e] -= 1

    cur = 0
    ret = 0
    for i in range(N):
        cur = cur + imos[i]
        ret = max(ret,cur)
    print(ret)

Submission status: Accepted

Solution code:
def to_second(t):
  res = 0
  hour,minute,second = t.split(":")
  res += int(hour)*60*60
  res += int(minute)*60
  res += int(second)
  return res

while True:
  N = int(input())
  if N == 0: exit()
  times = [0] * (24*60*60)
  for _ in range(N):
    s,t = map(str,input().split())
    times[to_second(s)] += 1
    times[to_second(t)] -= 1

  for t in range(24*60*60-1):
    times[t+1] += times[t]

  print(max(times))

Submission status: Accepted

Solution code:
import itertools
while True:
    n = int(input())
    if n == 0:
        break
    time = [0]*(60*60*24)
    for _ in range(n):
        h, c = input().split()
        l = 60*60*int(h[0:2]) + 60*int(h[3:5]) + int(h[6:8])
        r = 60*60*int(c[0:2]) + 60*int(c[3:5]) + int(c[6:8])
        time[l] += 1
        time[r] -= 1
    cumsum = list(itertools.accumulate(time))
    print(max(cumsum))

Submission status: Accepted

Solution code:
def second(s):
    return int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
while(1):
    n = int(input())
    if not n:
        break
    a = [0] * 86500
    b = [0] * 86500
    for i in range(n):
        l, r = map(second, input().split())
        a[l+1] += 1
        b[r] += 1

    ans = a[0]
    cur = a[0]

    for i in range(86499):
        cur += a[i+1]-b[i]
        ans = max(ans, cur)

    print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
while 1:
    N = int(input())
    if N==0:
        break
    imos = [0]*24*60*60
    for _ in range(N):
        s, e = input().split()
        S = list(map(int, s.split(':')))
        E = list(map(int, e.split(':')))
        imos[S[0]*60*60+S[1]*60+S[2]] += 1
        imos[E[0]*60*60+E[1]*60+E[2]] -= 1
    IMOS = list(accumulate(imos))
    print(max(IMOS))

Submission status: Accepted

Solution code:
def second(hms):
    h, m, s = map(int, hms.split(':'))
    return h * 60 * 60 + m * 60 + s


while True:
    N = int(input())
    if N == 0:
        break
    trains = [0] * 86400
    for _ in range(N):
        start, end = map(second, input().split(' '))
        trains[start] += 1
        trains[end] -= 1

    for i in range(1, len(trains)):
        trains[i] += trains[i - 1]
    print(max(trains))

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())

while N:
  al = [0]*86400
  for i in range(N):
    l,r = input().split()
    hh,mm,ss = map(int,l.split(":"))
    al[hh*3600+mm*60+ss] += 1
    hh,mm,ss = map(int,r.split(":"))
    al[hh*3600+mm*60+ss] -= 1
  print(max(accumulate(al)))
  N = int(input())

Submission status: Accepted

Solution code:
def sec(m):
  hour = int(m[0:2])
  minute = int(m[3:5])
  second = int(m[6:8])
  s= 60 * 60 * hour + 60 * minute + second
  return s
  
p = 0
while p == 0:
  N = int(input())
  if N == 0:
    p = 1
    quit()
  time = [0] * (86500)
  for i in range(N):
    a, b = map(str, input().split())
    time[sec(a)] += 1
    time[sec(b)] -= 1
  ans = 1
  now = 0
  for i in range(len(time)):
    now += time[i]
    ans = max(ans, now)
  print(ans)

Submission status: Accepted

Solution code:
# 山手線は34.5Km
# 一周一時間かかる
# 駅は29駅ある
import itertools
while True:
    n = int(input())  # n <= 10000
    if n == 0:
        break
    timestamps = [0 for _ in range(24 * 60 * 60 + 1)]
    for _ in range(n):
        start, end = input().split()
        start_h, start_m, start_s = map(int, start.split(":"))
        start_h = start_h * 60 * 60
        start_m = start_m * 60
        start_time = start_h + start_m + start_s
        end_h, end_m, end_s = map(int, end.split(":"))
        end_h = end_h * 60 * 60
        end_m = end_m * 60
        end_time = end_h + end_m + end_s
        timestamps[start_time + 1] += 1
        timestamps[end_time + 1] -= 1
    timestamps = list(itertools.accumulate(timestamps))
    print(max(timestamps))

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0: break
    def to_seconds(s):
        d = 3600
        ret = 0
        for i in s.split(":"):
            ret += d * int(i)
            d //= 60
        return ret

    d = [0] * 90000
    for i in range(N):
        a, b = input().split()
        a, b = to_seconds(a), to_seconds(b)
        d[a] += 1
        d[b] -= 1

    for i in range(1, 90000):
        d[i] += d[i-1]

    print(max(d))

Submission status: Accepted

Solution code:
def solve():
    while True:
        N = int(input())
        if N==0:
            return
        firsts = [0]*(86401)
        lasts = [0]*(86401)
        for i in range(N):
            a,b = input().split()
            h,m,s = a.split(':')
            t = 0
            for i,n in enumerate([h,m,s]):
                if n[0]=='0':
                    n = n[1]
                t += int(n)*60**(2-i)
            firsts[t] += 1
            h,m,s = b.split(':')
            t = 0
            for i,n in enumerate([h,m,s]):
                if n[0]=='0':
                    n = n[1]
                t += int(n)*60**(2-i)
            lasts[t] += 1
        now = 0
        ans = 0
        for f,l in zip(firsts,lasts):
            now += f-l
            ans = max(ans,now)
        print(ans)
solve()

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    l = [0]*(3600*24 + 1)
    for i in range(n):
        s, t = input().split()
        stime = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
        etime = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])
        # print(stime, etime)
        l[stime]+=1
        l[etime]-=1
    for i in range(len(l)-1):
        l[i+1] = l[i] + l[i+1]
    # print(l[0:3700])
    ans = max(l[1:])
    print(ans)

Submission status: Accepted

Solution code:
MAX = 24*60**2 + 60*60 + 60

def datetime2second(datetime):
    hours, minutes, seconds = map(int, datetime.split(':'))

    return hours * 60**2 + minutes * 60 + seconds

while True:
    n = int(input())
    if n == 0: break

    s = [0] * (MAX + 1)
    for i in range(n):
        d, a = map(datetime2second, input().split())

        s[d] += 1
        s[a] -= 1
    
    ans = s[0]
    for i in range(MAX):
        s[i+1] += s[i]
        ans = max(ans, s[i+1])

    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    DP=[0 for _ in range(24*10**4+1)]
    for i in range(n):
        a,b=map(lambda x:int("".join(x.split(":"))),input().split())
        DP[a] +=1
        DP[b] -=1
    for i in range(1,24*10**4+1):
        DP[i]=DP[i]+DP[i-1]
    print(max(DP))

Submission status: Accepted

Solution code:
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    
    def hhmmss_to_s(t):
        hh = int(t[0:2])
        mm = int(t[3:5])
        ss = int(t[6:8])
        return hh*3600+mm*60+ss

    while True:
        n = I()
        if n==0:
            break
        else:
            cnt = [0]*(24*3600+1)
            for _ in range(n):
                leave, arrive = map(hhmmss_to_s, input().split())
                cnt[leave] += 1
                cnt[arrive] -= 1
            for i in range(24*3600):
                cnt[i+1] += cnt[i]

            print(max(cnt))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013
from itertools import accumulate
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    while True:
        n = int(readline())
        if n == 0:
            break

        table = [0] * 87000
        for _ in range(n):
            s_hms, t_hms = readline().split()
            s = int(s_hms[0:2]) * 3600 + int(s_hms[3:5]) * 60 + int(s_hms[6:8])
            t = int(t_hms[0:2]) * 3600 + int(t_hms[3:5]) * 60 + int(t_hms[6:8])

            table[s] += 1
            table[t] -= 1
        
        A = accumulate(table)
        ans = max(list(A))
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if not n: break
    cnt = [0]*(60**3+1)
    for i in range(n):
        dep,arr = input().split()
        h,m,s = map(int,dep.split(":"))
        cnt[h*3600+m*60+s] += 1
        h,m,s = map(int,arr.split(":"))
        cnt[h*3600+m*60+s] -= 1
    for i in range(1,60**3+1): cnt[i] += cnt[i-1]
    print(max(cnt))

Submission status: Accepted

Solution code:
import sys


# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

# ===CODE===
def main():
    while True:
        n = int(input())
        if n == 0:
            exit(0)

        d = [[[0 for i in range(60)] for j in range(60)] for k in range(24)]

        for _ in range(n):
            a, b = input().split()
            a_h, a_m, a_s = a.split(":")
            b_h,b_m,b_s = b.split(":")
            d[int(a_h)][int(a_m)][int(a_s)] += 1
            d[int(b_h)][int(b_m)][int(b_s)] -= 1

        ans = 0
        tmp_ans = 0
        for i in range(24):
            for j in range(60):
                for k in range(60):
                    tmp_ans += d[i][j][k]
                    ans = max(ans, tmp_ans)

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

while True:
    N = int(input())
    if N==0:
        exit()

    MAX_T = 24*3600+10
    S = [0]*MAX_T
    for _ in range(N):
        start, end = input().split()
        a, b,c = map(int, start.split(":"))
        d,e,f  = map(int, end.split(":"))
        # imos
        S[a*3600+b*60+c] += 1
        S[d*3600+e*60+f] -= 1

        # cumsum
    for i in range(MAX_T-1):
        S[i+1] += S[i]
    print(max(S))

Submission status: Accepted

Solution code:
def cvtTime(s):
    h, m, s = map(int, s.split(":"))
    return h * 60 * 60 + m * 60 + s


while True:
    n = int(input())
    if n == 0:
        break

    cnt = [0] * (60 * 60 * 24 + 2)

    for i in range(n):
        begin, end = input().split()
        begin_time = cvtTime(begin)
        end_time = cvtTime(end)

        cnt[begin_time] += 1
        cnt[end_time] -= 1

    for i in range(1, len(cnt)):
        cnt[i] += cnt[i - 1]

    print(max(cnt))

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    def index_from_timer(time):
        hour=int(time[:2])
        minute=int(time[3:5])
        second=int(time[6:8])
        return hour*3600+minute*60+second

    while 1:
        n=int(input())
        if n==0:
            break
        timer=[input() for i in range(n)]
        A=[0 for _ in range(86400)]
        for time in timer:
            start=time[:8]
            end=time[9:]
            A[index_from_timer(start)]+=1
            A[index_from_timer(end)]-=1
        print(max(list(accumulate(A))))
main()

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
        
    ta = [0] * 86400
    for _ in range(n):
        a,b = input().split()
        c,cc,ccc = int(a[0:2]),int(a[3:5]),int(a[6:8])
        d,dd,ddd = int(b[0:2]),int(b[3:5]),int(b[6:8])
        ta[c*3600+cc*60+ccc] += 1
        ta[d*3600+dd*60+ddd] -= 1

    for i in range(86400):
        if 0 < i:
            ta[i] += ta[i-1]

    ans = 0
    for i in range(86400):
        if ans < ta[i]:
            ans = ta[i]

    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n==0:
        break
    ab = [list(input().split()) for _ in range(n)]
    
    T = [0] * (3600*24)
    
    for i in range(n):
        a, b = ab[i]
        a_h, a_m, a_s = map(int, a.split(':'))
        b_h, b_m, b_s = map(int, b.split(':'))
        a_time = a_h*3600 + a_m*60 + a_s
        b_time = b_h*3600 + b_m*60 + b_s
        T[a_time] += 1
        T[b_time] -= 1
        
    for i in range(1, len(T)):
        T[i] += T[i-1]
    
    print(max(T))

Submission status: Accepted

Solution code:
def seconds(a):
    hour,minute,second=a.split(":")
    hour,minute,second=int(hour),int(minute),int(second)
    return(3600*hour+60*minute+second)

from itertools import accumulate
while True:
    n=int(input())
    if n==0:
        exit()
    memo=[0]*86401
    for i in range(n):
        l,r=input().split()
        l=seconds(l)
        r=seconds(r)
        memo[l+1]+=1
        if r!=86400:
            memo[r+1]-=1
    ac=list(accumulate(memo))
    print(max(ac))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate

def time_to_int(x):
    time = ""
    for ch in x:
        if ch == ":":
            continue
        time += ch
    return int(time)

while True:
    n = int(input())

    if n == 0:
        exit()
    data = [0] * (10**6) 

    for i in range(n):
        s,e = input().split()
        int_s = time_to_int(s)
        int_e = time_to_int(e)

        data[int_s] += 1
        data[int_e] -= 1
    data = [0] + data
    cum_data = list(accumulate(data))

    print(max(cum_data))

Submission status: Accepted

Solution code:
def t2s(t):
    h = t[:2]
    m = t[3:5]
    s = t[6:]
    return int(h)*3600+int(m)*60+int(s)



while (True):
    n = int(input())
    c = [0 for i in range(24*3600+1)]
    if (n == 0):
        break
    for i in range(n):
        tt = input()
        c[t2s(tt[:8])] += 1
        c[t2s(tt[9:])] -= 1
    cc = [0]
    for i in range(len(c)):
        cc.append(cc[-1] + c[i])
    print(max(cc))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    while 1:
        n = I()
        if n == 0:
            break
        m = 24*60**2
        a = [0]*m
        for i in range(n):
            l,r = input().split()
            l = list(map(int, l.split(":")))
            r = list(map(int, r.split(":")))
            l = l[2]+60*(l[1]+60*(l[0]))
            r = r[2]+60*(r[1]+60*(r[0]))
            a[l] += 1
            a[r] -= 1
        for i in range(m-1):
            a[i+1] += a[i]
        print(max(a))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:

while True:
    N = int(input())
    if N == 0: break

    s = []
    for _ in range(N):
        d,a = input().split()
        s.append((d,1))
        s.append((a,-1))
    s.sort()
    s.append(('END',0))
    ans = 0
    cnt = 0
    bt = ''
    for t,c in s:
        if bt != t: ans = max(ans,cnt)
        cnt += c
        bt = t
    print (ans)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

for _ in range(10 ** 9):
    n = int(input())
    if n == 0:
        break
    hs = [0 for _ in range(24 * 60 * 60 + 2)]
    for i in range(n):
        start, end = map(str, input().split())
        start = [int(start[0:2]), int(start[3:5]), int(start[6:8])]
        end = [int(end[0:2]), int(end[3:5]), int(end[6:8])]
        hs[start[0] * 60 * 60 + start[1] * 60 + start[2]] -= 1
        hs[end[0] * 60 * 60 + end[1] * 60 + end[2]] += 1
    hs = list(itertools.accumulate(hs))
    print(abs(min(hs)))

Submission status: Accepted

Solution code:
from itertools import accumulate
import operator
while True:
    L = [0] * 86401
    num = int(input())
    if num == 0:
        break

    for _ in range(num):
        s, t = input().split()
        hh, mm, ss = [int(x) for x in s.split(":")]
        s  = 3600 * hh + 60 * mm + ss
        hh, mm, ss = [int(x) for x in t.split(":")]
        t = 3600 * hh + 60 * mm + ss
        L[s] +=1
        L[t] -=1

    S = accumulate(L, operator.add)
    print(max(S))

Submission status: Accepted

Solution code:

while(1):
 num = 100009
 time = [0]*num

 n = int(input())
 if(n == 0): break

 for i in range(n):
  t = list(input().split())
  a_,b_ = t[0].split(':'),t[1].split(':')
  a = int(a_[0])*3600+int(a_[1])*60+int(a_[2])
  b = int(b_[0])*3600+int(b_[1])*60+int(b_[2]) -1
  #print(a)
  #print(b)

  time[a] += 1
  time[b+1] -= 1

 ans = 1
 for i in range(num):
  if(i != 0): time[i] += time[i-1]
  ans = max(ans,time[i])
 print(ans)

Submission status: Accepted

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def calc(t):
    h,m,s = map(int,t.split(':'))
    return (h*60+m)*60+s


while True:
    n = inp()
    if n == 0:
        break
    else:
        imos = [0]*(60*60*24+5)
        for _ in range(n):
            ts,tt = input().split()
            ts = calc(ts)
            tt = calc(tt)
            imos[ts] += 1
            imos[tt] -= 1

        tmp = 0
        for i in range(60*60*24+5):
            tmp += imos[i]
            imos[i] = tmp
        print(max(imos))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import accumulate

T = 86400


def sec(a):
    return 3600 * a[0] + 60 * a[1] + a[2]


while True:
    n = int(input())
    if n == 0:
        exit()
    imos = [0] * T
    for _ in range(n):
        s, t = map(lambda x: list(map(int, x.split(':'))), input().split())
        imos[sec(s)] += 1
        imos[sec(t)] -= 1
    imos = list(accumulate(imos))
    print(max(imos))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    
    trains = []
    for _ in range(n):
        dept, ariv = input().split()
        trains.append((dept, ariv))
    trains.sort(key=lambda x:x[0])
    dcheck = 0
    usecar = 0
    returntime = []
    for tridx in range(len(trains)):
        new = True
        for ariv in returntime:
            if ariv <= trains[tridx][0]:
                new = False
                returntime.remove(ariv)
                break
        if new: usecar += 1
        returntime.append(trains[tridx][1])
    print(usecar)

Submission status: Accepted

Solution code:
from datetime import datetime
ts = '%H:%M:%S'
while(True):
    n = int(input())
    if n == 0:
        break
    ipt = [None]*n
    for i in range(len(ipt)):
        ipt[i] = list(map(lambda x: datetime.strptime(x,ts),input().split()))
    ipt = sorted(ipt)
    l = [datetime.strptime('00:00:00',ts)]
    for i in range(len(ipt)):
        for j in range(len(l)):
            if l[j] <= ipt[i][0]:
                l[j] = ipt[i][1]
                break
        else:
            l.append(ipt[i][1])
    print(len(l))

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    ans=0
    k=0
    l1=[]
    l2=[]
    for i in range(n):
        a=input()
        l1.append(int(3600*int(a[0:2])+60*int(a[3:5])+int(a[6:8])))
        l2.append(int(3600*int(a[9:11])+60*int(a[12:14])+int(a[15:17])))
    l1.sort()
    l2.sort()
    for t in l1:
        while t>=l2[0]:
            k+=1
            l2.pop(0)
        if k==0:
            ans+=1
        else:
            k-=1
    print(ans)

Submission status: Accepted

Solution code:
while(1):
    n = int(input())
    if n==0: break
    table = [0 for i in range(24*60*60)]
    for i in range(n):
        s,g=input().split()
        s=list(map(int,s.split(':')))
        x=(s[0]*60+s[1])*60+s[2]
        g=list(map(int,g.split(':')))
        y=(g[0]*60+g[1])*60+g[2]
        table[x]+=1
        table[y]-=1
    ret=table[0]
    for i in range(1,24*60*60):
        table[i]+=table[i-1]
        ret=max(ret,table[i])
    print(ret)

Submission status: Accepted

Solution code:
from itertools import accumulate

while True:
  n = int(input())
  if n == 0:
    break

  def to_sec(time):
    h, m, s = map(int, time.split(":"))
    return 3600 * h + 60 * m + s
  section = [0] * (60 * 60 * 24)
  for _ in range(n):
    t1, t2 = map(to_sec, input().split())
    section[t1] += 1
    section[t2] -= 1

  section_acc = accumulate(section)
  print(max(section_acc))

Submission status: Accepted

Solution code:
from itertools import accumulate
while 1:
    n=int(input())
    if n==0:
        break
    timeline=[0 for i in range(86401)]
    for i in range(n):
        a,b=input().split()
        a=list(map(int,a.split(':')))
        b=list(map(int,b.split(':')))
        a=a[0]*3600+a[1]*60+a[2]
        b=b[0]*3600+b[1]*60+b[2]
        timeline[a]+=1
        timeline[b]-=1
    print(max(accumulate(timeline)))

Submission status: Runtime Error

Solution code:
def to_sec(a):
    h,m,s = map(int,a.split(":"))
    return 3600*h+60*m+s

while 1:
    n = int(raw_input())
    if n == 0: break
    used = [0]*84401
    for loop in range(n):
        a,b = raw_input().split()
        a,b = to_sec(a),to_sec(b)
        used[a] += 1
        used[b] -= 1
    for i in range(1,84400):
        used[i] += used[i-1]
    print max(used)

Submission status: Runtime Error

Solution code:
m=24*60*60
while True:
	n=int(input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=input().split()
		a,b,c=map(int,a.split(':'));
		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
	for i in range(m):
		dp[i+1]+=dp[i]
	print(max(dp))

Submission status: Runtime Error

Solution code:
m=24*60*60
while True:
	n=int(input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=input().split()
#		a,b,c=map(int,a.split(':'));
#		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
	for i in range(m):
		dp[i+1]+=dp[i]
	print(max(dp))

Submission status: Runtime Error

Solution code:
m=24*60*60
while True:
	n=int(input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=input().split()
#		a,b,c=map(int,a.split(':'));
#		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
#	for i in range(m):
#		dp[i+1]+=dp[i]
#	print(max(dp))

Submission status: Runtime Error

Solution code:
m=24*60*60
while True:
	n=int(input())
	if n==0:break
#	dp=[0]*(m+1)
	for _ in range(n):
		a,d=input().split()
#		a,b,c=map(int,a.split(':'));
#		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
#	for i in range(m):
#		dp[i+1]+=dp[i]
#	print(max(dp))

Submission status: Runtime Error

Solution code:
m=24*60*60
while True:
	n=int(input())
	if n==0:break
#	dp=[0]*(m+1)
#	for _ in range(n):
#		a,d=input().split()
#		a,b,c=map(int,a.split(':'));
#		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
#	for i in range(m):
#		dp[i+1]+=dp[i]
#	print(max(dp))

Submission status: Runtime Error

Solution code:
while 1:
    n = int(raw_input())
    if not n: break
    cnt = 1
    t = [0 for i in xrange(24*60*60)]
    for i in xrange(n):
        a = raw_input().split()
        h,m,s = [0,0],[0,0],[0,0]
        for i in xrange(2):
            h[i],m[i],s[i] = map(int, a[i].split(':'))
        t1 = h[0]*60**2 + m[0]*60 + s[0]
        t2 = h[1]*60**2 + m[1]*60 + s[1]
        for i in xrange(t1,t2):
            t[i] += 1

    for i in xrange(24*60*60):
        cnt = max(t[i], cnt)

    print cnt