#C7861. Chickens and Cows

    ID: 51779 Type: Default 1000ms 256MiB

Chickens and Cows

Chickens and Cows

You are given the total number of animals and the total number of legs. Each animal is either a chicken (which has 2 legs) or a cow (which has 4 legs). You need to determine the number of chickens and cows such that the following system of equations holds:

\( x + y = \text{animals} \quad \text{and} \quad 2x + 4y = \text{legs} \)

If there is no valid solution, output -1.

The input is read from stdin and the result must be printed to stdout.

inputFormat

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

  • animals: the total number of animals.
  • legs: the total number of legs.

outputFormat

If there is a valid solution, print two space-separated integers: the number of chickens followed by the number of cows. Otherwise, print -1.

## sample
8 24
4 4