jiahuimbzuai/CoQuIR huggingface dataset:
//  [swift]
import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}


class Solution {
    func maxBalancedPath(_ arr: [[[Int]]], _ n: Int, _ m: Int, _ total: Int) -> Int {
        var dp = [[[Bool]]](repeating: [[Bool]](repeating: [Bool](repeating: false, count: total+1), count: m+1), count: n+1)
        
        for i in stride(from: 0, to: m, by: 1) {
            for j in stride(from: 0, to: total+1, by: 1) {
                dp[0][i][j] = true
            }
        }
        
        for i in stride(from: 0, to: n, by: 1) {
            for j in stride(from: 0, to: total+1, by: 1) {
                dp[i][0][j] = true
            }
        }
        
        for i in stride(from: 1, through: n, by: 1) {
            for j in stride(from: 1, through: m, by: 1) {
                let val = abs(arr[i-1][j-1][0]-arr[i-1][j-1][1])
                if  i == 1 && j == 1 {
                    dp[i][j][val] = true
                    continue
                }
                //now setting dp[i][j]
                for k in stride(from: 0, to: total+1, by: 1) {
                    if k + val < total+1 {
                        dp[i][j][k+val] = (dp[i][j][k+val] || (i-1 > 0 ? dp[i-1][j][k] : false) || (j-1 > 0 ? dp[i][j-1][k] : false) )
                    }
                    if i-1 > 0 {
                        dp[i][j][k] = (dp[i][j][k] || dp[i-1][j][abs(k-val)] || (k+val < total+1 ? dp[i-1][j][k+val] : false))
                    }
                    if j-1 > 0 {
                        dp[i][j][k] = (dp[i][j][k] || dp[i][j-1][abs(k-val)] || (k+val < total+1 ? dp[i][j-1][k+val] : false))
                    }
                }
            }
//            print("\(i)")
        }
        for i in stride(from: 0, to: 12730, by: 1) {
            if dp[n][m][i] {
                return i
            }
        }
        return 0
    }
    
}

let nm = Scanner.readIntArr()
let fs = Scanner.readM(nm[0])
let ss = Scanner.readM(nm[1])
var mat = [[[Int]]](repeating: [[Int]](repeating: [Int](repeating: 0, count: 2), count: nm[1]), count: nm[0])
var total = 0
for i in 0..<nm[0] {
    var rowMax = 0
    for j in 0..<nm[1] {
        mat[i][j][0] = fs[i][j]
        mat[i][j][1] = ss[i][j]
        rowMax = max(rowMax, abs(fs[i][j]-ss[i][j]))
    }
    total += rowMax
}
//print(total)
print(Solution().maxBalancedPath(mat, nm[0], nm[1], total))
//  [swift]
var input_num = readLine()!

var arr = input_num.split ( separator:" " ).map { Int($0)! }

// print (arr)

if (arr[0] + arr[1] + arr[2] == 21) {
    print("win")
} else {
    print ("bust")
}
//  [swift]
import Foundation
let str = readLine()!.components(separatedBy:" ")
var sum : Int! = 0
var num = [Int]()
for i in str {
    sum = sum + Int(i)!
}

if sum >= 22 {
    print("bust")
}else {
    print("win")
}
//  [typescript]
import * as fs from 'fs'

//in
// 5 7 9
//out
// win
const func = (inp: string) => {
    const [a1, a2, a3]: number[] = inp.split(' ').map(Number);

    if (a1 + a2 + a3 >= 22) {
        console.log('bust');
    } else {
        console.log('win');
    }
};

