PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000071. Sắp xếp Turbo (Turbo)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sắp xếp Turbo (Turbo)

Turbo

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Frane is given a permutation containing every integer from 11 to nn exactly once. He wants to sort it in increasing order by a fixed procedure of exactly nn phases.

In phase one, he moves value 11 to the first position using swaps of adjacent elements. In phase two, he moves value nn to the last position. Phase three moves value 22 to the second position, phase four moves value n−1n-1 to position n−1n-1, and so on, alternately fixing the smallest and largest values not fixed yet. Once an element reaches its final position, later phases leave it in place.

For each phase, determine the number of adjacent swaps required, in chronological order. Print 00 when the selected element is already in its final position.

Input

The first line contains integer nn.

Exactly nn lines follow; line ii contains integer aia_i, the original value at position ii.

Output

Print exactly nn lines. Line tt contains the number of adjacent swaps performed during phase tt.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤ai≤n1\le a_i\le n; each integer from 11 to nn occurs exactly once.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ai≤n1\le a_i\le n; each integer from 11 to nn occurs exactly once.

  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤n1\le a_i\le n; each integer from 11 to nn occurs exactly once.

Examples

Input

3
2
1
3

Output

1
0
0

Explanation

Initially the permutation is [2,1,3][2,1,3].

  • Phase 1: Value 11 is at position 22. Swap it with 22, producing [1,2,3][1,2,3] in one swap.
  • Phase 2: Value 33 is already last, requiring zero swaps.
  • Phase 3: Value 22 is already second, requiring zero swaps.

The three lines are therefore 1, 0, and 0.