This is the code of the Contest version: