Banned K

AtCoder
IDabc159_d
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
5
1 1 2 1 2
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$.
Input #2
4
1 2 3 4
Output #2
0
0
0
0

No two balls have equal numbers written on them.
Input #3
5
3 3 3 3 3
Output #3
6
6
6
6
6

Any two balls have equal numbers written on them.
Input #4
8
1 2 1 4 2 1 4 1
Output #4
5
7
5
7
7
5
7
5
API Response (JSON)
{
  "problem": {
    "name": "Banned K",
    "description": {
      "content": "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 distin",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc159_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have $N$ balls. The $i$\\-th ball has an integer $A_i$ written on it.  \nFor each $k=1, 2, ..., N$, solve the following problem and print the answer.\n\n*   Find the number of ways to choose two distin...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments