#P6339. [COCI 2007/2008 #2] TURBO

[COCI 2007/2008 #2] TURBO

Problem Description

Given a permutation of length nn containing 1n1 \sim n, you need to sort it in increasing order. The sorting rules are as follows:

  • Phase 1: Move the number 11 to index 11 by swapping it with adjacent numbers.
  • Phase 2: Move the number nn to index nn in the same way.
  • Phase 3: Move the number 22 to index 22 in the same way.
  • Phase 4: Move the number n1n-1 to index n1n-1 in the same way.

And so on.

For each phase, output the number of swaps.

Input Format

The first line contains an integer nn.

The next nn lines each contain one integer, describing a permutation of 1n1 \sim n.

Output Format

Output a total of nn lines. For each phase, output the number of swaps.

3
2
1
3
1
0
0
5
5
4
3
2
1
4
3
2
1
0
7
5
4
3
7
1
2
6
4
2
3
0
2
1
0

Hint

Constraints

  • For 70%70\% of the testdata, n<100n < 100.
  • For 100%100\% of the testdata, 1n1051 \le n \le 10^5.

Notes

This problem is translated from COCI2007-2008 CONTEST #2 T4 TURBO

Translated by ChatGPT 5