#P8665. Calculate Flight Duration

    ID: 21831 Type: Default 1000ms 256MiB

Calculate Flight Duration

Calculate Flight Duration

For a flight that may cross time zones, the departure and arrival times for the outbound and return flights are given in the local times of the respective airports. Let the outbound flight depart at time A (in minutes) and arrive at time B (in minutes) (in the destination local time), and the return flight depart at time C (in the destination local time) and arrive at time D (in the origin local time). Assume the airplane’s actual flight time T (in minutes) is the same in both directions, and denote the unknown time zone difference by d (in minutes). Then we have:

\[B - A + k_1 \times 1440 = T + d\]

\[D - C + k_2 \times 1440 = T - d\]

for some nonnegative integers \(k_1\) and \(k_2\) which account for possible day rollovers. Adding the two equations yields

\[ (B - A + k_1 \times 1440) + (D - C + k_2 \times 1440) = 2T, \]

so the flight time is computed as

\[ T = \frac{(B - A + k_1 \times 1440) + (D - C + k_2 \times 1440)}{2}. \]

Your task is to determine the minimal positive flight time T (formatted in HH:MM) by choosing appropriate nonnegative integers \(k_1\) and \(k_2\) such that T is positive and the summed difference is even.

inputFormat

The input consists of two lines. The first line contains two time strings in the format HH:MM, representing the departure time A and arrival time B of the outbound flight. The second line contains two time strings in the format HH:MM, representing the departure time C and arrival time D of the return flight.

outputFormat

Output the flight time T in the format HH:MM, where HH and MM are two‐digit numbers. It is guaranteed that the answer exists and is unique.

sample

10:00 12:00
12:00 14:00
14:00