SPOJ submission 10037653