How about we signify by c0, c1 and c2 the number of numbers from the cluster a that have leftovers 0, 1 and 2 when separated by the number 3, individually. Suppose that the exhibit a has adjusted leftovers if c0, c1 and c2 are equivalent. For instance, assuming n=6 and a=[0,2,5,5,4,8], the accompanying arrangement of
Correct answer will be upvoted else downvoted. Computer science.
How about we signify by c0, c1 and c2 the number of numbers from the cluster a that have leftovers 0, 1 and 2 when separated by the number 3, individually. Suppose that the exhibit a has adjusted leftovers if c0, c1 and c2 are equivalent.
For instance, assuming n=6 and a=[0,2,5,5,4,8], the accompanying arrangement of moves is conceivable:
at first c0=1, c1=1 and c2=4, these qualities are not equivalent to one another. How about we increment a3, presently the exhibit a=[0,2,6,5,4,8];
c0=2, c1=1 and c2=3, these qualities are not equivalent. How about we increment a6, presently the cluster a=[0,2,6,5,4,9];
c0=3, c1=1 and c2=2, these qualities are not equivalent. We should increment a1, presently the cluster a=[1,2,6,5,4,9];
c0=2, c1=2 and c2=2, these qualities are equivalent to one another, which implies that the cluster a has adjusted leftovers.
Track down the base number of moves expected to make the exhibit a have adjusted leftovers.
Input
The primary line contains one integer t (1≤t≤104). Then, at that point, t experiments follow.
The main line of each experiment contains one integer n (3≤n≤3⋅104) — the length of the cluster a. It is ensured that the number n is distinguishable by 3.
The following line contains n integers a1,a2,… ,an (0≤
It is ensured that the amount of n over all experiments doesn't surpass 150000.
Output
For each experiment, output one integer — the base number of moves that should be made for the a cluster to cause it to have adjusted leftovers.
Step by step
Solved in 4 steps with 1 images