func(fs.readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
function Main(input) {
  let sum = input.trim().split(" ").map(Number).reduce((sum, n) => sum += n);
  console.log(sum < 22 ? 'win' : 'bust');
}

Main(require('fs').readFileSync("/dev/stdin", "utf8"));
//  [typescript]
function main(input: string) {
  const [A1,A2,A3] = input.split(" ").map(v => parseInt(v));
  console.log(A1+A2+A3 <= 21 ? "win" : "bust");
}

main(
  require("fs")
    .readFileSync("/dev/stdin", "utf8")
    .trim()
);
//  [typescript]
const fs = require('fs');

const main = () => {

    const input: string = fs.readFileSync('/dev/stdin', 'utf8');
  	let hugs = 0;
    for (let i = 0; i < input.length/2; i++) {
        if (input[i] != input[input.length-1-i]) {
          hugs++;
        }
    }
   console.log(hugs);
};

main();
//  [typescript]
function Main(i) {
	console.log(i.split(' ').reduce((acc, t) => {return acc + parseInt(t)}, 0) > 22 ? 'bust': 'win')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
'use strict'
function Main(input) {
	const lines = input.split('\n');
	let n = lines.shift()*1
	const people = Array(n).fill(null);

	while (lines.length) {
		const a = lines.shift();
		for (let i = 0; i < a; i++) {
			const [x, y] = lines.shift().split(' ');
			if (people[x - 1] === null) {
				people[x - 1] = y;
				if (y === '0') n--;
			} else if(people[x - 1] !== y) n--;
		}
	}
	
	console.log(n);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    B = [0] * (N + 1)
    for a in A:
        B[a] += 1

    total = 0
    for b in B:
        total += b * (b - 1) // 2

    ans = [0] * N
    for i, a in enumerate(A):
        ans[i] = total - (B[a] - 1)

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()
//  [python]
#!/usr/bin/env python3
def main():
    import time

    N = int(input())
    A = [int(x) for x in input().split()]

    num_lst = [0] * (N + 1)
    for a in A:
        num_lst[a] += 1

    ans = 0
    for num in num_lst:
        # ans += comb(num, 2, exact=True)
        ans += num * (num - 1) // 2

    start = time.time()
    for a in A:
        print(ans - (num_lst[a] - 1))
    end = time.time() - start
    # print(f'{end:6f}', 's')


if __name__ == '__main__':
    main()
//  [python]
import collections
N=int(input())
A=list(map(int,input().split()))

D = collections.Counter(A)
for i in range(N):
  D[A[i]]-=1
  s=0
  for j in D:
    s+=D[j]*(D[j]-1)//2
  print(s)
  D[A[i]]+=1
//  [python]
import collections
N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
ans = 0
for i in range(N):
  ans+=c[i]*(c[i]-1)//2

for i in range(N):
  print(ans-(c[A[i]]-1))
//  [python]
import collections
N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
ans = 0
for i in range(N):
  ans+=c[i]*(c[i]-1)//2

for i in range(N):
  print(ans-(c[A[i]]-1)) if c[A[i]]>1 else print(ans)
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Yagnik
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DBannedK solver = new DBannedK();
        solver.solve(1, in, out);
        out.close();
    }

    static class DBannedK {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), MX = (int) 2e5 + 1;
            long[] f = new long[MX];
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                f[a[i]]++;
            }
            long ans = 0;
            for (int i = 0; i < MX; i++) ans += f[i] * (f[i] - 1) >> 1;
            for (int i = 0; i < n; i++) w.println(ans - f[a[i]] + 1);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}
//  [java]
import java.util.Scanner;

/**
 * Banned K
 * 
 * https://atcoder.jp/contests/abc159/tasks/abc159_d
 */
