UVa 10942 - Can of Beans

Summary
Given a century, and three numbers, representing year, month and day (but in some unknown order), what is the smallest valid date (in Gregorian calendar) they can represent?

Explanation
Simply check all $$3! = 6$$ permutations of numbers and choose the earliest valid date.

It's convenient to replace the century, $$c$$, by $$c$$ mod 4 to avoid overflows in computations.

Input
5 20 9 6 3 13244324 99 99 99 1073741823 29 2 96 1073741823 29 2 0 1073741820 29 2 0

Output
03 06 09 -1 96 02 29 -1 00 02 29