You are given a sequence of integers .
In one operation, choose two adjacent entries with values and . Delete either one of them at cost , preserving the order of all other entries.
Find the minimum total cost of reducing the sequence to length .
For each test case, output the minimum total cost.
Delete using its neighbor , then using , then using . The costs are .
Delete the middle entry at cost , then delete one of the equal entries at cost .
The sequence already has length .
Delete in that order, using neighbors . The costs are .