New Year Present Problem

Pls Can anyone explain solution to this problem

Can not able to understand from editorial

@anon55659401 @vijju123

Please help