Trying spoj in python