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: Wrong Answer

Solution code:
def hms2s (t):
	l = map(int,t.split(":"))
	return l[0]*3600 + l[1]*60 + l[0]
while 1:
	n = int(raw_input())
	if n == 0:
		break
	time_table = []
	for i in range(n):
		t = raw_input().split(" ")
		time_table.append([hms2s(t[0]),True])
		time_table.append([hms2s(t[1]),False])
	time_table.sort()
	max_num = 0
	move_num = 0
	for t in time_table:
		if t[1]:
			move_num += 1
			max_num = max(max_num, move_num)
		else:
			move_num -= 1
	print max_num

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            log = [0 for _ in xrange(24 * 60 * 60 + 1)]
            for i in range(n):
                dept, arr = raw_input().split()
                dept = dept.split(':')
                arr = arr.split(':')
                dept = 24 * 60 * int(dept[0]) + 60 * int(dept[1]) + int(dept[2])
                arr = 24 * 60 * int(arr[0]) + 60 * int(arr[1]) + int(arr[2])
                log[dept+1] += 1
                log[arr+1] -= 1
            for i in range(len(log)-1):
                log[i+1] += log[i]
            print max(log)
            
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            log = [0 for _ in xrange(24 * 60 * 60)]
            for i in range(n):
                dept, arr = raw_input().split()
                dept = dept.split(':')
                arr = arr.split(':')
                dept = 24 * 60 * int(dept[0]) + 60 * int(dept[1]) + int(dept[2])
                arr = 24 * 60 * int(arr[0]) + 60 * int(arr[1]) + int(arr[2])
                log[dept+1] += 1
                log[arr+1] -= 1
            for i in range(len(log)-1):
                log[i+1] += log[i]
            print max(log)
            
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-
import re
import heapq

while 1:
    n = int(raw_input())
    if n==0:break
    q = []
    Max = 0
    for i in range(n):
        t = map(int, re.split(r'\s|:', raw_input()))
        lev = t[0]*24*60+t[1]*60+t[2]
        get = t[3]*24*60+t[4]*60+t[5]
        while len(q) > 0:
            top = heapq.heappop(q)
            if top > lev:
                heapq.heappush(q, top)
                break
        heapq.heappush(q, get)
        if Max < len(q):
            Max = len(q)
    print Max

Submission status: Wrong Answer

Solution code:
def time_to_i(s):
    tt = list(map(int, s.split(':')))
    return tt[0] * 3600 + tt[1] * 60 + tt[2]

while True:
    n = int(input())
    if n == 0: break
    tmp = []
    for i in range(n):
        tmp.append(input().split())
    table = []
    for t in tmp:
        table.append((time_to_i(t[0]), 0))
        table.append((time_to_i(t[1]), 1))
    table.sort(key=lambda x:x[0])
    trains = 1
    for t in table:
        if t[1] == 0:
            if trains > 0:
                trains -= 1
        else:
            trains += 1
    print(trains)

Submission status: Wrong Answer

Solution code:
while True:
    n = input()
    if not n: break 
    time = [0]*86400
    for i in range(n):
        s, t = raw_input().split()
        ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
        tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])
        time[ssec] += 1
        time[tsec] -= 1
    ans = time[0]
    for i in range(43200-1):
        time[i+1] += time[i]
        ans = max(ans, time[i+1])
    print ans

Submission status: Wrong Answer

