5 4 4 2 2 8

3 2 2 6

6
5 4 4 2 2 8

6
4
2
1

8
1 2 3 4 3 3 2 1

8
6
4
1

#### 額外解釋

```木棍的長度            要切除的長度      剩下木棍的數量
5 4 4 2 2 8             2               6
3 2 2 _ _ 6             2               4
1 _ _ _ _ 4             1               2
_ _ _ _ _ 3             3               1
_ _ _ _ _ _           DONE            DONE```

```木棍的長度            要切除的長度      剩下木棍的數量
1 2 3 4 3 3 2 1         1               8
_ 1 2 3 2 2 1 _         1               6
_ _ 1 2 1 1 _ _         1               4
_ _ _ 1 _ _ _ _         1               1
_ _ _ _ _ _ _ _       DONE            DONE```

#### 參考答案

```import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Solution {

public static void main(final String[] args) throws Exception {
final Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();
final ArrayList<Integer> sticks = new ArrayList<>();
for (int i = 0; i < n; ++i) {
}
Collections.sort(sticks);
while (!sticks.isEmpty()) {
final int size = sticks.size();
final int min = sticks.get(0);
for (int i = size - 1; i >= 0; --i) {
int stick = sticks.get(i);
stick -= min;
sticks.remove(i);
if (stick > 0) {