#P9222. Inferring the Current Time Period from a Date‐Changing Clock

    ID: 22377 Type: Default 1000ms 256MiB

Inferring the Current Time Period from a Date‐Changing Clock

Inferring the Current Time Period from a Date‐Changing Clock

A clock with a rotating dial displays only the date. The clock updates its displayed date exactly at (12:00) AM (midnight). Note that the clock uses a 12‐hour format so that after (11:59) AM comes (12:00) PM and after (11:59) PM comes (12:00) AM; however, the date is updated only at midnight (i.e. when the clock shows (12:00) AM).

Suppose you observed the clock continuously over a closed time interval from one moment to another. Based solely on whether the displayed date changed during your observation, determine if you can definitively infer whether the current period is morning (AM) or afternoon (PM). In other words, if a date change is observed then you know that the clock passed midnight and the current period is AM; otherwise, if no date change is observed the available information is ambiguous.

You are given two time strings in the format HH:MM (using a 12‐hour clock with possible values from 12:00 to 11:59). Assume that the observed interval is the smallest possible interval (i.e. the end time is taken to be the earliest time that is not earlier than the start time in chronological order).

Your task is to output:

  • AM if the observation interval necessarily includes the midnight update (and so the current period is AM),
  • and NO otherwise (since if no date change is observed, it is not possible to deduce whether the current period is AM or PM).

Note on Time Conversion:

For comparison, convert a time in format HH:MM as follows:

  • If \(HH = 12\), consider it as 0 minutes (i.e. 12:00 is treated as 0 minutes past midnight in an AM interpretation).
  • Otherwise, convert it normally as \(\text{HH} \times 60 + \text{MM}\).

Thus, if the converted start time is greater than the converted end time, the interval must have passed midnight (i.e. a date change occurred) and the answer is AM; otherwise, output NO.

inputFormat

The input consists of two lines. The first line contains the start time and the second line contains the end time, each in the format HH:MM. Both times are given in a 12-hour format.

outputFormat

Output a single line: AM if the observation interval necessarily included a date change (i.e. passed midnight), and NO otherwise.

sample

11:59
12:00
AM