{"raw_statement":[{"iden":"problem statement","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$, $A_{l+1}=A_{l+2}=\\dots=A_{r-1}$, and $A_{l+1}\\neq A_l$. Replace each of $A_{l+1},A_{l+2},\\dots,A_{r-1}$ with $A_l$. The cost of this operation is $r-l-1$.\n\nYou will repeat this operation until there is no $l$ and $r$ $(1\\leq l < r \\leq N)$ such that $A_l=A_r$, $A_{l+1}=A_{l+2}=\\dots=A_{r-1}$, and $A_{l+1}\\neq A_l$. Find the minimum total cost of such a series of operations."},{"iden":"constraints","content":"*   $3 \\leq N \\leq 5 \\times 10^5$\n*   $1 \\leq A_i \\leq N$\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\dots$ $A_N$"},{"iden":"sample input 1","content":"7\n1 2 3 2 3 2 1"},{"iden":"sample output 1","content":"7\n\nFor 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$.\nOn 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$."},{"iden":"sample input 2","content":"5\n1 2 3 4 5"},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"40\n1 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"},{"iden":"sample output 3","content":"44"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}