In IOI 2017 toy [train](https://oj.uz/problem/view/IOI17_train), does anyone know what are the intended solutions for the subtasks, particularly subtasks 3-5? The [editorial](https://ioi2017.ir/tasks/editorial/train.pdf) goes straight to the full solution.