#K10416. Maximum Non-overlapping Cake Baking

    ID: 23242 Type: Default 1000ms 256MiB

Maximum Non-overlapping Cake Baking

Maximum Non-overlapping Cake Baking

You are given several datasets, each representing a schedule of cakes to be baked. Each cake has a name, a start time, and an end time (in the 24-hour format HHMM). Your task is to determine the maximum number of cakes that can be baked in a day without any time overlaps. Two cakes are considered non-overlapping if the start time of a cake is greater than or equal to the finish time of the previously baked cake.

Note: Use the greedy algorithm approach (i.e. select the cake that finishes first) to achieve an optimal solution.

The input terminates when a dataset starts with 0, which should not be processed.

inputFormat

The input consists of multiple test cases. Each test case begins with an integer N (the number of cakes). If N is 0, it indicates the end of input.

For each test case, the next N lines each contain three elements separated by spaces: a cake name (a string), the start time, and the end time (both in HHMM format).

You should read from stdin.

outputFormat

For each test case, output a single line containing one integer – the maximum number of non-overlapping cakes that can be baked. Write your output to stdout.

## sample
3
Chocolate 0900 1100
Vanilla 1030 1230
Strawberry 1200 1400
2
Lemon 0800 1000
Blueberry 0900 1100
0
2

1

</p>