Solution code:
while True:
    n = input()
    if not n: break 
    time = [0]*86400
    for i in range(n):
        s, t = raw_input().split()
        ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
        tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])
        time[ssec] += 1
        time[tsec] -= 1
    ans = time[0]
    for i in range(43200-1):
        time[i+1] += time[i]
        ans = max(ans, time[i+1])
    print ans

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    times = [[0] * 2 for i in range(n)]
    for i in range(n):
        l, a = input().split()
        lh, lm, ls = map(int, l.split(":"))
        ah, am, ass = map(int, a.split(":"))
        times[i][0] = lh * 3600 + lm * 60 + ls
        times[i][1] = ah * 3600 + am * 60 + ass
    times.sort(key = lambda x:x[1])
    ans = 0
    arrive = 60 * 60 * 24
    for i in range(n):
        if times[i][0] < arrive:
            arrive = times[i][1]
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    times = [[0] * 2 for i in range(n)]
    for i in range(n):
        l, a = input().split()
        lh, lm, ls = map(int, l.split(":"))
        ah, am, ass = map(int, a.split(":"))
        times[i][0] = lh * 3600 + lm * 60 + ls
        times[i][1] = ah * 3600 + am * 60 + ass
    times.sort(key=lambda x: x[1])
    ans = 1
    arrive = times[0][1]
    idx = 1
    for i in range(1, n):
        if times[idx][1] < arrive:
            arrive = times[idx][1]
            idx += 1
        if times[i][0] < arrive:
            arrive = times[i][1]
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
def tosec(t):
    return int(t[:2])*60*60 + int(t[3:5])*60 + int(t[6:])

while True:
    n = int(input())
    if n == 0: break
    time = [0] * (60*60*24 + 1)

    for _ in range(n):
        s, f = input().split()
        time[tosec(s)] += 1
        time[tosec(f)] -= 1

    ans = time[0]
    for i in range(60*60*24):
        time[i+1] += time[i]
        ans = max(ans, time[i+1])

    print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter 
def hms2s (t):
	l = t.split(":")
	return sum([0 if l[i] == "" else int(l[i]) * (60**(2-i)) for i in range(3)])
while 1:
	n = int(raw_input())
	if n == 0:
		break
	time_table = []
	for i in range(n):
		t = raw_input().split(" ")
		time_table.append([hms2s(t[0]),1])
		time_table.append([hms2s(t[1]),0])
	time_table.sort(key=itemgetter(0,1))
	max_num = 0
	move_num = 0
	for t in time_table:
		if t[1]:
			move_num += 1
			max_num = max(max_num, move_num)
		else:
			move_num -= 1
	print max_num

Submission status: Accepted

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]*86401
    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,86401):
        used[i] += used[i-1]
    print max(used)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            log = [0 for _ in xrange(24 * 60 * 60 + 1)]
            for i in range(n):
                dept, arr = raw_input().split()
                dept = dept.split(':')
                arr = arr.split(':')
                dept = 60 * 60 * int(dept[0]) + 60 * int(dept[1]) + int(dept[2])
                arr = 60 * 60 * int(arr[0]) + 60 * int(arr[1]) + int(arr[2])
                log[dept+1] += 1
                log[arr+1] -= 1
            # print log[:100]
            # print log[1801]
            for i in range(len(log)-1):
                log[i+1] += log[i]
            # print log[:100]
            # print log[1801]
            print max(log)
            
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N == 0:
        break
    schedule = [0 for i in range(24*60*60)]
    for i in range(N):
        s,e = map(lambda x:list(map(int,x.split(':'))),input().split())
        schedule[s[0]*60*60+s[1]*60+s[2]] += 1
        schedule[e[0]*60*60+e[1]*60+e[2]] -= 1
    for i in range(1,24*60*60):
        schedule[i] += schedule[i-1]
    print(max(schedule))

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-
import re
import heapq

while 1:
    n = int(raw_input())
    if n==0:break
    q = []
    lg = []
    Max = 0
    for i in range(n):
        t = map(int, re.split(r'\s|:', raw_input()))
        lg.append([t[0]*60*60+t[1]*60+t[2], t[3]*60*60+t[4]*60+t[5]])
    lg.sort()
    for i in range(n):
        while len(q) > 0:
            top = heapq.heappop(q)
            if top > lg[i][0]:
                heapq.heappush(q, top)
                break
        heapq.heappush(q, lg[i][1])
        if Max < len(q):
            Max = len(q)
    print Max

Submission status: Accepted

Solution code:
def time_to_i(s):
    tt = list(map(int, s.split(':')))
    return tt[0] * 3600 + tt[1] * 60 + tt[2]

while True:
    n = int(input())
    if n == 0: break
    tmp = []
    for i in range(n):
        tmp.append(input().split())
    table = []
    for t in tmp:
        table.append((time_to_i(t[0]), 1)) # 1: departure, 0: arrival
        table.append((time_to_i(t[1]), 0))
    table.sort(key=lambda x:(x[0], x[1]))
    trains = 1
    for t in table:
        if t[1] == 1:
            if trains > 0:
                trains -= 1
        else:
            trains += 1
    print(trains)

Submission status: Accepted

Solution code:
def hms2s (t):
	l = t.split(":")
	return sum([0 if l[i] == "" else int(l[i]) * (60**(2-i)) for i in range(3)])
while 1:
	n = int(raw_input())
	if n == 0: break
	train = []
	for i in range(n):
		inputs = raw_input().split(" ")
		train.append((hms2s(inputs[0]),1))
		train.append((hms2s(inputs[1]),0))
	train.sort(key = lambda x : (x[0],x[1]))
	moving = 0
	max_move = 0
	for t in train:
		if t[1]:
			moving += 1
			max_move = max(moving, max_move)
		else:
			moving -= 1
	print max_move

Submission status: Accepted

Solution code:
while True:
    n = input()
    if not n: break 
    time = [0]*86400
    for i in range(n):
        s, t = raw_input().split()
        ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
        tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])
        time[ssec] += 1
        time[tsec] -= 1
    ans = time[0]
    for i in range(86400-1):
        time[i+1] += time[i]
        ans = max(ans, time[i+1])
    print ans

Submission status: Accepted

Solution code:
def f(s):
    return (s[0]*60+s[1])*60+s[2]
a=86401
while 1:
    t=[0]*a
    n=int(input())
    if n==0:break
    for _ in range(n):
        b,c=input().split()
        b,c=list(map(int,b.split(':'))),list(map(int,c.split(':')))
        t[f(b)]+=1;t[f(c)]-=1
    d=0
    for i in range(1,a):
        t[i]+=t[i-1]
        d=max(d,t[i])
    print(d)

Submission status: Accepted

Solution code:
def f(s):
    s=list(map(int,s.split(':')))
    return (s[0]*60+s[1])*60+s[2]
a=86401
while 1:
    t=[0]*a
    n=int(input())
    if n==0:break
    for _ in range(n):
        b,c=input().split()
        t[f(b)]+=1;t[f(c)]-=1
    d=0
    for i in range(1,a):
        t[i]+=t[i-1]
        d=max(d,t[i])
    print(d)

Submission status: Accepted

Solution code:
def f(s):
    return (s[0]*60+s[1])*60+s[2]
a=86400
while 1:
    t=[0]*a
    n=int(input())
    if n==0:break
    for _ in range(n):
        b,c = map(lambda x:list(map(int,x.split(':'))),input().split())
        t[f(b)]+=1;t[f(c)]-=1
    d=0
    for i in range(1,a):
        t[i]+=t[i-1]
        if d<t[i]:d=t[i]
    print(d)

Submission status: Accepted

Solution code:
from itertools import accumulate


def get_second(time_str):
    return int(time_str[:2]) * 3600 + int(time_str[3:5]) * 60 + int(time_str[6:])


while True:
    n = int(input())
    if n == 0:
        break
    cnt = [0] * 86400
    for _ in range(n):
        dep_str, arr_str = input().strip().split()
        dep, arr = get_second(dep_str), get_second(arr_str)
        cnt[dep] += 1
        cnt[arr] -= 1
    print(max(accumulate(cnt)))

Submission status: Accepted

Solution code:
from itertools import accumulate