public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) throws Exception {
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int[] B = new int[N + 1];
        for (int a : A) {
            B[a]++;
        }

        long K = 0;
        for (int i = 1; i <= N; i++) {
            K += B[i] * (B[i] - 1) / 2;
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < N; i++) {
            int b = B[A[i]];
            if (b < 2) {
                ans.append(K).append("\n");
            } else {
                ans.append(K - b * (b - 1) / 2 + (b - 1) * (b - 2) / 2).append("\n");
            }
        }

        System.out.println(ans.toString());
    }

}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int[] A = new int[N];
		int[] B = new int[N+1];
		int[] C = new int[N];
		long ans = 0;
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
			B[A[i]]++;
		}

		for (int i = 1; i < N+1; i++) {
			ans += B[i]*(B[i]-1)/2;
		}

		for (int i = 0; i < N; i++) {
			ans -= B[A[i]] - 1;
			System.out.println(ans);
			ans += B[A[i]] - 1;
		}

	}

}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int[] A = new int[N];
		int[] B = new int[N+1];
		int[] C = new int[N];
		long ans = 0;
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
			B[A[i]]++;
		}

		for (int i = 1; i < N+1; i++) {
			ans += B[i]*(B[i]-1)/2;
		}

		for (int i = 0; i < N; i++) {

			ans -= B[A[i]]*(B[A[i]]-1)/2 - (B[A[i]]-1)*(B[A[i]]-2)/2;

			System.out.println(ans);

			ans += B[A[i]]*(B[A[i]]-1)/2 - (B[A[i]]-1)*(B[A[i]]-2)/2;

		}

	}

}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, c, * owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	//swap(c, ci[8]);
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	//swap(c, ci[8]);
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 - 100000];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue >= 10) {
		memcpy(di, f.C + f.K[ue], f.K[ue + 1] - f.K[ue]);
		di += f.K[ue + 1] - f.K[ue];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else if (ue) {
		*di++ = f.C[f.K[ue]];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int B[200001];

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(ci, 1, CM, stdin);

	int N = getint();
	ll kotae = 1;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int *a = A;
	
	int amari = N % 10800;
	int shou = N / 10800;
	rep(j, shou) {
		rep(k, 10800) putint(kotae - B[*a++]);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[*a++]);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, c, * owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	swap(c, ci[8]);
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	swap(c, ci[8]);
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 - 100000];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue >= 10) {
		memcpy(di, f.C + f.K[ue], f.K[ue + 1] - f.K[ue]);
		di += f.K[ue + 1] - f.K[ue];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else if (ue) {
		*di++ = f.C[f.K[ue]];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int B[200001];

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(ci, 1, CM, stdin);

	int N = getint();
	ll kotae = 1;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int *a = A;
	
	int amari = N % 10800;
	int shou = N / 10800;
	rep(j, shou) {
		rep(k, 10800) putint(kotae - B[*a++]);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[*a++]);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, * owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	char c = ci[8];
	ci[8] = 0;
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci[8] = c;
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 - 100000];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue) {
		memcpy(di, f.C + f.K[ue], f.K[ue + 1] - f.K[ue]);
		di += f.K[ue + 1] - f.K[ue];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		memcpy(di, f.C + f.K[sita], f.K[sita + 1] - f.K[sita]);
		di += f.K[sita + 1] - f.K[sita];
	}
	else {
		memcpy(di, f.C + f.K[X], f.K[X + 1] - f.K[X]);
		di += f.K[X + 1] - f.K[X];
	}
	*di++ = '\n';
}

int B[200001];

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(ci, 1, CM, stdin);

	int N = getint();
	ll kotae = 1;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int *a = A;
	
	int amari = N % 10800;
	int shou = N / 10800;
	rep(j, shou) {
		rep(k, 10800) putint(kotae - B[*a++]);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[*a++]);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    long long ans=0;
    vector<int> a(n),suuti(n+1);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        suuti.at(a.at(i))++;
    }
    for(int i=0;i<=n;i++){
        ans+=suuti.at(i)*(suuti.at(i)-1)/2;
    }
    //cout << ans << endl;
    for(int i=0;i<n;i++){
        cout << ans-suuti.at(a.at(i))+1 << endl;
    }
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#include <list>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 100000007;
using Graph = vector<vector<int>>;


int main(){
    int N;
    cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];

    ll tot = 0;
    ll ans[N];
    map<int,int> M;
    REP(i,N){
        if(M.count(A[i])) M[A[i]]++;
        else M[A[i]] = 1;
    }
    for(int i = 1; i <= N; ++i){
        if(M.count(i)){
            if(M[i]>1){
                int x = M[i]*(M[i]-1);
                x/=2;
                tot+=x;
            }
        }
    }
    REP(i,N){
        if(M[A[i]]==1) ans[i]=tot;
        else if(M[A[i]]==2) ans[i] = tot-1;
        else{
            int a = M[A[i]];
            int b = a*(a-1);
            b/=2;
            --a;
            int c =a*(a-1);
            c/=2;
            ans[i] = tot - b + c;
        }
    }
    REP(i,N) cout << ans[i] << endl;
}
//  [cpp]
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> dp(N+1);
    for(int i=0;i<N;i++){
        cin >> A[i];
        dp[A[i]]++;
    }
    ll total=0;
    for(int i=1;i<=N;i++){
        if(dp[i]>1){
            total+= dp[i]*(dp[i]-1)/2;
        }
    }
    for(int i=0;i<N;i++){
        int num = A[i];
        ll ans=total;
        if(dp[num]>1){
            ans = ans - dp[num]*(dp[num]-1)/2;
            if(dp[num]>2){
                ans += (dp[num]-1)*(dp[num]-2)/2;
            }
        }
        cout << ans << endl;
    }
}
//  [c]
// ABC 159-D
// 2020.3.24 bal4u

