#FT0000202. Cắt tóc và số nghịch thế (Haircut)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cắt tóc và số nghịch thế (Haircut)
Haircut
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are hair strands in a row, with initial length micrometers for strand . For any integer threshold , every strand longer than is cut to exactly ; all other strands remain unchanged. Thus .
The badness is the number of pairs satisfying , known as inversions. For each threshold , find the badness of the resulting array. Every threshold is applied to the original lengths independently.
Input
- The first line contains , the number of hair strands.
- The second line contains integers , listed from left to right.
Output
Print exactly lines. Line contains the number of inversions after applying threshold , for .
Subtasks
-
Subtask 1 (20 points): ; for every .
-
Subtask 2 (30 points): ; for every .
-
Subtask 3 (50 points): ; for every .
Examples
Input
5
5 2 3 3 0
Output
0
4
4
5
7
Explanation
For , all values become zero and there are no inversions. For , the arrays become and , each having four inversions ending at the fifth element. For , the array is , adding to those four inversions, for a total of five. At , the array becomes with four inversions ending at plus three starting at the first value, giving seven.