SPOJ submission 10057291