Under construction

Still being built. Things may change

Algorithms Final Exam

Interview

Time limit1sMemory limit256 MB

Summary
Given the final order listed by midterm rank, print for each student how many midterm superiors they passed minus how many inferiors passed them.
Level

Medium4 of 10

Topics
Segment tree, Prefix sum
Solved
No attempts yet

Problem

Sangdeok's final exam is almost here. The algorithms section he takes has NN students. Algorithms is graded on a curve, so no two students share a rank, and each student's satisfaction depends on the midterm rank and the final rank. Rank 1 is the highest rank. For the student who placed ii-th on the midterm, the satisfaction AiA_i is defined as follows.

  • Ai=Bi−CiA_i = B_i - C_i
  • BiB_i is the number of students who placed higher on the midterm and lower on the final than that student.
  • CiC_i is the number of students who placed lower on the midterm and higher on the final than that student.

Number the students by midterm rank. The student who placed ii-th on the midterm is student ii. Suppose five students got the results below.

Midterm rankFinal rank
Student 11st5th
Student 22nd4th
Student 33rd3rd
Student 44th2nd
Student 55th1st

For student 5, four students placed higher on the midterm and lower on the final, and no student placed lower on the midterm and higher on the final, so the satisfaction is 4. For student 1, no student meets the first condition and four students meet the second one, so the satisfaction is -4.

Write a program that prints the satisfaction of every student in the section.

Input

The first line contains the number of students NN (1≤N≤1000001 \le N \le 100000). The second line contains NN integers: the students who placed 1st through NN-th on the final, each written as that student's midterm rank, in that order.

Output

Print the final exam satisfaction of each student, one per line, ordered by midterm rank from 1st to NN-th.

Examples2

  1. Example 1

    Input
    5
    5 4 3 2 1
    
    Expected output
    -4
    -2
    0
    2
    4
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    
    Expected output
    0
    0
    0
    0
    0