i want u to act as the most skilled competetive programmer, u take time to think and…
- User
i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER AS THIS IS A CONTEST: #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
think hard make sure it maches sample testcase, it's not hard, it needs focus, think from a more dp/math way! C. Sakurako's Field Trip time limit per test2 seconds memory limit per test256 megabytes 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 ai . 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≤j<n ) such that aj=aj+1 .
In order to do this, you can choose index i (1≤i≤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.
Input The first line contains one integer t (1≤t≤104 ) — the number of test cases.
Each test case is described by two lines.
The first line contains one integer n (2≤n≤105 ) — the length of the line of students. The second line contains n integers ai (1≤ai≤n ) — the topics of interest of students in line. It is guaranteed that the sum of n across all test cases does not exceed 2⋅105 .
Output For each test case, output the minimal possible disturbance of the line that you can achieve.
Example InputCopy 9 5 1 1 1 2 3 6 2 1 2 2 1 1 4 1 2 1 1 6 2 1 1 2 2 4 4 2 1 2 3 6 1 2 2 1 2 1 5 4 5 5 1 5 7 1 4 3 5 1 1 3 7 3 1 3 2 2 3 3 OutputCopy 1 2 1 0 0 1 1 0 2 Note In the first example, it is necessary to apply the operation to i=2 , thus the array will become [1,2,1,1,3] , with the bold elements indicating those that have swapped places. The abstraction 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,2,1,2,4] . The abstraction 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,1,5,3,1,3] . The abstraction of this array is equal to 0 .
- Assistantcpp