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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using P = pair<ll, ll>;
const int INF = 1001001001;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 500010;
const int MOD = 1000000007;

bool comInit;
long long fac[MAX], finv[MAX], inv[MAX];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long com(ll n, ll k){
    if(!comInit)
    {
        cominit();
    }
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll moddiv(ll x, ll y, ll mod)
{
    y = modpow(y, mod-2, mod);
    return x * y % mod;
}

ll modcomb(ll n, ll r, ll mod) {
    ll x = 1;
    ll y = 1;

    rep(i, r)
    {
        x = (x * (n - i)) % mod;
        y = (y * (i + 1)) % mod;
    }

    return moddiv(x, y, mod);
}

struct uf {
    vector<ll> par;

    uf(int n)
    {
        for(int i = 0; i < n; i++) {
            par.push_back(-1);
        }
    }

    ll root(int x) 
    {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) 
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(par[rx] < par[ry]) 
        {
            ll r = rx;
            rx = ry;
            ry = r;
        }

        par[rx] += par[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) 
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll size(int x)
    {
        return -par[root(x)];
    }
};

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

  bool initComb;
  std::vector<std::vector<long long>> combC;

ll comb(int n, int r) {

  if(!initComb)
  {
      combC = vector<std::vector<long long>>(n + 1,std::vector<long long>(n + 1, 0));
      for (int i = 0; i < combC.size(); i++) {
    combC[i][0] = 1;
    combC[i][i] = 1;
  }
  for (int j = 1; j < combC.size(); j++) {
    for (int k = 1; k < j; k++) {
      combC[j][k] = (combC[j - 1][k - 1] + combC[j - 1][k]);
    }
  }
      initComb = true;
  }

  return combC[n][r];
}

ll digit(ll num)
{
    if(num < 10)
    {
        return 1;
    }

    ll d = 1;
    ll k = 10;
    while(num >= k)
    {
        d++;
        k *= 10;
    }

    return d;
}

ll digitNum(ll num, ll count)
{
    ll a = (num % (ll) pow((double) 10, (double) count));
    return a / pow(10, count - 1);
}

bool less_abs(int lhs, int rhs) {
    if(lhs < 0)
    {
        lhs *= -1;
    }
    if(rhs < 0)
    {
        rhs *= -1;
    }

    return lhs < rhs;
}

bool IsTrueBit(int bit, int index)
{
    return (bit & (1 << index));
}

int main(){
    ll n;
    
    cin >> n;
    ll a[n];
    ll k[n];
    map<ll, ll> m;
    ll x = 0;
    rep(i, n) 
    {
        cin >> a[i];
    }

    rep(i, n) 
    {
        m[a[i]] = 0;
    }

    rep(i, n) 
    {
        m[a[i]]++;
    }

    map<ll, bool> ggg;
    rep(i, n)
    {
        ll w = a[i];
        if(ggg[w])
        {
            continue;
        }
        x += m[w] * (m[w] - 1) / 2;
        ggg[w] = true;
    }

    rep(i, n)
    {
        ll ans = x;
        k[i] = x - (m[a[i]] - 1);
    }

    rep(i, n) cout << k[i] << endl;

    return 0;
}