Codeforces Round 981 (Div. 3) |
---|
Finished |
Even in university, students need to relax. That is why Sakurakos teacher decided to go on a field trip. It is known that all of the students will be walking in one line. The student with index $$$i$$$ has some topic of interest which is described as $$$a_i$$$. As a teacher, you want to minimise the disturbance of the line of students.
The disturbance of the line is defined as the number of neighbouring people with the same topic of interest. In other words, disturbance is the number of indices $$$j$$$ ($$$1 \le j < n$$$) such that $$$a_j = a_{j + 1}$$$.
In order to do this, you can choose index $$$i$$$ ($$$1\le i\le n$$$) and swap students at positions $$$i$$$ and $$$n-i+1$$$. You can perform any number of swaps.
Your task is to determine the minimal amount of disturbance that you can achieve by doing the operation described above any number of times.
The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
Each test case is described by two lines.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output the minimal possible disturbance of the line that you can achieve.
951 1 1 2 362 1 2 2 1 141 2 1 162 1 1 2 2 442 1 2 361 2 2 1 2 154 5 5 1 571 4 3 5 1 1 373 1 3 2 2 3 3
1 2 1 0 0 1 1 0 2
In the first example, it is necessary to apply the operation to $$$i=2$$$, thus the array will become $$$[1, \textbf{2}, 1, \textbf{1}, 3]$$$, with the bold elements indicating those that have swapped places. The disturbance of this array is equal to $$$1$$$.
In the fourth example, it is sufficient to apply the operation to $$$i=3$$$, thus the array will become $$$[2, 1, \textbf{2}, \textbf{1}, 2, 4]$$$. The disturbance of this array is equal to $$$0$$$.
In the eighth example, it is sufficient to apply the operation to $$$i=3$$$, thus the array will become $$$[1, 4, \textbf{1}, 5, \textbf{3}, 1, 3]$$$. The disturbance of this array is equal to $$$0$$$.
Name |
---|