Vanya and Cubes

CodeForces - 492A