Jon Snow and his Favourite Number

CodeForces - 768C