def get_sec(s):
    return sum(t * c for t, c in zip(map(int, s.split(':')), (3600, 60, 1)))

while True:
    n = int(input())
    if n == 0:
        break
    cnt = [0] * 86400
    for _ in range(n):
        dep, arr = map(get_sec, input().split())
        cnt[dep] += 1
        cnt[arr] -= 1
    print(max(accumulate(cnt)))

Submission status: Accepted

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: Accepted

Solution code:
m=24*60*60
while True:
	n=int(raw_input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=raw_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: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0: break
    times = []
    for i in range(N):
        a,b = input().split()
        at = int(''.join(a.split(':')))
        bt = int(''.join(b.split(':')))
        times.append((at,1))
        times.append((bt,-1))
    ans = n = 0
    for t,d in sorted(times):
        n += d
        ans = max(ans,n)
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break

        a = [LS() for _ in range(n)]
        b = []
        for s,e in a:
            b.append((s,1))
            b.append((e,-1))
        b.sort()
        r = c = 0
        for t,f in b:
            c += f
            if r < c:
                r = c

        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
while 1:
    n = int(raw_input())
    if not n: break
    cnt = 0
    m = cnt
    t = []
    for i in xrange(n):
        a = raw_input().split()
        t.append((a[0],2))
        t.append((a[1],1))
    t.sort()
    for i in xrange(len(t)):
        #print t[i]
        if t[i][1] is 2: cnt += 1
        else: cnt -= 1

        m = max(m, cnt)

    print m

Submission status: Accepted

Solution code:
import sys
import math

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    time = []
    for z in xrange(n):
        start, end = map(int, raw_input().replace(':', '').split())
        time.append((end, start))
    time.sort()
    train = [0]
    for end, start in time:
        for i in xrange(len(train)):
            if train[i] <= start:
                train[i] = end
                break
        else:
            train.append(end)
        train.sort(reverse=True)
    print len(train)

Submission status: Accepted

Solution code:
while True:
    N=input()
    if N==0:break
    L=[]
    for i in range(N):
        a,b=raw_input().split()
        L.append((a,1))
        L.append((b,-1))
    L.sort()
    maxInt=temp=0
    for i in range(2*N):
        if L[i][1]==1:
            temp+=1
        else:
            temp-=1
        maxInt=max(maxInt,temp)
    print maxInt

Submission status: Accepted

Solution code:
import re

while True:
    n = int(raw_input())
    if n == 0:
        break
    l = [0] * (24*60*60+1)
    for _ in range(n):
        h1,m1,s1,h2,m2,s2 = map(int, re.split(':| ', raw_input()))
        l[h1*60*60 + m1*60 + s1] += 1
        l[h2*60*60 + m2*60 + s2] -= 1
    r = 0
    for i in range(24*60*60):
        l[i+1] += l[i]
        r = max(r, l[i+1])
    print r

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    l = []
    for _ in range(n):
        hms1, hms2 = raw_input().split()
        l.append((hms1, True))
        l.append((hms2, False))
    l.sort()
    r, t = 0, 0
    for i in range(len(l)):
        if l[i][1]:
            t += 1
        else:
            t -= 1
        r = max(r, t)
    print r

Submission status: Accepted

Solution code:
class Event:
    def __init__(self, name_, type_, time_):
        self.time = time_
        self.etype = type_
        self.name = name_
    def __lt__(self, other):
        if self.time != other.time:
            return self.time < other.time
        if self.etype != other.etype:
            return self.etype > other.etype
        return self.time < other.time
    def __str__(self):
        return '{0} {1} {2}'.format(
            self.name, self.etype, self.time)

while 1:
    n = input()
    if n==0 : break

    evs = [0]*2*n
    for i in range(n):
        la = raw_input().split(' ')
        for j in range(2):
            t = map(int,la[j].split(':'))
            t = (t[0]*60+t[1])*60+t[2]
            evs[i*2+j] = Event(i, j, t)
    evs.sort()

    ans = 0
    cur = 0
    for i in evs:
        if i.etype == 0:
            cur+=1
            ans = max(cur, ans)
        else:
            cur-=1
        # print i
    print ans

Submission status: Accepted

Solution code:
class Event:
    def __init__(self, type_, time_):
        self.time = time_
        self.etype = type_
    def __lt__(self, other):
        if self.time != other.time:
            return self.time < other.time
        if self.etype != other.etype:
            return self.etype > other.etype
        return self.time < other.time

while 1:
    n = input()
    if n==0 : break

    evs = [0]*2*n
    for i in range(n):
        la = raw_input().split(' ')
        for j in range(2):
            t = map(int,la[j].split(':'))
            t = (t[0]*60+t[1])*60+t[2]
            evs[i*2+j] = Event(j, t)
    evs.sort()

    ans, cur = 0, 0
    for i in evs:
        if i.etype == 0:
            cur+=1
            ans = max(cur, ans)
        else:
            cur-=1
        # print i
    print ans

Submission status: Accepted

Solution code:
def solve(n):
    events = []
    for _ in range(n):
        a, b = input().split()
        events.append((a, 1))
        events.append((b, -1))
    events.append(('99:99:99', 0))
    events.sort(key=lambda event: event[0])
    ans = 0
    tmp = 0
    prev = None
    for e, d in events:
        if prev != e:
            ans = max(ans, tmp)
        tmp += d
        prev = e
    print(ans)

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

Submission status: Accepted

Solution code:
def time_to_int(t):
    hh, mm, ss = map(int, t.split(':'))
    return hh*3600 + mm*60 + ss

from itertools import accumulate
def solve(n):
    res = [0]*(24*3600+1)
    for _ in range(n):
        s, t = map(time_to_int, input().split())
        res[s] += 1
        res[t] -= 1
    
    ress = accumulate(res)
    print(max(ress))

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

Submission status: Accepted

Solution code:
from itertools import accumulate
HR_IN_DAY = 24; MIN_IN_HR = 60;  SEC_IN_MIN = 60

while True:
    n = int(input())
    if n == 0: break
    train = [0] * HR_IN_DAY * MIN_IN_HR * SEC_IN_MIN
    for i in range(n):
        depart, arrive = [t.split(':') for t in input().split(' ')]
        d_hr, d_min, d_sec = map(int, depart)
        a_hr, a_min, a_sec = map(int, arrive)
        train[d_hr * MIN_IN_HR * SEC_IN_MIN + d_min * SEC_IN_MIN + d_sec] += 1
        train[a_hr * MIN_IN_HR * SEC_IN_MIN + a_min * SEC_IN_MIN + a_sec] -= 1

    train = accumulate(train)
    print(max(train))

Submission status: Accepted

Solution code:

import itertools

ft=24*60*60
while True:
    n=int(input())
    if n==0:
        break
    c=[0]*(ft+1)
    for i in range(n):
        t1,t2=input().split()
        tt1=(int(t1[0:2])*60+int(t1[3:5]))*60+int(t1[6:8])
        tt2=(int(t2[0:2])*60+int(t2[3:5]))*60+int(t2[6:8])
        c[tt1]+=1
        c[tt2]-=1
    cc = itertools.accumulate(c)
    cc=list(cc)
    print(max(cc[:ft+1]))

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013

from itertools import accumulate

def getsec(s):
    # hh:mm:ss 23:59:59までかな 23*3600+59*60+59=86399
    h, m, s = map(int, s.split(":"))
    return h * 3600 + m * 60 + s

def solve(n):
    A = [0] * 90000
    for _ in range(n):
        ai, bi = input().split()
        ai, bi = getsec(ai), getsec(bi)
        A[ai] += 1
        A[bi] -= 1
    
    cA = accumulate(A)
    print(max(cA))


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

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/problems/2013


def to_my_time_unit(time_str: str):
    hour, minute, second = map(int, time_str.split(sep=':'))
    return int(hour) * 60*60 + int(minute) * 60 + int(second)


def solve(n):
    A = [0 for _ in range(24 * 60 * 60+1)]
    for _ in range(n):
        start_str, end_str = input().split()
        start = to_my_time_unit(start_str)
        end = to_my_time_unit(end_str)
        A[start] += 1
        A[end] -= 1
    B = [0 for _ in range(24 * 60 * 60+1)]
    tmp = 0
    for i in range(24 * 60 * 60+1):
        tmp += A[i]
        B[i] = tmp
    print(max(B))


if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        solve(n)

Submission status: Accepted

Solution code:
def time_to_sec(time):
    sec = int(time[0:2])*3600
    sec = sec + int(time[3:5])*60
    sec = sec + int(time[6:8])
    return sec


while True:
    timeline = [0] * 86400
    num = int(input())
    if num == 0:
        break
    for i in range(num):
        start,end = input().split()
        start = time_to_sec(start)
        end = time_to_sec(end)
        timeline[start] = timeline[start]+1 
        timeline[end] = timeline[end]-1
    for i in range(1,86400):
        timeline[i] = timeline[i] + timeline[i-1]

    print(max(timeline))

Submission status: Accepted

Solution code:
for i in range(10**6):
    N=int(input())
    if N==0:
        exit()
    D={}
    for j in range(N):
        s,g=input().split()
        S=s.split(":")
        G=g.split(":")
        ST=int(S[0])*60*60+int(S[1])*60+int(S[2])
        GT=int(G[0])*60*60+int(G[1])*60+int(G[2])
        if ST not in D:
            D[ST]=1
        else:
            D[ST]+=1
        if GT not in D:
            D[GT]=-1
        else:
            D[GT]-=1
    LD=list(D.items())    
    LD.sort()
    MAX=0
    cnt=0
    for t,c in LD:
        cnt+=c
        if MAX<cnt:
            MAX=cnt
    print(MAX)
    #print(LR)

Submission status: Accepted

Solution code:
import sys


def culc(time):
    h=int(time[:2])
    m=int(time[3:5])
    s=int(time[6:8])

    return 3600*h+60*m+s


R=60*60*24
while True:
    n=int(input())
    if n==0:
        sys.exit()
    
    L=[0]*(R+1)
    for i in range(n):
        leave,arrive=map(str,input().split())
        leave=culc(leave)
        arrive=culc(arrive)
        L[leave]+=1
        L[arrive]-=1
    
    for i in range(1,R):
        L[i]+=L[i-1]
    
    ans=0
    for i in range(R):
        ans=max(ans,L[i])
    print(ans)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        exit()
    L = [list(map(int,input().replace(':','').split())) for _ in range(N)]
    T = [0]*240002
    for l in L:
        T[l[0]] += 1
        T[l[1]] -= 1
    for i in range(240002):
        if i > 0:
            T[i] += T[i-1]
    print(max(T))

Submission status: Accepted

Solution code:
from itertools import accumulate

def time_to_seconds(time):
    h, m, s = time.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)

