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



Sample input:
5
1 1 2 1 2


Sample output:
2
2
3
2
3

Submission status: Wrong Answer

Solution code:
import collections
import math
 
def combinations_count(n, r):
  if n == r:
    return 1
  elif n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input().strip())
A = list(map(int, input().strip().split()))

combi = collections.Counter(A)
new_combi = {}
ans_dict = {}
combi_dict = {}
for k, v in combi.items():
  if v > 1:
    new_combi[k] = v
#print(combi)

for i in range(N):
  ans = 0
  dec = False
  
  if A[i] in ans_dict:
    ans = ans_dict[A[i]]
    #print('from dict: ' + str(ans))
  
  # i番目の要素をcombiからdecrement
  elif A[i] in new_combi:
    new_combi[A[i]] -= 1
    dec = True
    for v in new_combi.values():
      #print(v)
      if v in combi_dict:
        ans += combi_dict[v]
      else:
        r = combinations_count(v, 2)
        ans += r
        combi_dict[v] = r
        
    ans_dict[A[i]] = ans
    #print('from calc: ' + str(ans))
    
  print(ans)

  # i番目の要素をcombiからincrement
  if dec:
    new_combi[A[i]] += 1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3

import sys
sys.setrecursionlimit(10 ** 6)
memo = [1, 1]
def fact(n):
	if len(memo) > n:
		return memo[n]
	else:
		for i in range(len(memo), n+1):
			memo.append(memo[i-1] * i)
		return memo[n]
