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# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc159
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc159D();
        }

        public static void solve_abc159D()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] cnt = new int[20001];
            for (int i = 0; i < n; i++)
            {
                cnt[a[i]]++;
            }
            long[] combSum = new long[20001];
            long[] combSumExclude = new long[20001];
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                if (cnt[i] > 0)
                {
                    long c1 = combs(cnt[i], 2);
                    long c2 = combs(cnt[i] - 1, 2);
                    sum += c1;
                    combSum[i] = c1;
                    //case when c2 == 0 ? 2 out of 1.
                    combSumExclude[i] = c2;
                }
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine((sum - combSum[a[i]]) + combSumExclude[a[i]]);
            }
        }
        public static void solve_abc159C()
        {
            double l = Convert.ToDouble(Console.ReadLine());
            double d = l / 3;
            Console.WriteLine("{0:F12}", d * d * d);
            /*
            long max = 0; 
            for (int a = 1; a < 32; a++)
            {
                for (int b = 1; b < 32; b++)
                {
                    for (int c = 1; c < 32; c++)
                    {
                        if (a * a + b * b + c * c <= l)
                        {
                            max = Math.Max(max, a * b * c);
                        }
                    }
                }
            }*/

            //Console.WriteLine(max);
        }

        public static void solve_abc159B()
        {
            string s = Console.ReadLine();
            bool ok = true;

            int l = 0;
            int r = s.Length - 1;
            ok = isPalindrom(s, l, r);
            if (ok)
            {
                ok = isPalindrom(s, 0, ((s.Length - 1) / 2) - 1);
            }
            if (ok)
            {
                ok = isPalindrom(s, ((s.Length + 3) / 2) - 1, s.Length - 1);
            }
            if (ok)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public static bool isPalindrom(string s, int l, int r)
        {
            bool ok = true;
            while (l < r)
            {
                if (s[l] != s[r])
                {
                    ok = false;
                    break;
                }
                l++;
                r--;
            }
            return ok;
        }

        public static void solve_abc159A()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long even = 0;
            if (nm[0] > 1)
            {
                even = combs(nm[0], 2);
            }
            long odd = 0;
            if (nm[1] > 1)
            {
                odd = combs(nm[1], 2);
            }
            Console.WriteLine(even + odd);
        }
        public static long combs(int n, int k)
        {
	        int res = 1;
	        for (int i = n - k + 1; i <= n; i++)
            {
		        res *= i;
            }
	        for (int i = 2; i <= k; i++)
            {
		        res /= i;
            }
            return res;
            /*double res = 1;
	        for (int i = 1; i <= k; i++)
            {
		        res = res * (n - k + i) / i;
            }
	        return (long) (res + 0.01);
            */
        }
    }
}