#include <stdio.h>

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
	//(c & 0xf)：字符0-9 Ascii码0x30-0x39 与0xf（即00001111）按位与运算 只保留个位数（0x0-0x9）
}

void out(ll n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int f[200005];
int A[200005];

int main()
{
	int i, N, a, ma;
	ll s;

	N = in();
	ma = 0;
	for (i = 0; i < N; ++i) {
		A[i] = a = in(), f[a]++;
		if (a > ma) ma = a;
	}
	s = 0; for (i = 1; i <= ma; ++i) s += (ll)f[i] * (f[i] - 1) >> 1;// >> 1:右移运算符 将其二进制右移1位 即/2
	for (i = 0; i < N; ++i) out(s - (f[A[i]]-1));
	return 0;
}
//  [c]
// ABC 159-D
// 2020.3.24 bal4u

#include <stdio.h>

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(ll n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int f[200005];
int A[200005];

int main()
{
	int i, N, a, ma;
	ll s;

	N = in();
	ma = 0;
	for (i = 0; i < N; ++i) {
		A[i] = a = in(), f[a]++;
		if (a > ma) ma = a;
	}
	s = 1; for (i = 1; i <= ma; ++i) s += (ll)f[i]*(f[i]-1) >> 1;
	for (i = 0; i < N; ++i) out(s - f[A[i]]);
	return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

// 200000*7
#define BUF_SIZE 1500000

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define NUM_MAX 200000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+1];
    fget_array(arr, num);
    static int map[NUM_MAX+1];

    int i, j;
    for(i = 0; i < num; i++) {
        map[arr[i]]++;
    }

    static uint64_t base[NUM_MAX];
    uint64_t base_sum = 0;
    for(i = 1; i <= NUM_MAX; i++) {
        uint64_t cnt = map[i];
        base[i] = cnt * (cnt-1) / 2;
        base_sum += base[i];
    }
#ifdef DEBUG
    printf("%d\n", base_sum);
#endif

    for(i = 0; i < num; i++) {
        int cnt = map[arr[i]];
        // n*(n-1)/2 - (n-1)*(n-2)/2 = (n-1)
        uint64_t res = base_sum - (cnt-1);
        printf("%llu\n", res);
    }
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int x[200001];
int main(void){
  ll n;
  scanf("%lld",&n);
  ll a[n];
  FOR(i,n){
    scanf("%lld",&a[i]);
    x[a[i]]++;
  }
  ll ans=0;
  FOR(i,200001)ans+=x[i]*(x[i]-1)/2;
  FOR(i,n)PRL(ans-x[a[i]]+1);
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int x[1000000];
int main(void){
  ll n;
  scanf("%lld",&n);
  ll a[n];
  FOR(i,n){
    scanf("%lld",&a[i]);
    x[a[i]]++;
  }
  ll ans=0;
  FOR(i,1000000)ans+=x[i]*(x[i]-1)/2;
  FOR(i,n)PRL(ans-x[a[i]]+1);
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int x[1000000];
int main(void){
  int n;
  scanf("%d",&n);
  int a[n];
  FOR(i,n){
    scanf("%d",&a[i]);
    x[a[i]]++;
  }
  ll ans=0;
  FOR(i,1000000)ans+=x[i]*(x[i]-1)/2;
  FOR(i,n)PRL(ans-x[a[i]]+1);
  return 0;
}
//  [javascript]
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var map = {};
  for(var i = 0; i < N; i++){
    if(map[list[i]] == null){
      map[list[i]] = 1;
    }else{
      map[list[i]]++;
    }
  }
  var sum = 0;
  var keys = Object.keys(map);
  for(var i = 0; i < keys.length; i++){
    var tmp = map[keys[i]];
    sum += (tmp * (tmp - 1)) / 2;
  }
  var output = new Array(N);
  for(var i = 0; i < N; i++){
    var rem = list[i];
    var tmp = map[rem];
    output[i] = (sum - (tmp * (tmp - 1) / 2) + ((tmp - 1) * (tmp - 2) / 2));
  }
  myout(myconv(output,9));
}
//  [javascript]
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var N = parseInt(input[0],10);
  var vec_A = input[1].map(e => (parseInt(e, 10)));
  var eachNumCount = Array.from({length: N}, () => 0);
  var pairCount = Array.from({length: N}, () => 0);
  var sumPair, tmp;
  var ans = [];
  for (var i = 0; i < N; i++){
    eachNumCount[vec_A[i]-1] ++;
    pairCount[vec_A[i]-1] = (eachNumCount[vec_A[i]-1] * (eachNumCount[vec_A[i]-1] - 1) / 2)
  }
  sumPair = sum(pairCount);
  for (var i = 0; i < N; i++){
    tmp = eachNumCount[vec_A[i]-1]
    if (tmp === 0) ans.push(sumPair)
    else ans.push(sumPair - (tmp * (tmp - 1) / 2) + ((tmp - 1) * (tmp - 2) / 2));
  }
  console.log(ans.join('\n'));
}   

var sum  = function(arr) {
  var sum = 0;
  arr.forEach(function(elm) {
      sum += elm;
  });
  return sum;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
const combi = function(n){
    return n*(n-1)/2
}

const main = arg => {
    const input = arg.trim().split("\n");

    const N = parseInt(input[0].split(" ")[0]);
    const A = input[1].split(" ").map(n => parseInt(n));

    let m = {}
    for(let i = 0; i<A.length; i++){
        if(!m[A[i]]) m[A[i]] = 1
        else m[A[i]]++
    }
    let orgCnt = 0
    let keys = Object.keys(m)
    for(let i = 0; i<keys.length; i++){
        orgCnt = orgCnt + combi(m[keys[i]])
    }

    let out = ""
    for(let i = 0; i<A.length; i++){
        let num = m[A[i]]
        const diff = combi(num) - combi(num-1)

        out = out + String(orgCnt-diff)+"\n"
    }
    console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
  input=input.split("\n");
  var array=input[1].split(' ').map(e=>{
    return e-0;
  });
  var number=new Array(Math.max(...array)+1);
  number.fill(0);
  array.forEach(e=>{
    number[e]++;
  });
  var sum=0;
  number.forEach(e=>{
    sum+=e*(e-1)/2;
  });
  array.forEach(e=>{
    console.log(sum-number[e]+1);
  });
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const A = lines[1].split(' ').map(Number)

    const m = Array(N + 1).fill(0)
    for (let i = 0; i < N; i++) {
        m[A[i]]++
    }

    const f = (n, m, d = 1) => {
        let sum = n
        let add = n
        for (let i = 1; i < m; i++) {
            add += d
            sum += add
        }
        return sum
    }

    let s = 0
    for (let i = 0; i < N; i++) {
        if (m[i] < 2) continue
        s += f(1, m[i] - 1)
    }

    for (let k = 0; k < N; k++) {
        const ans = s - (m[A[k]] - 1)
        console.log(ans)
    }

})(input)
//  [javascript]
const main = (input) => {
  input = input.trim().split('\n')
  const N = parseInt(input[0], 10)
  const nums = input[1].split(' ')

  const x = {}
  const cache = {}
  let sum = 0
  for (let i = 0; i < N; i++) x[nums[i]] = ~~x[nums[i]] + 1
  for (let [k, v] of Object.entries(x)) {
    if (v < 2) {
      delete x[k]
    } else {
      sum += v*(v-1) / 2
    }
  }


  for (let i = 0; i < N; i++) {
    console.log(sum === 0 ? 0 : sum - Math.max(0, x[nums[i]] - 1))
  }

  // nums.forEach(v => {
  //   x[v] -= 1
  //
  //   if (!cache[v]) {
  //     let sum = 0
  //     Object.keys(x).forEach(o => sum += (x[o] > 1) ?  c(x[o], 2) : 0)
  //     cache[v] = sum
  //   }
  //   console.log(cache[v])
  //
  //   x[v] += 1
  // })
}

const _cmb = (a, b) => {
  let numerator = 1
  for (let i = 0; i < b; i++) {
    numerator *= a
    a--
  }

  let denominator = 1
  while (b > 0) {
    denominator *= b
    b--
  }

  return numerator / denominator
}

const memo = (fn) => {
  const cache = {}
  return (a, b) => {
    if (!cache[`${a}c${b}`]) cache[`${a}c${b}`] = fn(a, b)
    return cache[`${a}c${b}`]
  }
}

const c = memo(_cmb)

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	return num
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	ans := make([]int, n+1)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		ans[a[i]]++
	}

	total := 0
	for i := 0; i < n; i++ {
		if ans[i+1] != 0 {
			total += ans[i+1] * (ans[i+1] - 1) / 2
		}
	}

	wb := bufio.NewWriter(os.Stdout)
	defer wb.Flush()
	for i := 0; i < n; i++ {
		if ans[a[i]] == 0 {
			fmt.Fprintln(wb, 0)
		} else {
			temp := ((ans[a[i]] - 1) * (ans[a[i]] - 2) / 2) - (ans[a[i]] * (ans[a[i]] - 1) / 2)
			fmt.Fprintln(wb, total+temp)
		}
	}

}
//  [go]
//problem_d.go

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	//"strings"
)

