Under construction

Still being built. Things may change

Emma Loves Parties

Time limit1sMemory limit128 MB

Summary
Given parties as hourly intervals, find the most Emma can attend if she stays at least 30 minutes at each one.
Level

Medium5 of 10

Topics
Greedy, Sorting, Intervals
Solved
No attempts yet

Problem

Emma has just graduated from high school. In her town it is a long-standing custom to hold many parties that every graduate may attend, and Emma, who loves parties, wants to attend as many of them as she possibly can.

On weekdays only two or three parties are held in the evening, but on Saturday parties run all day long. Some parties begin as early as 8:00 in the morning, and because the neighbors might complain, no party ever ends later than 24:00 (midnight).

Every party has a fixed start time and end time, and every party begins and ends exactly on the hour. To be polite, Emma must stay at each party she attends for at least 30 minutes, and she always keeps this rule. Emma can teleport, so travelling between parties takes no time at all. When there is no other party left for her to attend, she goes home.

Write a program that finds the maximum number of parties Emma can attend.

Input

The input consists of several test cases. Each test case begins with a line containing an integer pp (p≤100p \le 100), the number of parties held that day. A value of p=0p = 0 marks the end of the input. Each of the following pp lines contains two integers ss and ee (8≤s<e≤248 \le s < e \le 24): ss is the party's start time and ee is its end time. Several different parties may have exactly the same start and end time — that is, the same (s,e)(s, e) pair may appear more than once — and each of them counts as a separate party.

Output

For each test case, print exactly one line in the following format:

On day d Emma can attend as many as n parties.

Here nn is the maximum number of parties Emma can attend and dd is the number of the test case (test cases are numbered starting from 1). Always write the word parties (plural), even when nn is 1.

Examples1

  1. Example 1

    Input
    8
    12 13
    13 14
    12 13
    9 10
    9 10
    12 13
    12 14
    9 11
    3
    14 15
    14 15
    14 15
    0
    
    Expected output
    On day 1 Emma can attend as many as 7 parties.
    On day 2 Emma can attend as many as 2 parties.