CSES-Towers problem: help needed!

can anyone help me with this problem in CSES.
Thank you :slight_smile: