Observing Two Stars

Interview

Time limit1sMemory limit128 MB

Summary
Given start times and periods of two blinking stars, find the earliest simultaneous blink time and weekday, or report it never happens.
Level

Medium5 of 10

Topics
Number theory, Math, Simulation
Solved
No attempts yet

Problem

Sanggeun and Junggeun are observing two stars for their astronomy class. For each star, they recorded the time it first blinked today and the period after which it blinks again. Each star keeps blinking forever at its own fixed period.

Today is Saturday, and the first time of a day is 00:00 midnight. Find the earliest time when the two stars blink at the same time.

Input

Four lines are given. Each line is a time in HH:MM format, where 0 <= HH <= 23 and 0 <= MM <= 59.

The first line is the time when the first star first blinked today, the second line is the time when the second star first blinked today, the third line is the blinking period of the first star, and the fourth line is the blinking period of the second star.

The first two times are always different. Today is Saturday. A blinking period is never 00:00.

Output

If the two stars never blink at the same time, print Never.

Otherwise, print the weekday of the earliest simultaneous blink on the first line. The weekday must be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday.

On the second line, print the time of that simultaneous blink in HH:MM format.

Examples3

  1. Example 1

    Input
    02:20
    13:00
    05:50
    01:00
    
    Expected output
    Saturday
    14:00
    
  2. Example 2

    Input
    02:20
    23:28
    00:40
    23:50
    
    Expected output
    Never
    
  3. Example 3

    Input
    23:19
    10:19
    02:42
    09:11
    
    Expected output
    Thursday
    00:31