#B3754. Determine the Minimum and Maximum Number of Rabbits

    ID: 11413 Type: Default 1000ms 256MiB

Determine the Minimum and Maximum Number of Rabbits

Determine the Minimum and Maximum Number of Rabbits

There are three types of animals in a cage:

  • Chicken: 1 head, 2 legs
  • Three-legged cat: 1 head, 3 legs
  • Rabbit: 1 head, 4 legs

Given two integers \(x\) and \(y\) representing the total number of heads and legs respectively, you cannot determine the exact count of each animal directly. Instead, your task is to calculate the minimum and maximum possible number of rabbits.

Let \(a\) be the number of chickens, \(b\) be the number of three-legged cats, and \(c\) be the number of rabbits. The following equations hold:

\( a + b + c = x \)

\( 2a + 3b + 4c = y \)

By eliminating \(a\) and \(b\), you can deduce that \(c\) (rabbits) satisfies:

\( c \geq \max(0, y - 3x) \)

and

\( c \leq \frac{y - 2x}{2} \)

Output the minimum and maximum number of rabbits possible.

inputFormat

The input consists of two space-separated integers \(x\) and \(y\). It is guaranteed that \(2x \leq y \leq 4x\).

outputFormat

Output two integers separated by a space: the minimum and maximum possible number of rabbits in the cage, respectively.

sample

35 95
0 15