SPOJ submission 10058178