Question from today's Atcoder Yahoo Programming Contest , Problem D.

Can anyone help me in solving problem D of Atocder , which is based on some dp approach , How to formulate dp state : many solutions are very short but what they are ?

LINK : D - Ears

Editorial link : https://img.atcoder.jp/yahoo-procon2019-qual/editorial.pdf