const (
	mod = int(1e9) + 7
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

// -----------------------------------------

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

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

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

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

// -----------------------------------------

// Sort Fanction

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func rsortIntSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

// -----------------------------------------

// Num Fanction

//numModPow(a, n, m) == a^n % m
func numModPow(a int, n int, m int) int {
	result := 1

	for n > 0 {
		if n%2 == 1 {
			result = (result * a) % m
		}

		a = (a * a) % m
		n >>= 1
	}

	return result
}

// numGcd(a, b) == gcd(a, b)
func numGcd(a int, b int) int {
	if b == 0 {
		return a
	}

	return numGcd(b, a%b)
}

// numLcm(a, b) == lcm(a, b)
func numLcm(a int, b int) int {
	return a * b / numGcd(a, b)
}

// numModInv(a, p) == a^(-1) % p
func numModInv(a int, p int) int {
	if a == 1 {
		return 1
	} else {
		return p - numModInv(p%a, p)*(p/a)%p
	}
}

// -----------------------------------------

func solve() {

	n := getInt()
	ns := getIntSlice(n)

	var count_table [2*int(1e5) + 10]int
	s := 0

	for i := 0; i < n; i++ {
		count_table[ns[i]]++
	}

	for i := 1; i <= n; i++ {
		if count_table[i] >= 2 {
			s += count_table[i] * (count_table[i] - 1) / 2
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(wr, s-(count_table[ns[i]]-1))
	}
}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}
//  [go]
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  B := make([]int, N + 1)
  for _, a := range A {
    B[a]++
  }
  C := make([][]int, 2)
  for i := range C { C[i] = make([]int, N + 1) }
  for i, b := range B {
    C[0][i] = b * (b - 1) / 2
    if 0 < b { C[1][i] = (b - 1) * (b - 2) / 2 }
  }
  S := SumInt(C[0]...)
  D := make([]int, N + 1)
  for i := range D {
    D[i] = S - C[0][i] + C[1][i]
  }
  for _, a := range A {
    Write(D[a])
  }
}