ans = []
while(1):
    N = int(input())
    if N==0:
        break
    A = []
    for n in range(N):
        begin, end = input().split()
        begin = time_to_seconds(begin)
        end = time_to_seconds(end)
        A.append((begin,1))
        A.append((end,-1))
    A.sort()
    mx = 0
    cumsum = 0
    for _, x in A:
        cumsum += x
        mx = max(mx, cumsum)
    ans.append(mx)

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
INF=10**5
while True:
  n=int(input())
  if n==0:break
  imos=[0 for i_ in range(INF)]
  for _ in range(n):
    a,b=input().split()
    s1=list(map(int,a.split(':')))
    s2=list(map(int,b.split(':')))
    s1=s1[0]*3600+s1[1]*60+s1[2]
    s2=s2[0]*3600+s2[1]*60+s2[2]
    imos[s1]+=1
    imos[s2]-=1
  for i in range(INF-1):
    imos[i+1]+=imos[i]
  print(max(imos))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9 + 7

# map(int, input().split())
# list(map(int, input().split()))

while True:
    N = int(input())
    if N == 0:
        break
    times = [0] * (24 * 60 * 60 + 1)
    for i in range(N):
        line = input().split()
        start, end = 0, 0
        for j in range(2):
            h, m, s = map(int, line[j].split(":"))
            seconds = h * 60 * 60 + m * 60 + s
            if j == 0:
                start = seconds
            else:
                end = seconds
        times[start] += 1
        times[end] -= 1
    for i in range(1, 60 * 60 * 24 + 1):
        times[i] += times[i - 1]
    print(max(times))

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013


