This page is still under construction.

Parts of this page are still being built. What you see may change.

Osaki

Time limit8sMemory limit512 MB

Summary
Given each train's departure and arrival times at Osaki on a loop line, find the minimum number of train cars (units) needed to cover all scheduled trips.
Level

Medium5 of 10

Topics
Greedy, Sorting, Intervals, Implementation
Solved
No attempts yet

Problem

The Yamanote Line is a loop railway line laid within the 23 wards of Tokyo. Its total length is 34.5 km, and a full circuit takes about one hour. There are 29 stations in total. Its line color is warbler green. At peak times the congestion rate exceeds 200%, making it one of the most crowded railway lines in Japan. During the busiest hours a train runs every 3 minutes, and people visiting Tokyo for the first time are astonished by the sight.

Tetsuko is a genuine railway enthusiast who loves the Yamanote Line beyond measure. One day, while reading her favorite JR timetable, she arrived at the following question. "How many cars are used on the Yamanote Line in a single day?"

She tried to work out from the timetable the minimum number of cars needed for operation. But the number of trains was so large that she could never count them all alone. So she asked you, an excellent programmer, for help.

Your job is to write a program that finds, from a given timetable, the minimum number of cars needed to operate the Yamanote Line. Since the Yamanote Line is a loop line, its timetable is often written for convenience with Osaki Station as the first and last station. For that reason, the timetable she handed you also records only each train's departure time and arrival time at Osaki Station.

This cannot happen on the real Yamanote Line, but to keep the setting simple, we assume here that a train can depart Osaki Station immediately after arriving there. Also, the times Tetsuko copied down may contain errors, or trains she added on her own whim in her fantasies may have slipped into the timetable, but you cannot tell which, so you must find the number of cars for exactly the times as written.

If you write a program that works correctly, she might invite you on a date inside a train. Whether you accept or decline the invitation is, of course, up to you.

Input

The input consists of multiple datasets. Each dataset has the following format.

n
hh:mm:ss hh:mm:ss
hh:mm:ss hh:mm:ss
...
hh:mm:ss hh:mm:ss

The integer n on the first line is the number of trains contained in the timetable. This value is guaranteed not to exceed 10,000. The n lines from the second line to the (n+1)-th line give each train's departure time and arrival time at Osaki Station in that order, separated by a single space. Each time is written in the form hh:mm:ss, where hh is hours, mm is minutes, and ss is seconds. The ranges of the values are 0 ≦ hh < 24, 0 ≦ mm < 60, 0 ≦ ss < 60. Each number is padded with leading zeros as needed so that all have two digits.

No train is included that runs across midnight 24:00. Therefore the departure time is always earlier than the arrival time.

The end of the input is indicated by n = 0. This is not included in the datasets.

Output

For each dataset, output the minimum number of cars required on one line.

Examples1

  1. Example 1

    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
    
    Expected output
    1
    3