func main() {
  Solve()
  Output()
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan_init()
	n:= scanInt()
	a:=make([]int, n)
	memo := make(map[int]int)
	for i:= 0; i<n; i++ {
		a[i] = scanInt()
		if _,ok := memo[a[i]]; !ok {
			memo[a[i]] = 0
		}
		memo[a[i]]++
	}
	// fmt.Println("aa")
	for i:= 0; i<n; i++ {
		sum := 0
		memo[a[i]]--
		for _,value := range  memo {
			if value == 1 || value == 0 {
				continue
			}
			sum += (value*(value-1))/2
		}
		fmt.Println(sum)
		memo[a[i]]++
	}

}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	m := make(map[int]int)
	for _, ai := range A {
		m[ai]++
	}
	for _, ai := range A {
		m[ai]--
		c := 0
		for _, v := range m {
			if v > 1 {
				c += v * (v - 1) / 2
			}
		}
		m[ai]++
		fmt.Println(c)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

// O(N^2)
// 配列Aを作成
// 数値に対して、値の出現数を記録したハッシュテーブルを作成
// ハッシュテーブルの値に対して、組み合わせ数を記録したハッシュテーブルを作成

func fact(n int) int {
	if n == 0 {
		return 1
	}
	a := 1
	for n != 0 {
		a *= n
		n = n - 1
	}
	return a
}

func combinationTwo(a int) int {
	if a == 0 || a == 1 {
		return 0
	}
	if a == 2 {
		return 1
	}
	return fact(a) / (2 * fact((a - 2)))
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var a = make([]int, n)
	var values = make(map[int]int)
	var combinations = make(map[int]int)
	var all int
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		values[a[i]]++
	}
	for k, v := range values {
		combi := combinationTwo(v)
		combinations[k] = combi
		all += combi
	}
	for i := 0; i < n; i++ {
		k := a[i]
		balls := values[k] - 1
		combi := combinations[k]
		newCombi := combinationTwo(balls)
		pattern := all + newCombi - combi
		fmt.Println(pattern)
	}
}
//  [ruby]
def main(str)
  lines = str.split("\n").map { |x| x.split(' ').map(&:to_i) }
  _n = lines[0][0]
  as = lines[1]
  counts = as.each_with_object(Hash.new(0)) { |x, m| m[x] += 1 }
  counts_sum = counts.values.map { |x| (x * (x-1))/ 2 }.sum
  as.map do |a|
    val = counts[a]
    counts_sum - (val * (val - 1)) / 2 + ((val - 1) * (val - 2)) / 2
  end.join("\n")
