Math Homework
InterviewTime limit1sMemory limit1024 MB
Given the leg counts b, d, c of three animal types and a total of l legs, list every count triple whose legs add up to l, or print impossible.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
Since entering 2nd grade, Theta has had daily math homework sheets. The problems on her worksheet usually go like this:
There is a certain number of birds, dogs, and cats on a farm. Together they have legs. How many birds, dogs, and cats could there be? Write down as many answers as you can!
It is always the same problem, just written in different ways: sometimes with horses, cows, sheep, goats, chickens, beetles, or even spiders (but never with snakes or fishes!)
Can you write a program to double-check Theta's answers?
Input
The input consists of a single line with 4 integers , , , and . , , and are the numbers of legs the first, second, and third type of animal has. You are given that , because some farm animals in these problems may be centipedes. The total number of legs is ().
Output
Output all possible answers, each on a separate line, in lexicographical order: sorted by the number of the first animal, with ties broken by the second and then the third animal. Separate the number of the first, second, and third animal with spaces. If there are no possible solutions, output impossible on a single line.