Change It

All submissions for this problem are available.
### Read problems statements in [Hindi](http://www.codechef.com/download/translated/COOK113/hindi/CHNGIT.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK113/mandarin/CHNGIT.pdf), [Russian](http://www.codechef.com/download/translated/COOK113/russian/CHNGIT.pdf), [Vietnamese](http://www.codechef.com/download/translated/COOK113/vietnamese/CHNGIT.pdf), and [Bengali](http://www.codechef.com/download/translated/COOK113/bengali/CHNGIT.pdf) as well. You are given a sequence $A_1, A_2, \ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j = i1$ or $j = i+1$ (it is not allowed to choose $j = 0$ or $j = N+1$) and change the value of $A_i$ to $A_j$ — in other words, you should replace the value of one element of the sequence by one of its adjacent elements. What is the minimum number of moves you need to make in order to make all the elements of the sequence equal? ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains a single integer $N$.  The second line contains $N$ spaceseparated integers $A_1, A_2, \ldots, A_N$. ### Output For each test case, print a single line containing one integer — the minimum required number of moves. ### Constraints  $1 \le T \le 100$  $1 \le N \le 100$  $1 \le A_i \le 100$ for each valid $i$ ### Example Input ``` 3 5 1 1 1 1 1 4 9 8 1 8 2 1 9 ``` ### Example Output ``` 0 2 1 ``` ### Explanation **Example case 1:** No moves are needed since all the elements are already equal. **Example case 3:** We can perform one move on either $A_1$ or $A_2$.Author:  kmaaszraa 
Editorial  https://discuss.codechef.com/problems/CHNGIT 
Tags  cakewalk, cook113, greedy, kmaaszraa, kmaaszraa 
Date Added:  15122019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 