SPOJ submission 10057809