# UVa 10942

From Algorithmist

## 10942 - Can of Beans[edit]

## Summary[edit]

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[edit]

Simply check all permutations of numbers and choose the earliest valid date.

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

## Input[edit]

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

## Output[edit]

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