To find , solve . You can iterate: start from and keep incrementing while . The largest such is your answer. Let .
If , output 0. Otherwise, count how many ways to assign colors to each level such that you use exactly red blocks and exactly green blocks. This is where the DP comes in. Understanding this concept will help you solve more complex problems.