#FT0000077. Nghịch thế sau khi xoay giá trị (Rotated Inversions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghịch thế sau khi xoay giá trị (Rotated Inversions)
Rotated Inversions
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers and a sequence , where every value lies between and . Duplicate values are allowed.
For each integer , form a sequence by setting . The order of positions does not change: only the values are rotated modulo .
The inversion count of is the number of index pairs for which . Equality must not be counted.
Compute and output the inversion count for every in increasing order.
Input
The first line contains integers .
The second line contains integers .
Output
Print exactly lines. Line contains the inversion count of , for .
Subtasks
-
Subtask 1 (20 points): ; for all .
-
Subtask 2 (30 points): ; for all .
-
Subtask 3 (50 points): ; for all .
Examples
Input
3 3
2 1 0
Output
3
1
1
Explanation
With and , consider all three values of :
- : ; all pairs are inversions, so the answer is .
- : ; only pair is an inversion, so the answer is .
- : ; only pair is an inversion, so the answer is .
Print 3, 1, 1, one per line.