http://uva.onlinejudge.org/external/4/497.html