Zuma
HardRating 1900CodeforcesAdvanced DP (Bitmask, Digit, Interval)
Approach hintTry it first, then revealHide
Let dp[l][r] be the answer for a segment. Gem l is removed alone, together with an equal neighbour, or as the outer layer of a palindrome closed by an equal gem k, which adds nothing beyond clearing l+1..k-1.