Valera and Elections

CodeForces - 369C