from itertools import accumulate
import sys
input = sys.stdin.readline


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

    imos = [0]*86401

    def trams_sec(x):
        return int(x[:2]) * 3600 + int(x[3:5]) * 60 + int(x[6:])


    for _ in range(N):
        a, b = input().split()
        imos[trams_sec(a)] += 1
        imos[trams_sec(b)] -= 1

    res = list(accumulate([0] + imos))

    print(max(res))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    t = []
    for i in range(n):
        t.append(list(map(str, input().split())))
    
    l = [0]*(10**6)
    for i in range(n):
        date = []
        for j in range(2):
            date.append(list(t[i][j]))

        date1 = 3600*(int(date[0][0])*10+int(date[0][1])) + 60*(int(date[0][3])*10+int(date[0][4])) + (int(date[0][6])*10+int(date[0][7]))
        date2 = 3600*(int(date[1][0])*10+int(date[1][1])) + 60*(int(date[1][3])*10+int(date[1][4])) + (int(date[1][6])*10+int(date[1][7]))

        l[date1] += 1
        l[date2] -= 1
    
    for i in range(len(l)-1):
        l[i+1] += l[i]

    print(max(l))

Submission status: Accepted

Solution code:
# AOJ_osaki.py
def calc_imos(one_day):
    day = []
    cum_sum = 0
    for i in one_day:
        cum_sum += i
        day.append(cum_sum)
    return max(day)

def calc_time(time):
    h,m,s = map(int,time.split(":")) 
    return h*60*60 + m*60 + s

while True:
    N = int(input())
    if N==0:break
    one_day = [0]*(24*60*60+1) # 秒数で1日を管理する
    for i in range(N):
        start, end = input().split()
        # 時間を1日の秒数に直す
        # one_dayに累積和を登録していく
        start = calc_time(start)
        end = calc_time(end)
        one_day[start+1] += 1
        one_day[end+1] -= 1
    print(calc_imos(one_day))
# 累積和を計算して本数を計算する

Submission status: Accepted

Solution code:
from itertools import accumulate
from sys import stdin
input = stdin.readline

def calctime(string):
    h,m,s = map(int, string.split(':'))
    time = h*60*60 + m*60 + s
    return time

maxtime = 24*60*60
while True:
    n = int(input())
    if n == 0:
        break
    trainlist = [0]*(maxtime)
    for _ in range(n):
        start, end = input().split()
        start = calctime(start)
        end = calctime(end)
        trainlist[start] += 1
        trainlist[end] -= 1
    trainlist = accumulate(trainlist)
    print(max(trainlist))

Submission status: Accepted

Solution code:
from itertools import accumulate

while 1:
    n = int(input())
    if n == 0:
        exit()
    ans = [0]*(24*60*60+1)
    for _ in range(n):
        s, t = input().split()
        sl = s.split(':')
        tl = t.split(':')
        ans[int(sl[0])*3600+int(sl[1])*60+int(sl[2])] += 1
        ans[int(tl[0])*3600+int(tl[1])*60+int(tl[2])] -= 1
    print(max(list(accumulate(ans))))