Problem:
Score : 400 points

Problem Statement

We have N balls. The i-th ball has an integer A_i written on it.

For each k=1, 2, ..., N, solve the following problem and print the answer.

Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Constraints

3 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

For each k=1,2,...,N, print a line containing the answer.

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.

From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    int s[n];
    int a0=0;
    int a1=0;
    int a2=0;
    int a3=0;
    int a4=0;
    int a5=0;
    int a6=0;
    int a7=0;
    int a8=0;
    int a9=0;
    int aa0=0;
    int aa1=0;
    int aa2=0;
    int aa3=0;
    int aa4=0;
    int aa5=0;
    int aa6=0;
    int aa7=0;
    int aa8=0;
    int aa9=0;

    for(int i=0; i<n; i++){
        scanf("%d",&a[i]);
        s[i]=0;
        switch (a[i])
        {
        case 0:
            a0++;
            break;
        case 1:
            a1++;
            break;
        case 2:
            a2++;
            break;
        case 3:
            a3++;
            break;
        case 4:
            a4++;
            break;
        case 5:
            a5++;
            break;
        case 6:
            a6++;
            break;
        case 7:
            a7++;
            break;
        case 8:
            a8++;
            break;
        case 9:
            a9++;
            break;
        default:
            break;
        }
    }
    for(int i=0; i<n; i++){
        switch (a[i])
        {
        case 0:
            a0--;
            break;
        case 1:
            a1--;
            break;
        case 2:
            a2--;
            break;
        case 3:
            a3--;
            break;
        case 4:
            a4--;
            break;
        case 5:
            a5--;
            break;
        case 6:
            a6--;
            break;
        case 7:
            a7--;
            break;
        case 8:
            a8--;
            break;
        case 9:
            a9--;
            break;
        default:
            break;
        }
        for(int j=a0-1; j>0; j--){
            aa0+=j;
        }
        for(int j=a1-1; j>0; j--){
            aa1+=j;
        }
        for(int j=a2-1; j>0; j--){
            aa2+=j;
        }
        for(int j=a3-1; j>0; j--){
            aa3+=j;
        }
        for(int j=a4-1; j>0; j--){
            aa4+=j;
        }
        for(int j=a5-1; j>0; j--){
            aa5+=j;
        }
        for(int j=a6-1; j>0; j--){
            aa6+=j;
        }
        for(int j=a7-1; j>0; j--){
            aa7+=j;
        }
        for(int j=a8-1; j>0; j--){
            aa8+=j;
        }
        for(int j=a9-1; j>0; j--){
            aa9+=j;
        }
        s[i]=aa0+aa1+aa2+aa3+aa4+aa5+aa6+aa7+aa8+aa9;
        aa0=aa1=aa2=aa3=aa4=aa5=aa6=aa7=aa8=aa9=0;
        switch (a[i])
        {
        case 0:
            a0++;
            break;
        case 1:
            a1++;
            break;
        case 2:
            a2++;
            break;
        case 3:
            a3++;
            break;
        case 4:
            a4++;
            break;
        case 5:
            a5++;
            break;
        case 6:
            a6++;
            break;
        case 7:
            a7++;
            break;
        case 8:
            a8++;
            break;
        case 9:
            a9++;
            break;
        default:
            break;
        }
        printf("%d\n",s[i]);
    }
}