Solutions from SPOJ.pl