Descriptions:

Petr and a Combination Lock

CodeForces - 1097B