end

unless ENV["TEST"]
  puts(main($stdin.read.chomp))
  exit(0)
end

require 'minitest/autorun'

class TestA < Minitest::Test
  def test_main
    assert_equal("2
2
3
2
3", main("5
1 1 2 1 2"))
    assert_equal("0
0
0
0", main("4
1 2 3 4"))
    assert_equal("6
6
6
6
6", main("5
3 3 3 3 3"))
    assert_equal("5
7
5
7
7
5
7
5", main("8
1 2 1 4 2 1 4 1"))
  end
end
//  [ruby]
N = gets.to_i
num = gets.strip.split.map(&:to_i)
i = 0
ary = Array.new(N,0)
while i < N do
  ary[num[i]-1] += 1
  i += 1
end
sum = 0
j = 0
while j < N do
  sum += ary[j]*(ary[j]-1)/2 #すべての場合
  j += 1
end
k = 0
while k < N do
  puts sum-ary[num[k]-1]+1
  k += 1
end
//  [ruby]
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @a = gets.to_s.split.map{ |v| v.to_i }
    @h = a.tally
    @t = h.map{|k,v|v*(v-1)/2}.sum
  end

  def solve
    n.times.map do |i|
      t - h[a[i]] + 1
    end
  end

  def show(ans)
    ans.each do |v|
      puts v
    end
  end
end

Problem.new.instance_eval do
  show(solve)
  # pp self
end

# n * (n-1) / 2
# - (n-1) * (n-2) / 2
# = n-1
//  [ruby]
n=gets.to_i
a=gets.split.map(&:to_i)
h=Hash.new(0)
a.each{|i|h[i]+=1}
a.each do |i|
  ans=0
  h.each do |k,c|
    c-=1 if k == i
    ans+=c*(c-1)/2
  end
  puts ans
end
//  [ruby]
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
a.each do |i|
    hash[i] += 1
end
hash_2 = Hash.new(0)
arr = Array.new(n+1,0)
count = 0
hash.each do |i|
    #p i
    ans =  (i[1] * (i[1] - 1)) / 2
    hash_2[i[0]] = ans
    #p ans
    count += ans
end
p hash_2
a.each do |j|
    point = hash_2[j]
   # p point
  # puts "UU"
  # p j
    sa_1 = (hash[j] * (hash[j] - 1)) / 2
    #p sa_1
    sa_2 = [((hash[j]-1) * (hash[j] - 2)) / 2,0].max
    #p sa_2
    count = count - sa_1 + sa_2
    puts count
    count = count + (sa_1 - sa_2)
    #puts count
    #puts "KKK"
end
//  [ruby]
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
a.each do |i|
    hash[i] += 1
end
n.times do |j|
    hash[a[j]] -= 1
    count = 0
    hash.each do |i|
        ans =  (i[1] * (i[1] - 1)) / 2
        count += ans
    end
    puts count
    hash[a[j]] += 1
end
//  [rust]
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [usize1; n],
  }
  let mut popl = vec![0i64; n];
  for &x in &a {
    popl[x] += 1;
  }
  let mut all = 0;
  for i in 0 .. n {
    all += popl[i] * (popl[i] - 1) / 2;
  }
  for i in 0 .. n {
    puts!("{}\n", all - popl[a[i]] + 1);
  }
}