SPOJ submission 10058947