#K79767. Minimum Delivery Time for Circular Zones

    ID: 35382 Type: Default 1000ms 256MiB

Minimum Delivery Time for Circular Zones

Minimum Delivery Time for Circular Zones

In this problem, two delivery drones start from different zones on a circular track consisting of N zones. The goal is to compute the minimum time required for the two drones to meet. Drones can move in either clockwise or counter-clockwise directions.

Given the starting positions P1 and P2 of the drones, the effective travel time is the minimum of the clockwise distance and the counter-clockwise distance.

Mathematically, if we denote the distances as:

clockwise=(P2P1)modN\text{clockwise} = (P_2-P_1) \mod N counter-clockwise=(P1P2)modN\text{counter-clockwise} = (P_1-P_2) \mod N

Then, the answer is:

min(clockwise,counter-clockwise)\min(\text{clockwise}, \text{counter-clockwise})

inputFormat

The input consists of a single line containing three space-separated integers:

  • N (the number of zones arranged in a circle)
  • P1 (the starting zone of the first drone)
  • P2 (the starting zone of the second drone)

It is guaranteed that N >= 1 and 1 <= P1, P2 <= N.

outputFormat

Output a single integer representing the minimum time required for the two drones to meet.

## sample
5 1 1
0