Woburn Challenge 2002

Problem 7: Old MacDonald's Farm

It seems as though the monkeys are really getting their act together. The Head-Monkey, with the help of the Big-White Monkey, managed to commandeer a Flowers By Irene truck, gaining access to the finest spy equipment the NSA can develop. Armed with these tools, the Head-Monkey's loyal minion, Tiny, snuck into Bo Vine's complex and overheard his plan to use the dreaded APE on the monkeys. The Head-Monkey, upon hearing these shocking developments, was compelled to enlist the services of her trusty friends, the apes, bison, parrots and three-eyed fish, of Old MacDonald's Farm, of course. You see, Old MacDonald and the Head-Monkey go back many years, but that's a story for another day. There seems to be a problem, however. The Head-Monkey has counted the total number of heads, feet, tails and eyes that there are, but she can't keep the collection of animals still for long enough to count exactly how many of each type there are! The Head-Monkey knows the following:

  • Each animal has one head!
  • An ape has two feet, two eyes, and no tail.
  • A bison has four feet, two eyes, and one tail.
  • A parrot has two feet, one eye (it's a pirate's bird, and it has an eye patch) and a tail.
  • A three-eyed fish has zero feet, three eyes (…) and one tail.

Input

The first line of input contains a single integer, T (1 ≤ T ≤ 50), indicating the number of test cases.
Each test case consists of four integers, indicating the number of heads, feet, eyes and tails.
Note that these integers will be less than 215.

Output

The number of apes, bison, parrots and fish, in that order, separated by a space.
If the values you obtain indicate fractional animals, or worse, negative animals, output "FUNNY FARM"!

Sample Input

3
10 16 21 9
10 24 19 6
11 25 20 6

Sample Output

1 2 3 4
4 3 2 1
FUNNY FARM

All Submissions
Best Solutions


Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 30, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

I have read the announcement, if that's going to part of the response. I think my problem can pertain to others since quite a few others also have 9/13. The sample data works fine, I tried to filter out the possible fractional animals with both ceil and trunc at once, but alas something is still wrong. What did my code fail to take into consideration?

You output -0, try making that 0 instead.
And you fail a few simple test cases.