International Passport
Many people are familiar with the process of obtaining a document like a passport, which often requires visiting several locations in a specific order to complete tasks such as obtaining a certificate, writing an application, or certifying a photocopy. To make this process more convenient, these locations have been consolidated into unified centers, where each task is handled at a separate window. However, each window has its own operating hours, which can still pose a challenge.
A person plans to arrive at the unified center at hh hours and mm minutes. They need to visit exactly n windows in a specified order and are aware of each window's operating hours. The goal is to determine if they can complete their visits and receive their passport before the end of the day, assuming there are no other visitors at the center.
For each window, the opening and closing times are known, as well as the number of minutes required to serve one visitor.
It is assumed that the visitor approaches a window at the start of a specific minute. The opening time of a window is the first minute it begins operating, and the closing time is the first minute it stops operating. For example, if a window opens at 12:00 and closes at 20:00, and the service takes 11 minutes, then if a person arrives between 12:00 and 19:49, they will be served immediately. If they arrive at 11:59 or earlier, they will start being served at 12:00, and if they arrive at 19:50 or later, they will not be served.
The person moves between windows instantly. For instance, if service at a window takes 10 minutes and the person arrives at 12:45, they can start being served at the next window at 12:55 or later.
All windows open no earlier than 00:00 and close no later than 23:00. A window will not serve a visitor if there is insufficient time remaining before closing to complete the service.
The task is to determine whether the person can obtain the passport, and if so, at what earliest time they can leave the unified center with it.
Input
The first line contains the time the person plans to arrive at the unified center, in the format hh:mm. The second line contains one integer n — the number of windows to visit (1 ≤ n ≤ 100).
The next n lines describe the operation of each window in the order they need to be visited. Each line for window number i includes the opening time in the format hh:mm, a space, the closing time in the same format, another space, and one integer t_i — the number of minutes required to serve the visitor at this window (1 ≤ t_i ≤ 1440). The closing time of each window is strictly later than its opening time.
Output
If the person can obtain the passport, print Yes on the first line, and on the second line, print the time when they can leave the unified center with the passport in the format hh:mm. Otherwise, print No.