7 1 2 3 2 3 2 1
7 For example, if you perform the operation with $(l,r)=(3,5), (2,6), (1,7)$ in this order, $A$ changes as follows: $(1,2,3,2,3,2,1)\rightarrow (1,2,3,3,3,2,1) \rightarrow (1,2,2,2,2,2,1) \rightarrow (1,1,1,1,1,1,1)$, after which there is no $l$ and $r$ with the said property. The total cost of this series of operations is $1+3+5=9$. On the other hand, if you perform the operation with $(l,r)=(2,4), (4,6), (1,7)$ in this order, $A$ changes as follows: $(1,2,3,2,3,2,1)\rightarrow (1,2,2,2,3,2,1) \rightarrow (1,2,2,2,2,2,1) \rightarrow (1,1,1,1,1,1,1)$. The total cost of this series of operations is $1+1+5=7$.
5 1 2 3 4 5
0
40 1 2 3 4 5 6 7 8 7 6 5 6 7 8 7 6 5 4 3 2 2 1 2 3 4 5 4 5 6 7 8 7 7 6 5 6 6 7 8 8
44
{
"problem": {
"name": "Colorful Reversi",
"description": {
"content": "You are given an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$. On this sequence, the following operation can be performed: * Choose $l$ and $r$ $(1\\leq l < r \\leq N)$ such that $A_l=A_r$,",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "arc181_f"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You are given an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$. On this sequence, the following operation can be performed:\n\n* Choose $l$ and $r$ $(1\\leq l < r \\leq N)$ such that $A_l=A_r$,...",
"is_translate": false,
"language": "English"
}
]
}