#P1693. Herding Cows

    ID: 14978 Type: Default 1000ms 256MiB

Herding Cows

Herding Cows

Farmer John's three award-winning cows, Bessie, Elsie, and Mildred, have wandered off to far-away locations on the farm. The farm's field can be thought of as a number line where cows occupy integer positions. Farmer John wants to herd the cows so that they occupy three consecutive positions (for example, positions 6, 7, and 8).

At any given time, Farmer John can only move a cow that is at an endpoint (i.e. the cow at the smallest or largest position among the three). When moving that cow, she can be moved to any unoccupied integer position, as long as she no longer remains an endpoint after the move.

Your task is to determine the minimum and maximum number of moves required to rearrange the cows into three consecutive positions.

The positions of the cows are given as three distinct integers. Let the sorted positions be \(a, b, c\). Define \(gap_1 = b-a\) and \(gap_2 = c-b\). The answer is determined as follows:

  • If the cows are already consecutive \((gap_1 = 1 \text{ and } gap_2 = 1)\), the number of moves is 0.
  • If either \(gap_1 = 2\) or \(gap_2 = 2\), then the minimum moves is 1.
  • Otherwise, the minimum moves is 2.

The maximum moves is \(\max(gap_1, gap_2) - 1\).

inputFormat

The input consists of a single line containing three distinct space-separated integers representing the positions of the cows.

outputFormat

Output two space-separated integers on a single line: the minimum and the maximum number of moves required to make the cow positions consecutive.

sample

4 7 9
1 2