D - Banned K Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

ボールが NN 個あり、 ii 番目のボールには整数 AiA_i が書かれています。
k=1,2,...,Nk=1,2,...,N に対して以下の問題を解いて、答えをそれぞれ出力してください。

  • kk 番目のボールを除いた N1N-1 個のボールから、書かれている整数が等しいような異なる 22 つのボールを選び出す方法の数を求めてください。選ぶ順序は考慮しません。

制約

  • 3N2×1053 \leq N \leq 2 \times 10^5
  • 1AiN1 \leq A_i \leq N
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 A2A_2 ...... ANA_N

出力

k=1,2,...,Nk=1,2,...,N に対する答えを順番に一行ずつ出力せよ。


入力例 1Copy

Copy
5
1 1 2 1 2

出力例 1Copy

Copy
2
2
3
2
3

例えば k=1k=1 のとき、残りのボールに書かれている数はそれぞれ 1,2,1,2{1,2,1,2} です。
この中から書かれている数が等しいような異なる 22 つのボールを選び出す方法は 22 通りあります。
したがって、 k=1k=1 に対する問題の答えは 22 です。


入力例 2Copy

Copy
4
1 2 3 4

出力例 2Copy

Copy
0
0
0
0

どの 22 つのボールを選び出しても、書かれている数は等しくありません。


入力例 3Copy

Copy
5
3 3 3 3 3

出力例 3Copy

Copy
6
6
6
6
6

どの 22 つのボールを選び出しても、書かれている数が等しいです。


入力例 4Copy

Copy
8
1 2 1 4 2 1 4 1

出力例 4Copy

Copy
5
7
5
7
7
5
7
5

Score : 400400 points

Problem Statement

We have NN balls. The ii-th ball has an integer AiA_i written on it.
For each k=1,2,...,Nk=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 N1N-1 balls other than the kk-th ball so that the integers written on them are equal.

Constraints

  • 3N2×1053 \leq N \leq 2 \times 10^5
  • 1AiN1 \leq A_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 ...... ANA_N

Output

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


Sample Input 1Copy

Copy
5
1 1 2 1 2

Sample Output 1Copy

Copy
2
2
3
2
3

Consider the case k=1k=1 for example. The numbers written on the remaining balls are 1,2,1,21,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=1k=1 is 22.


Sample Input 2Copy

Copy
4
1 2 3 4

Sample Output 2Copy

Copy
0
0
0
0

No two balls have equal numbers written on them.


Sample Input 3Copy

Copy
5
3 3 3 3 3

Sample Output 3Copy

Copy
6
6
6
6
6

Any two balls have equal numbers written on them.


Sample Input 4Copy

Copy
8
1 2 1 4 2 1 4 1

Sample Output 4Copy

Copy
5
7
5
7
7
5
7
5


2025-04-24 (Thu)
08:24:02 +00:00