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: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder20200322
{
    class Program
    {
        static void Main(string[] args)
        {
            // TheNumberOfEvenPairs();
            //  StringPalindrome();
            // MaxVolume();
             BannedK();
            // KnapsackforAllSegments();
        }
        
        public static void TheNumberOfEvenPairs()
        {
            String[] inputs = Console.ReadLine().Split(' ');
            int n = int.Parse(inputs[0]);
            int m = int.Parse(inputs[1]);

            int sum = nCm(n, 2) + nCm(m, 2);
            Console.WriteLine(sum);
        }

        public static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static void MaxVolume()
        {
            double l = double.Parse(Console.ReadLine());
            double vol = Math.Pow(l, 3) / (double)27;
            Console.WriteLine(vol);
        }

        public static void BannedK()
        {
            int n = int.Parse(Console.ReadLine());
            String[] input_a = Console.ReadLine().Split(' ');
            int[] a_n = new int[n];
            Dictionary<int, long> dic = new Dictionary<int, long>();
            for (int i=0; i<n; i++)
            {
                a_n[i] = int.Parse(input_a[i]);
                if (dic.ContainsKey(a_n[i]))
                {
                    dic[a_n[i]]++;
                }
                else
                {
                    dic.Add(a_n[i], 1);
                }
            }
            long sum = 0;
            
            foreach(KeyValuePair<int, long> pair in dic)
            {
                sum += pair.Value * (pair.Value - 1) / 2;
            }

            // Result
            for(int i=0; i<n; i++)
            {
                int num = a_n[i];
                long res = sum - (dic[num] - 1);
                Console.WriteLine(res);
            }
        }

        public static void StringPalindrome()
        {
            String s = Console.ReadLine();
            int n = s.Length;
            char[] cs = new char[n];
            char[] c_former = new char[(n - 1) / 2];
            char[] c_latter = new char[(n - 1) / 2];
            int i = 0;
            foreach(char c in s)
            {
                cs[i] = c;
                i++;
            }
            bool isKaibun = true;
            for(int j=0; j<(n-1)/2; j++)
            {
                isKaibun = isKaibun && (cs[j] == cs[n - 1 - j]);
                c_former[j] = cs[j];
                c_latter[(n - 1) / 2 - 1- j] = cs[n - 1 - j];
            }
            if(!isKaibun)
            {
                Console.WriteLine("No");
                return;
            }
            for(int j=0; j<c_former.Length; j++)
            {
                isKaibun = isKaibun && (c_former[j] == c_former[c_former.Length - 1 - j]) && (c_latter[j] == c_latter[c_latter.Length - 1 - j]);   
            }
            if(isKaibun)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }


        }

        public static void KnapsackforAllSegments()
        {
            String[] input1 = Console.ReadLine().Split(' ');
            String[] input2 = Console.ReadLine().Split(' ');

            int n = int.Parse(input1[0]);
            int s = int.Parse(input1[1]);
            int[] a = new int[n];
            for(int i=0; i<n; i++)
            {
                a[i] = int.Parse(input2[i]);
            }

            int sum = 0;
            for(int l=1; l<=n; l++)
            {
                for(int r=l; r<=n; r++ )
                {
                    sum += funct(l, r, a, s);
                }
            }
            int res = sum % 998244353;
            Console.WriteLine(res);

        }

        public static int funct(int l, int r, int[] a, int s)
        {
            int bit_num = r - l + 1;
            int condition_num = (int)Math.Pow(2, bit_num);
            int count = 0;
            for(int i = 0; i < condition_num; i++)
            {
                int sum = 0;
                String twodig = Convert.ToString(i, 2).PadLeft(bit_num, '0');
                bool[] digits = twodig.Select(c => c=='1').ToArray();
                for(int j = 1; j<=bit_num; j++)
                {
                    if(digits[digits.Length - j])
                    {
                        sum += a[l - 1 + j - 1];
                    }
                }
                if(sum == s)
                {
                    // Console.WriteLine("f(" + l + ", " + r + ") :" + twodig);
                    count++;
                }
            }
            return count;



        }
    }
}