Do this first
Walls, the Rondanini Pietà, and Sempione as far as the arch. Add the Triennale only for a design show you want. Prices, security and last trains follow official sites.
After the castle
After the Pietà, leave by the back gate. Sempione stops at the arch. Without a show you want, leave the Triennale outside the park, and do not go on to the cathedral.