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 Go (1.6) (judge verdict: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	N := nextInt()
	A := nextInts(N)
	cmb := NewCombination()
	cmb.build()
	cnt := map[int]int{}
	ans := make([]int, N)
	for _, a := range A {
		cnt[a]++
	}
	for k := 0; k < N; k++ {
		cnt[A[k]] -= 1
		for _, v := range cnt {
			ans[k] += cmb.c(v, 2)
		}
		cnt[A[k]] += 1
	}
	for k := 0; k < N; k++ {
		fmt.Println(ans[k])
	}
}

type Combination struct {
	max, mod int
	fact     []int
	factInv  []int
	inv      []int
}

func NewCombination() *Combination {
	c := &Combination{}
	c.max = 21000
	c.mod = 2147483647
	c.fact = make([]int, c.max)
	c.factInv = make([]int, c.max)
	c.inv = make([]int, c.max)
	return c
}

func (c *Combination) build() {
	c.inv[1], c.fact[0], c.factInv[0] = 1, 1, 1
	var i int
	for i = 2; i < c.max; i++ {
		c.inv[i] = c.inv[c.mod%i] * (c.mod - c.mod/i) % c.mod
	}
	for i = 1; i < c.max; i++ {
		c.fact[i] = c.fact[i-1] * i % c.mod
		c.factInv[i] = c.factInv[i-1] * c.inv[i] % c.mod
	}
}

func (c *Combination) c(n, k int) int {
	if n < 0 || k < 0 || n < k {
		return 0
	}
	return c.fact[n] * c.factInv[k] % c.mod * c.factInv[n-k] % c.mod
}

func (c *Combination) p(n, k int) int {
	if k < 0 || k > n {
		return 0
	}
	return c.fact[n] * c.factInv[n-k] % c.mod
}

func (c *Combination) h(n, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	return c.c(n+k-1, k)
}

// c:N 個の整数の中から，相異なる K 個の整数を選ぶパターンの数C(N,K)
// p:N 個の整数の中から，相異なる K 個の整数を選び，順番に並べるパターンの数P(N,K)
// h:N 個の整数の中から，重複を許して K 個の整数を選ぶパターンの数H(N,K)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}