Under construction

Still being built. Things may change

Bus

Time limit1sMemory limit2048 MB

Summary
Find the shortest travel time from Zagreb to Wroclaw by taking a Zagreb-Graz bus, then a Graz-Wroclaw bus, or report NEMOGUCE if no connection works.
Level

Easy3 of 10

Topics
Brute force, Implementation
Solved
No attempts yet

Problem

Mr. Malnar decided to visit Wroclaw (Pol. Wrocław), a city in southwest Poland that he has not yet visited. He had not traveled by bus for a long time and missed the experience, but he found that there is no direct bus line between Zagreb and Wroclaw.

The best option is to transfer in the Austrian city of Graz. Mr. Malnar found a timetable listing the bus lines on the routes Zagreb-Graz and Graz-Wroclaw. A bus on a given route runs daily. It departs exactly at the start of the departure minute and arrives exactly at the end of the arrival minute. Transfer time is negligible: you can board a bus if you arrive before the bus you want departs. In other words, the arrival time of the first bus must be strictly less than the departure time of the second bus.

Determine the shortest time required to travel from Zagreb to Wroclaw.

Input

The first line contains a positive integer nn (1≤n≤2001 \le n \le 200), the number of bus lines.

Each of the next nn lines contains the names of two cities joined by -, the departure city first and the destination second, followed by the departure time and arrival time in the format h:mm--h:mm. Here h is the hour and mm is the minute, always written with two digits, with a leading zero when needed. Each trip without transfers lasts at most 24 hours.

Output

If a trip from Zagreb to Wroclaw is possible, print the travel time on the first line in the format h:mm.

Constraints

If the trip is not possible, print NEMOGUCE on the first line.

Examples2

  1. Example 1

    Input
    4
    Zagreb-Graz 15:30--23:59
    Graz-Wroclaw 10:42--19:15
    Zagreb-Graz 14:13--20:19
    Graz-Wroclaw 2:25--5:00
    
    Expected output
    13:31
    
  2. Example 2

    Input
    3
    Zagreb-Graz 6:05--16:40
    Zagreb-Graz 20:00--21:40
    Zagreb-Graz 9:56--22:36
    
    Expected output
    NEMOGUCE