Universal Cup Judging System

Universal Cup

時間限制: 6 s 記憶體限制: 512 MB 總分: 100 难度: [顯示] 可 Hack ✓
统计

Yuki has $n$ sticks arranged in a row, where the $i$-th stick has length $a_i$.

Yuki defines an operation as follows: - Choose a stick and cut it into two parts, both of which must have integer lengths (one of the parts can have length 0). - Merge the left part of the cut stick with the stick immediately to its left; if there is no stick to its left, the left part becomes a new, independent stick. - Merge the right part of the cut stick with the stick immediately to its right; if there is no stick to its right, the right part becomes a new, independent stick. - Remove all sticks of length 0.

Now, Yuki wants to perform some number of operations such that all sticks have the same length. You need to help Yuki find the minimum number of operations required to make all sticks have the same length.

It can be proven that there always exists at least one sequence of operations that can make all sticks have the same length.

Input

This problem contains multiple test cases.

The first line contains a positive integer $t$ ($1 \le t \le 10^5$), representing the number of test cases.

For each test case: - The first line contains a positive integer $n$ ($1 \le n \le 10^6$). - The second line contains $n$ positive integers $a_1, \dots, a_n$ ($1 \le a_i \le 10^6$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output

For each test case, output one line containing an integer representing the minimum number of operations required to make all sticks have the same length.

Sample 1

Input 1

3
3
1 5 4
4
1 4 2 5
5
3 3 3 3 3

Output 1

1
2
0

Note

For the first test case: - In the first operation, choose the second stick and cut it into two parts of lengths 4 and 1. The stick lengths from left to right become 5, 5, where all sticks have the same length. - It can be proven that the minimum number of operations required is 1.

For the second test case: - In the first operation, choose the first stick and cut it into two parts of lengths 0 and 1. The stick lengths from left to right become 5, 2, 5. - In the second operation, choose the second stick and cut it into two parts of lengths 1 and 1. The stick lengths from left to right become 6, 6, where all sticks have the same length. - It can be proven that the minimum number of operations required is 2.

For the third test case: - Initially, all sticks already have the same length, so the minimum number of operations required is 0.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1873EditorialOpenNew Editorial for Problem #17347wangmaruiView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.