def main():
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	cnt = {}
	sumcase = 0
	for i in range(n):
		cnt[a[i]] = cnt.get(a[i], 0) + 1
	print(a, cnt)
	for ai in cnt:
		if cnt[ai] >= 2:
			sumcase += fact(cnt[ai]) // fact(2) // fact(cnt[ai]-2)
	for i in range(n):
		if cnt[a[i]] == 2:
			print(sumcase - fact(cnt[a[i]]) // fact(2) // fact(cnt[a[i]]-2))
		elif cnt[a[i]] > 2:
			#print("hoge", a,  cnt[a[i]], sumcase, cnt)
			print(sumcase - fact(cnt[a[i]]) // fact(2) // fact(cnt[a[i]]-2) + fact(cnt[a[i]]-1) // fact(2) // fact(cnt[a[i]]-3))
		else:
			print(sumcase)
main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)

    for i in A:
        C[i] += 1


    b = 0
    print(C)
    for cnt in C:
        b += ((cnt * (cnt - 1)) // 2)

    for i in range(N):
        p = ((C[A[i]] - 1) * (C[A[i]] - 2)) >> 1
        m = (C[A[i]] * (C[A[i]] - 1)) >> 1
        print(b - m + p)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

from operator import mul
from functools import reduce
from functools import lru_cache

N = int(input())
A_list = [int(e) for e in input().split()]

#ある番号のボールが何個あるかをまとめる
number_dict = dict()

for i in range(N):
    ball_number = A_list[i]
    if ball_number not in number_dict:
        number_dict[ball_number] = 0
        
    number_dict[ball_number] += 1

#それぞれの番号のボールから2個選ぶ組み合わせをカウントする。
comb_dict = dict()

@lru_cache(maxsize=100000000)
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
    
@lru_cache(maxsize=100000000)
def two_choice(N):
    if N == 2:
        return 1
    elif N <= 1:
        return 0
    elif N == 3:
        return 3
    else:
        return combinations_count(N,2)*combinations_count(N-2,2)

all = 0

for in_dict in number_dict.items():
    ball_number = in_dict[0]
    balls = in_dict[1]
    comb_dict[ball_number] = two_choice(balls)
    all += comb_dict[ball_number]

#回答作成
for i in range(1,N+1):
    ball_number = A_list[i-1]
    now_balls = number_dict[ball_number] - 1
    print(int(all-comb_dict[ball_number]+two_choice(now_balls)))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)

    for i in A:
        C[i] += 1


    b = 0
    print(C)
    for cnt in C:
        print('b', 'cnt', b, cnt)
        b += ((cnt * (cnt - 1)) // 2)

    for i in range(N):
        p = ((C[A[i]] - 1) * (C[A[i]] - 2)) >> 1
        m = (C[A[i]] * (C[A[i]] - 1)) >> 1
        print(b - m + p)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

c = Counter(a)


res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if i == a[k-1]:
            quant = c[i] - 1
        else:
            quant = c[i]
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
import collections


def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)
ans_dict_1 = {}
ans_dict_2 = {}

for k, v in counter.items():
    if v >= 2:
        ans_dict_1[k] = C(v, 2)
    if v >= 3:
        ans_dict_2[k] = C(v - 1, 2)
total_w = sum(ans_dict_1.values())

for k in range(N):
    n = a_list[k]

    if counter[n] >= 3:
        w = total_w - ans_dict_1[n] + ans_dict_2[n]
    elif counter[n] >= 2:
        w = total_w - ans_dict_1[n]
    else:
        w = 0
    print(w)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
count = [0 for i in range(n+1)]
ans = 0
for i in range(n):
    count[a[i]] += 1
for i in range(n):
    ans += count[i]*(count[i]-1)//2
for i in range(n):
    num = count[a[i]]

    print(ans-(num*(num-1)//2)+(num-1)*(num-2)//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=A
S=list(set(B))
m=[]
for i in range(len(S)):
  B.remove(S[i])
  sum=0
  for j in range(len(S)):
    a=B.count(S[j])
    if a!=1:
      sum+=a*(a-1)//2
  m.append(sum)
  B.append(S[i])
for i in range(N):
  for j in range(len(S)):
    if A[i]==S[j]:
      print(m[j])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
from collections import Counter
MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans


d=Counter(a)
tni=0
df=d.items()
dv=d.values()
dv=list(dv)
for i in range(len(dv)):
    tni+=comb(int(dv[i]),2)

ans=[]
for i in range(n):
    r=d[a[i]]
    print(tni-(r-1))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from bisect import bisect_left

def f(i, d, dsum, n):
    return func(i, d) + dsum[i] + dsum[n] - dsum[i+1]

def func(i, w):
    return w[i][1] * max(0, w[i][1]-1) // 2

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    w = []
    for k in sorted(d.keys()):
        w.append([k, d[k]])
    m = len(w)
    c = [0] * (m+1)
    for i in range(1, m+1):
        c[i] = c[i-1] + func(i-1, w)
        # print(func(i-1, w))
    q = [u for u in w[0]]
    # print(c)
    # print(w)
    for i in v:
        g = bisect_left(q, i)
        w[g][1] -= 1
        print(f(g, w, c, m))
        w[g][1] += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

N = int(input())
A = list(map(int,input().split()))

dic = dict()
memo = [-1] * (N+1)
ans_vec = [-1] * (N+1) 

for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1

tmp = 0
for d in dic.values():
    if d >= 2:
        memo[d] = comb(d,2,exact=True)  
        memo[d-1] = comb(d-1,2,exact=True)   
        tmp += memo[d] 

for a in A:
    ans = 0
    t = dic[a]
    if ans_vec[t] != -1:
        print(ans_vec[t])
    else:
        if t >= 2:
            ans = tmp - memo[t] 
        if t-1 >= 2:
            ans += memo[t-1]
        ans_vec[t] = ans
        print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = list(map(int,input().split()))

C =[0]*N
for i in range(N):
    C[A[i]-1] +=1

dammy = 0
for i in range(N):
    if C[i] >=2:
        dammy = dammy + (C[i] * (C[i]-1)) /2

for i in range(N):
    if C[A[i]-1] ==0:
        print(int(dammy))
    elif C[A[i]-1] ==1:
        out = int(dammy-2)
        if out<0:
            out=0
        print(out)
    else:
        out = int(dammy-C[A[i]-1]+1)
        if out<0:
            out=0
        print(out)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
numlist = list(map(int, input().split()))
dic = {}
for num in numlist:
  if num not in dic:
    dic[num] = 1
  else:
    dic[num] += 1
    
ansdic = {}
for key in dic.keys():
  n = dic[key]
  ansdic[key] = [int(n*(n-1)/2),int((n-1)*(n-2)/2)]
      
ansdic2 = {}
for key in ansdic.keys():
  sum = 0
  for key2 in ansdic.keys():
    if key == key2:
      sum += ansdic[key][1]
    else:
      sum += ansdic[key][0]
    ansdic2[key] = sum  
    
for num in numlist:
  print(ansdic2[num])

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
a2=copy.copy(a)
for i in a2:
    a.append(i)
    ad=a[i+1:n+i]
    ans = 0
    adset=list(set(ad))
    for j in adset:
        k = ad.count(j)
        if(k >= 2):
           ans += (k*(k-1))//2
        else:
            continue
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

def countComb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
NN = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, NN + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N = int(input())
A = list(map(int, input().split()))

memo = [0 for _ in range(N)]
for a in A:
  memo[a-1] += 1

memo1 = [0 for _ in range(N)]
for n in range(N):
  memo1[n] = countComb(memo[n], 2, p)

total = sum(memo1)
for k in range(N):
  a = A[k]-1
  answer = 0
  answer += total
  answer -= memo1[a]
  answer += countComb(memo[a] - 1, 2, p)
  print(answer)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
nMax = 2 * 10 ** 5
lmemo = [-1] * (nMax + 1)
def fperm(a, b):
  if a < b:
    return 0
  nump = 1
  for i in range(b, a + 1):
    nump *= i
  return nump

def fcomb(a, b):
  if a < b:
    return 0
  if lmemo[a] != -1:
    return lmemo[a]
  else:
    lmemo[a] = fperm(a, b) // math.factorial(b)
    return lmemo[a]
  
l = {}
ldef = [0] * (nMax + 1)

ak = list(map(int, input().split()))
numMax = 0
for num in ak:
  if num in l:
    l[num] += 1
  else:
    l[num] = 1
ctotal = 0
for i in l:
  if l[i] >= 2:
    com = fcomb(l[i], 2)
    ctotal += com
    ldef[i] = fcomb(l[i] - 1, 2) - com
for num in ak:
  total = ctotal + ldef[num]
  print(total)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
c = collections.Counter(a)

a1=len(list(set(a)))

total=0
for j in range(a1):
    x=c.most_common()[j][1]
    total+=x*(x-1)/2
    print('total',total)

for i in range(n):
    ans=total-a.count(a[i])+1
    print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

n = int(input())
a = list(map(int,input().split()))
ans = 0

for k in range(n):
    c = a[k]
    del a[k]
    for v in range(1,n+1):
        co = a.count(v)
        co2 = co - 1
        if co >= 2:
            ans += co*co2/2
    ans = 0
    print(int(ans))
    a.append(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int,input().split()))
for i in range(N):
    array1 = array.copy()
    array1.pop(i)
    SET = set(array1)
    for j in list(SET):
        if(array1.count(j) <= 1):
            print(0)
            pass
        else:
            count = array1.count(j)
            print((count*(count-1))//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
values = list(map(int, input().split(' ')))



count = {}
for i in range(N):
    if values[i] not in count:
        count[values[i]] = 1
    else:
        count[values[i]] = count[values[i]] + 1

for i in range(N):
    temp = count
    temp[values[i]] = temp[values[i]] - 1
    num = 0
    for j in temp:
        num = num + int(temp[j]*(temp[j]-1)/2)
    print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
balls = input().split()
for i in range(n):
  balls[i] = int(balls[i])
for j in range(n):
  ans = 0
  len_n = 0
  for k in range(n):
    if len_n + balls.count(k) >= n:
      break
    if balls[j] == k:
      ans += (balls.count(k) - 1) * (balls.count(k) - 2) / 2
    else:
      ans += balls.count(k) * (balls.count(k) - 1) / 2
  print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys, math

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
A = read_int()

d = defaultdict(lambda: int())
for a in A:
    d[a] += 1

def combinations_count(n, r):
    if n - r < 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = len(d)
comn2 = [0 for _ in range(N + 1)]
def solve():
    all = 0
    for k, v in d.items():
        all += combinations_count(v, 2)
        comn2[v] = combinations_count(v, 2)
        comn2[v - 1] = combinations_count(v - 1, 2)
    print(comn2, all)
    for a in A:
        res = all - comn2[d[a]] + comn2[d[a] - 1]
        print(res)
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
answer = 0
answer1 = 0

for i in range(max(a)):
  answer += a.count(i + 1) * (a.count(i + 1) -1) // 2

for k in range(n):
  if a.count(a[k]) > 2:
    answer1 = answer - (a.count(a[k]) - 1)
  print(answer1)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
k=0
c=collections.Counter(a)
for i in range(a[-1]):
  v=c[i+1]
  k+=v*(v-1)//2
for i in a:
  ans=k-a.count(i)+1
  print(ans)

Submission status: Wrong Answer

Solution code:
ball_value=int(input())
ball_number=list(map(int,input().split()))
i=0

for i in range(ball_value):
    counter=ball_number.count(ball_number[i])-1
    print(counter)

Submission status: Wrong Answer

Solution code:
import math

past_ans = {}

def solve(k, arr):
    all_ans = {}
    tmp_arr = []
    tmp_arr.extend(arr)
    deleted_num = tmp_arr.pop(k)

    # 過去に計算していた場合
    if k in past_ans:
        return past_ans[k]

    # 新しく計算する場合
    set_arr = []
    set_arr = list(set(tmp_arr))
    ans = 0
    for i in set_arr:
        # iを過去に計算していた場合
        if i in all_ans:
            ans += all_ans[i]
        else:
            all_ans[i] = combinations_count(tmp_arr.count(i), 2)
            ans += all_ans[i]
    past_ans[deleted_num] = ans
    return ans

def combinations_count(count, r):
    if count <= 1:
        return 0
    return math.factorial(count) // (math.factorial(count - r) * math.factorial(r))

if __name__ == "__main__":
    n = int(input())
    arr = [int(s) for s in list(input().split())]
    [print(solve(k, arr)) for k in range(n)]

Submission status: Wrong Answer

Solution code:
from math import factorial
def cmb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))
##################################################

n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
    a1 = a[:int(i)] + a[int(i + 1):]
    #print(a1) #a1 check
    for j in range(n):
        if j in a1 == True:
            b = a1.count(j + 1)
            if b <= 1:
                pass
            else:
                ans += cmb(b, 2)
        #print(ans)
    print(ans)

    ans = 0 # initiation of the variant 'ans'

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

c = Counter(a)


res = []
for k, __ in enumerate(list(range(n)), 1):
    part_res = 0
    for i in c.keys():
        if i == a[k-1]:
            quant = c[i] - 1
        else:
            quant = c[i]
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

print(res)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
nMax = 2 * 10 ** 5
lmemo = [-1] * (nMax + 1)
def fperm(a, b):
  if a < b:
    return 0
  nump = 1
  for i in range(b, a + 1):
    nump *= i
  return nump

def fcomb(a, b):
  if a < b:
    return 0
  if lmemo[a] != -1:
    return lmemo[a]
  else:
    return fperm(a, b) // math.factorial(b)
  
l = {}
ldef = [0] * (nMax + 1)

ak = list(map(int, input().split()))
numMax = 0
for num in ak:
  if num in l:
    l[num] += 1
  else:
    l[num] = 1
ctotal = 0
for i in l:
  if l[i] >= 2:
    com = fcomb(l[i], 2)
    ctotal += com
    ldef[i] = fcomb(l[i] - 1, 2) - com
for num in ak:
  total = ctotal + ldef[num]
  print(total)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, *D  = [list(map(int, s.split())) for s in open(0)]
D = D[0]
dic = defaultdict(int)
for d1 in D:
    dic[d1] += 1

total_comb = 0
for k in dic:
    if dic[k] >= 2:
        total_comb += dic[k] * (dic[k] - 1) / 2

for d2 in D:
    comb = 0
    if dic[d2] >= 2:
        print(int(total_comb - dic[d2] + 1))
    else:
        print(total_comb)

Submission status: Wrong Answer

Solution code:
N = int(input())
data = [i for i in input().split()]

number_count = {}
for cmp in data:
    if cmp in number_count:
        number_count[cmp] += 1
        continue
    number_count[cmp] = 1

answer = {}
for i in range(N):
    if data[i] in answer:
        print(answer[data[i]])
        continue
    C = 0
    number_count_temp = number_count.copy()
    number_count_temp[str(data[i])] -= 1
    for cmp in number_count_temp:
        C += int(number_count_temp[cmp] * (number_count_temp[cmp] - 1) / 2)

    print(str(C))
    answer[data[i]] = str(C)
    print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
num = [0]*n
import numpy as np
for i in A:
  num[i-1] += 1
num = np.array(num)
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = np.sum(np.array(num))
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
from collections import defaultdict

n = int(sys.stdin.readline())
a = ''.join(sys.stdin.readline().split())
c = Counter(a)

total_comb_num = sum(map(lambda v: max(v*(v-1)//2, 0), c.values()))
for num in a:
    x = c[num]
    print(total_comb_num + max((x-1)*(x-2)//2, 0) - max((x*(x-1)//2, 0)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ua=list(set(a))
d={}
total=0
for i in range(n):
    y=a[i]
    if y in d:
        print(d[y])
        continue
    if ua:
        for x in ua:
            c = a.count(x)
            if c==1:
                ua.remove(x)
            total+=sum(range(c - (1 if x==y else 0)))
        print(total)
        d[y]=total
        total=0
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=[0]*200001##個数
s=0
t=0
nsum=0
for i in range(n):
    c[a[i]]+=1
for j in range(n):
    nsum+=max(c[j]*(c[j]-1)//2,0)
for k in range(n):
    t=(nsum+1-c[a[k]])
    print(int(t))

Submission status: Wrong Answer

Solution code:
n = int(input())
list = list(map(int,input().split()))
di = {}
for i in range(n):
	k = list[i]
	if k not in di:
		di[k]=1
	else:
		di[k]+=1
list_del=[]
for key in di.keys():
	if di[key]==1:
		list_del.append(key)
for i in range(len(list_del)):
	di.pop(list_del[i])
	
	
su=0
for valu in di.values():
	su += valu*(valu-1)/2
	
for i in range(n):
	k = list[i]
	if k in di:
		l = di[k]
		su_ch = su
		su_ch -= l*(l-1)/2
		su_ch += (l-1)*(l-2)/2
		print(int(su_ch))
	else:
		print(su)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = input()
res = list(map(int,input().split()))
a = Counter(res)
for i in a.keys():
    a[i] -= 1
    sums = 0
    for j in a.values():
        sums += j * (j - 1) // 2
    a[i] += 1
    res = [sums if x == i else x for x in res]
for k in res:
    print(k)

Submission status: Wrong Answer

Solution code:
#N = int(raw_input())
#A = map(int, raw_input().split())

N = 200000
A = [200000]*N

count = [0]*(N+2)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1

sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)

#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0 for _ in range(n + 10)]

for i in range(n):
    c[a[i]] += 1


ans = 0
for i in range(n):
    ans += c[i] * (c[i] - 1) / 2

for i in range(n):
    r = a[i]
    tmp = ans - c[r] * (c[r] - 1) / 2 + (c[r] - 1) * (c[r] - 2) / 2
    print(tmp)

Submission status: Wrong Answer

Solution code:
import collections
import math
 
def combinations_count(n, r):
  if n == r:
    return 1
  elif n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input().strip())
A = list(map(int, input().strip().split()))

combi = collections.Counter(A)
new_combi = {}
ans_dict = {}
for k, v in combi.items():
  if v > 1:
    new_combi[k] = v
#print(combi)

for i in range(N):
  ans = 0
  dec = False
  
  if A[i] in ans_dict:
    ans = ans_dict[A[i]]
    #print('from dict: ' + str(ans))
  
  # i番目の要素をcombiからdecrement
  elif A[i] in new_combi:
    new_combi[A[i]] -= 1
    dec = True
    for v in new_combi.values():
      #print(v)
      ans += combinations_count(v, 2)
    ans_dict[A[i]] = ans
    #print('from calc: ' + str(ans))
    
  print(ans)

  # i番目の要素をcombiからincrement
  if dec:
    new_combi[A[i]] += 1

Submission status: Wrong Answer

Solution code:
import itertools
import collections

N = int(input())
AList = input().split(" ")

for k in range(1, N + 1):
    count = 0
    tempList = collections.Counter([element for index, element in enumerate(AList) if k != index + 1])
    
    if len(tempList.keys()) == 1:
        print(len(list(itertools.combinations(range(len(tempList)), 2))))
        continue

    else:
        for c in tempList.values():
            count += len(list(itertools.combinations(range(c), 2)))
            
        print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
  print(i)

Submission status: Wrong Answer

Solution code:
import collections
MOD = 10**15+7
n = int(input())
a = list(map(int, input().split()))
b = [[0 for j in range(2)] for i in range(n)]
c = collections.Counter(a)
s = 0
def nCr(nn, r, mod):
	r = min(r, nn-r)
	numer = denom = 1
	for i in range(1, r+1):
		numer = numer * (nn+1-i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod-2, mod) % mod
for i in c:
	if c[i] < 2:
		b[i-1][0] = 0
	else:
		b[i-1][0] = nCr(c[i],2,MOD)
		s += b[i-1][0]
	if c[i]-1 < 2:
		b[i-1][1] = 0
	else:
		b[i-1][1] = nCr(c[i]-1,2,MOD)
for i in a:
	ans = s-b[i-1][0] + b[i-1][1]
	print (ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from functools import lru_cache

N = int(input())
A_list = [int(e) for e in input().split()]

number_dict = dict()

for i in range(N):
    if A_list[i] not in number_dict:
        number_dict[A_list[i]] = 0
        
    number_dict[A_list[i]] += 1

comb_dict = dict()

@lru_cache(maxsize=100000000)
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
    
@lru_cache(maxsize=100000000)
def two_choice(N):
    if N == 2:
        return 1
    elif N <= 1:
        return 0
    elif N == 3:
        return 3
    else:
        return combinations_count(N,2)*combinations_count(N-2,2)

all = 0

for in_dict in number_dict.items():
    ball_number = in_dict[0]
    balls = in_dict[1]
    #print(ball_number,balls)
    comb_dict[ball_number] = two_choice(balls)
    all += comb_dict[ball_number]

#print(number_dict[ball_number])

for i in range(1,N+1):
    ball_number = A_list[i-1]
    now_balls = number_dict[ball_number] - 1
    #print(i,ball_number,all,comb_dict[ball_number],two_choice(now_balls))
    print(int(all-comb_dict[ball_number]+two_choice(now_balls)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	ap = {}
	for i in A:
		if i in ap:
			ap[i] += 1
		else:
			ap[i] = 1

	mmax = 0
	for k, v in ap.items():
		if v > 1:
			mmax += cmb(v, 2)

	#print(mmax)
	for i in A:
		if mmax == 0:
			print(0)
			continue
		conts = ap[i]
		conts2 = conts -1
		#print("{} {}".format(conts, conts2))

		m = cmb(conts, 2)
		p = cmb(conts2, 2)

		#print("{} {}".format(m, p))
		if conts < 3:
			p = 0
		#print("{} {}".format(m, p))
		aaa = mmax - m + p
		print(aaa)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))

# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

N = int(input())
A = list(map(int,input().split()))

dic = dict()

for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1

tmp = 0
for d in dic.values():
	tmp += comb(d,2,exact=True) 

for a in A:
    ans = 0
    t = dic[a]
    ans = tmp - comb(t,2,exact=True) + comb(t,2,exact=True)
    print(ans)