#P11444. Maximizing the Sum of Squares in a Constrained Zuma Game

    ID: 13524 Type: Default 1000ms 256MiB

Maximizing the Sum of Squares in a Constrained Zuma Game

Maximizing the Sum of Squares in a Constrained Zuma Game

In this problem, you are given a sequence of positive integers (a_1, a_2, \dots, a_n) representing colored balls. You are allowed to perform a series of deletion moves. In each move, you may choose a contiguous segment in the sequence such that all numbers in the segment are identical and the segment's length (X) satisfies (X_{min} \le X \le X_{max}). When you remove such a segment, the remaining parts of the sequence are concatenated (and if two segments with the same number become adjacent, they naturally form a longer contiguous block). You obtain a score equal to (X^2) for that move.

Your goal is to compute the maximum total score (i.e. the maximum possible sum of squares of the lengths of the segments you remove) that can be achieved by repeatedly applying the deletion operation. It is possible that not all elements in the sequence can be removed.

Formally, given a sequence ({a_i}{i=1}^n) and two integers (X{min}) and (X_{max}), find the maximum value of (\sum X_i^2), where each (X_i) is the length of a valid removed segment (with (X_{min} \le X_i \le X_{max})). All deletions are performed one after another on the current sequence.

Note: All formulas are in (\LaTeX) format.

inputFormat

The first line of input contains three integers (n), (X_{min}) and (X_{max}) (the length of the sequence and the inclusive limits for the deletion length). The second line contains (n) positive integers (a_1, a_2, \dots, a_n) separated by spaces.

outputFormat

Output a single integer representing the maximum total score (i.e. the maximum sum of squares of the lengths of the deletion moves) that can be obtained.

sample

5 2 3
2 3 3 3 1
9