TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
from math import factorial

N = int(input())
index = list(map(int, input().split()))
val = [0]*max(index)
for i in index:
    val[i-1] += 1
total = 0
for i in val:
    if i >= 2:
        total += comb(i, 2, exact=True)
for i in index:
    if val[i-1] >= 2:
        print(total-(comb(val[i-1], 2, exact=True)-comb(val[i-1]-1, 2, exact=True)))
    else:
        print(total)


from scipy.special import comb

N = int(input())
index = list(map(int, input().split()))
val = [0]*max(index)
for i in index:
    val[i-1] += 1
total = 0
for i in val:
    if i >= 2:
        total += comb(i, 2, exact=True)
for i in index:
    if val[i-1] >= 2:
        print(total-(comb(val[i-1], 2, exact=True)-comb(val[i-1]-1, 2, exact=True)))
    else:
        print(total)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
N = int(input())
A = list(map(int, input().split()))
wlists = collections.Counter(A)
print(wlists)
print(wlists[1])
print(wlists[2])
sum_num = 0
for i in wlists:
  sum_num += wlists[i] * (wlists[i] - 1) // 2
print("num_sum:{}".format(sum_num))
for i in range(N):
  num = sum_num - wlists[A[i]] * (wlists[A[i]] - 1) // 2
  if wlists[A[i]] > 1:
    num += (wlists[A[i]] - 1) * (wlists[A[i]] - 2) // 2
  print(num)

import collections
N = int(input())
A = list(map(int, input().split()))
wlists = collections.Counter(A)
sum_num = 0
for i in wlists:
  sum_num += wlists[i] * (wlists[i] - 1) // 2
for i in range(N):
  num = sum_num - wlists[A[i]] * (wlists[A[i]] - 1) // 2
  if wlists[A[i]] > 1:
    num += (wlists[A[i]] - 1) * (wlists[A[i]] - 2) // 2
  print(num)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
for k in l:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)


import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
ans=0
for k in an:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
input()
aa = list(map(int, input().split()))
uu = list(set(aa))
cc = uu.copy()
for i in range(len(uu)):
    cc[i] = aa.count(uu[i])
    total += cc[i] * (cc[i]-1) / 2

dic = dict(zip(uu,cc))

for a in aa:
    print(int(total - dic[a] + 1))

input()
from collections import Counter
aa = list(map(int, input().split()))
dic = Counter(aa)

total = 0
for v in dic.values():
    total += v * (v-1) / 2

for a in aa:
    print(int(total - dic[a] + 1))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
A = list(map(int, input().split()))

setA = set(A)
an = 0
for num in B:
    d = A.count(num)
    an += d*(d-1)//2

for i in range(n):
    ans = an
    t = A[i]
    e = A.count(A[i])
    ans -= e*(e-1)//2
    ans += (e-1)*(e-2)//2
    print(ans)

n = int(input())

li = list(map(int, input().split()))

ans = [0]*n
for i in range(n):
    li2 = li
    del li2[i]
    for j in range(n-1):
        for k in range(j+1, n-1):
            if li2[j] == li2[k]:
                ans[i] += 1
for l in range(len(ans)):
    print(ans[l])
 


N=int(input())
K=list(map(int, input().split()))
from collections import Counter
ans = 0
for i in range(N):
    ans += i*(i-1)//2
C = Counter(K)
for a in K:
    e = C[a]
    print(ans-a*(a-1)//2+(a-1)*(a-2)//2)

N=int(input())
K=list(map(int, input().split()))
from collections import Counter
ans = 0
C = Counter(K)
for k, v in C.items():
    ans += v*(v-1)//2

for a in K:
    e = C[a]
    print(ans-e*(e-1)//2+(e-1)*(e-2)//2)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

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

s = Counter(c)
t = list(s.items())

nag = len(t)
x = 0
rt = [0 for i in range(nag)]
print(s)

for i in range(nag):
    x += (t[i][1]*(t[i][1]-1))//2
for f in range(nag):
    rt[f] = x - (t[f][1] -1)
  
for j in range(n):
    for k in range(nag):
        if c[j] == t[k][0]:
            print(rt[k])
            break


from collections import Counter

n = int(input())
c = list(map(int,input().split()))
s = Counter(c)
t = list(s.items())
nag = len(t)
x = 0
ans = 0

for i in range(nag):
    x += (t[i][1]*(t[i][1]-1))//2
    
for j in range(n):
    ans = x - s[c[j]] + 1 
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
#from scipy.special import comb
# a = comb(n, r)
# >> cannot use in Contest (like AtCoder)


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


N = int(input())
data = list(map(int, input().split()))
count = Counter(data)
#print(count) > Counter({1: 4, 2: 2, 4: 2})
countMost = count.most_common()

lis = [0] * (2 * 10 ** 5)
tot = 0
for i, v in countMost:
    #print(i, v)
    lis[i - 1] = v
    tot += cmb(v, 2)

for i, v in enumerate(data):
    num = lis[v-1]
    ans = tot - cmb(num - 1, 2)

    print(ans)
'''
dataSort = data.sort()
print(countMost)
print(len(countMost))
'''


from collections import Counter
#from scipy.special import comb
# a = comb(n, r)
# >> cannot use in Contest (like AtCoder)


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
    if n <= 1:
        return 0

    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


N = int(input())
data = list(map(int, input().split()))
count = Counter(data)
#print(count) > Counter({1: 4, 2: 2, 4: 2})
countMost = count.most_common()

lis = [0] * (2 * 10 ** 5)
combination = [0] * (2 * 10 ** 5)
tot = 0
for i, v in countMost:
    #print(i, v)
    lis[i - 1] = v
    val = cmb(v, 2)
    tot += val
    combination[i - 1] = val

# print(lis[0])
for i, v in enumerate(data):
    num = lis[v - 1]
    if (num == 2):
        #    print('a')
        ans = tot - 1
    else:
        ans = tot - combination[v-1] + cmb(num-1, 2)

    print(ans)
'''
dataSort = data.sort()
print(countMost)
print(len(countMost))
'''


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))



def choose2(n):
    return n*(n-1)/2
  

N = get_int()
An = get_ints()

uni = [0] * (N+1)

for i in range(N):
    uni[An[i]] += 1
sumWay = 0

for i in range(N):
    sumWay += choose2(uni[i])

for i in range(N):
    print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) 


def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))

def choose2(n):
    return n*(n-1)/2

N = get_int()
An = get_ints()

uni = [0] * (N)

for i in range(N):
    uni[An[i]] += 1
sumWay = 0

for i in range(N):
    sumWay += choose2(uni[i])

for i in range(N):
    print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) 
# 4 - 3 + 1



def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))

import math

def choose2(n):
    return math.floor(n*(n-1)/2)


N = get_int()
An = get_ints()

uni = [0] * (N+1)

for i in range(N):
    uni[An[i]] += 1
sumWay = 0

for i in range(N+1):
    sumWay += choose2(uni[i])

for i in range(N):
    print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) 

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8

import collections
import copy


N = int(input())


A = list(map(str, input().split()))

print(A)
for _N in range(N):
  A2 = copy.copy(A)
  del A2[_N]
  c = collections.Counter(A2)
  ans = 0
  for v in c.values():
    if v >= 2:
      ans += int(((v * (v - 1)) / 2))
  print(ans)


# coding: utf-8

import collections
import copy


N = int(input())


A = list(map(str, input().split()))

c = collections.Counter(A)
nodel = 0

for cv in c.values():
  if cv >= 2:
    nodel += int((cv * (cv-1))/2)

for a in A:
  ans = copy.copy(nodel)
  if c.get(a) >= 3:
    ans = ans - int((c.get(a)*(c.get(a)-1))/2) + int(((c.get(a)-1)*(c.get(a)-2))/2)
  elif c.get(a) == 2:
    ans -= 1
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10000000000000)

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


comb_dict = dict()

@lru_cache(maxsize=10000000000000)
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=10000000000000)
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)))

import sys
sys.setrecursionlimit(1000000000)

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


comb_dict = dict()

@lru_cache(maxsize=10000000000000)
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=10000000000000)
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
l = []
total = 0

m = max(a)

for i in range(1, m+1):
    if a.count(i):
        total += (a.count(i)*(a.count(i)-1))/2
    l.append(a.count(i))

print(l)
print(total)

for k in range(n):
    score = total
    if l[a[k]-1]:
        score -= (l[a[k]-1]-1)
    print(int(score))


from collections import Counter

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

c = Counter(a)

for r in list(c.values()):
    total += (r*(r-1))/2

#print(l)
#print(total)

for i in a:
    score = total - (c[i]-1)
    print(int(score))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(d[i] + r)

n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
t = sum(d)
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(t - d[i] + r)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
inp = [input() for i in range(2)]
N = int(inp[0])
A = list(map(int, inp[1].split()))
# B = 0
d = {}
for k in A:
    # a = A.count(k)
    # B += (a - 1) / 2
    if k in d.keys():
        d[i] += 1

# for k in range(N):
#     c = A.count(A[k]) - 1
#     counter = B - c
#     print(int(counter))

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = cnt * (cnt-1) / 2

total = sum(p.values())

for item in A:
    print(int(total - d[item] + 1))

import math
inp = [input() for i in range(2)]
N = int(inp[0])
A = list(map(int, inp[1].split()))
# B = 0
d = {}
for k in A:
    # a = A.count(k)
    # B += (a - 1) / 2
    if k in d.keys():
        d[k] += 1
    else:
        d[k] = 1

# for k in range(N):
#     c = A.count(A[k]) - 1
#     counter = B - c
#     print(int(counter))

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = cnt * (cnt-1) / 2

total = sum(p.values())

for item in A:
    print(int(total - d[item] + 1))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

import sys
input = sys.stdin.readline

n = int(input())

balls = list(map(int, input().split()))

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)

print(total)

for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)


import sys
input = sys.stdin.readline

n = int(input())

balls = list(map(int, input().split()))

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)


for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))

Ad = {a_set:A.count(a_set) for a_set in A_set}

score_sum = sum([x*(x-1)/2 for x in list(Ad.values())]

for a in A:
    print(int(score_sum - (Ad[a] - 1)))


import collections

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

Ad = dict(collections.Counter(A))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
# Ad = {}

#   if not i in Ad:
#     Ad[i]=0
#   Ad[i] += 1

score_sum = sum([x*(x-1)/2 for x in list(Ad.values())])

for a in A:
    print(int(score_sum - (Ad[a] - 1)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=[int(s) for s in input().split()]
for i in range(0,n):
    print(a.count(a[i])-1)

n=int(input())
a=[int(s) for s in input().split()]
d={}
for i in range(0,n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1 
for i in range(0,n):
    print(d[a[i]]-1)

n=int(input())
a=[int(s) for s in input().split()]
d={}
for i in range(0,n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1 
d1={}
s=0
for i in range(0,n):
    if a[i] not in d1:
        d1[a[i]]=(d[a[i]]*(d[a[i]]-1))//2
        s+=d1[a[i]]
for i in range(0,n):
    print(s-d[a[i]]+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections

mod = pow(10,9)+7


memo = {}
def combination(n, a, mod):

    if (n,a) in memo:
        return memo[(n,a)]

    x = 1
    y = 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod

    ans = x * pow(y, mod-2, mod)%mod

    memo[(n, a)] = ans
    return ans

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all_cnt = 0 
    a_cnt = []


    for i in range(n):
        for item in c.items():
            cnt = combination(item[1],2,mod)
            all_cnt += cnt
            a_cnt.append(cnt - combination(item[1]-1,2,mod))

    for i in range(n):
        ans = all_cnt - a_cnt[i]
        print(ans)


import collections

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all = 0
    before = []
    after = []

    for i in range(n):
        for item in c.items():
            cnt = item[1]*(item[1]-1)//2
            all += cnt
            before.append(item[1]*(item[1]-1)//2)
            after.append((item[1]-1)*(item[1]-2)//2)

    for i in range(n):
        ans = all - before[i] + after[i]
        print(ans)


import collections

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all = 0

    for item in c.items():
        all += item[1] * (item[1] - 1) //2

    for i in range(n):
        item = c[a[i]]
        after = item * (item-1) // 2
        before = (item-1) * (item-2) // 2
        #print(after, before)
        ans = all - after + before
        print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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

    # print(N)
    # print(A)

    for i in range(N):
        result = 0
        for j in range(N):
            if A[i] == A[j]:
                result += 1
        print(result)




if __name__ == '__main__':
    main()


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

    print(N)
    print(A)

    for i in range(N):
        result = 0
        for j in range(N):
            if A[i] == A[j]:
                result += 1
        print(result)




if __name__ == '__main__':
    main()


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

    # print(N)
    # print(A)
    d = {i:0 for i in range(1,N+1)}
    d2 = {}
    d3 = {}
    # print(d)
    # return


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

    # print(d)
    sum = 0
    for i in range(1,N+1):
        d2[i] = int(d[i] * (d[i]-1) / 2)
        sum += d2[i]

    # print(d2)

    for i in range(1, N+1):
        if d[i] == 0: d3[i] = 0
        else: d3[i] = int((d[i]-1) * (d[i]-2) / 2)

    # print(d3)


    for i in A:
        print(sum - d2[i] + d3[i])

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
l = [0] * 100000
for i in A:
    l[i] += 1
c = 0
nums = [0] * N
for i in range(N):
    nums[i] = l[i] * (l[i] - 1) / 2
s = sum(nums)
for i in range(N):
    a = A[i]
    print(int(s - nums[a - 1] + (l[a] - 1) * (l[a] - 2) / 2))


N = int(input())
A = list(map(int, input().split()))
l = [0] * 10000001
for i in A:
    l[i] += 1
s = 0
for i in l:
    s += i * (i - 1) // 2
for a in A:
    a = l[a]
    print(s - (a * (a - 1) // 2) + ((a - 1) * (a - 2) // 2))


N = int(input())
A = list(map(int, input().split()))
l = [0] * 10000001
for i in A:
    l[i] += 1
s = 0
for i in range(N + 1):
    i = l[i]
    s += i * (i - 1) // 2
for a in A:
    a = l[a]
    print(s - (a * (a - 1) // 2) + ((a - 1) * (a - 2) // 2))


Verdicts: Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
b = [a.count(i+1) for i in range(n)]
d = []
for j in b:
    if j >= 2:
        d.append(factorial(j)//factorial(2)//factorial(j-2))
    else:
        d.append(0)

for k in a:
    if b[k-1] >= 3:
        u = b[k-1] 
        p = factorial(u-1)//factorial(2)//factorial(u-3)
        print(sum(d)-d[k-1]+p)
    else:
        print(sum(d)-d[k-1])

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

    

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    comb = 0
    for i in c.values():
        if i >= 2:
            comb += i*(i-1)/2
    for i in range(N):
        print(comb - (c[A[i]] - 1))

if __name__ == '__main__':
    main()

from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    comb = 0
    for i in c.values():
        if i >= 2:
            comb += i*(i-1)//2
    for i in range(N):
        print(comb - (c[A[i]] - 1))

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
C=Counter(a)
#print(C)
total=0
for k,v in C.items():
    if v>=2:
        total+=v*(v-1)//2
print(total)
for i in range(n):
    V=C[a[i]]
    ans=total-(V*(V-1))//2+((V-1)*(V-2))//2
    print(ans)

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
C=Counter(a)
#print(C)
total=0
for k,v in C.items():
    if v>=2:
        total+=v*(v-1)//2
#print(total)
for i in range(n):
    V=C[a[i]]
    ans=total-(V*(V-1))//2+((V-1)*(V-2))//2
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def nC2(n):
    return n*(n-1)/2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(n):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))

def nC2(n):
    return n*(n-1)//2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(1, n+1):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
n=int(input())
a=list(map(int,input().split()))
t=0
u=0
for i in range(n):
  if u!=n-1:
    m=a[i]
    del a[i]
    s=sorted(a)
    x=s.count(s[u])
    t+=math.factorial(x)//2
    u+=x
    a.insert(i,m)
  print(t)

from collections import Counter

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

c=Counter(a)
ans=0
for i in c.keys():
  ans+=(c[i]*(c[i]-1))//2

for i in a:
  print(ans-c[i]+1)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
import math
N = int(input())
A = list(map(int, input().split(' ')))
c = collections.Counter(A)
d1 = {}
d2 = {}
for i in c:
    d1[str(i)] = (c[i]*(c[i]-1))/2
    d2[str(i)] = ((c[i]-1)*(c[i]-2))/2

s = sum(d1.values())

print(c)
for i in range(N):
    ans = s - d1[str(A[i])]+d2[str(A[i])]
    print(int(ans))


import collections
import math
N = int(input())
A = list(map(int, input().split(' ')))
c = collections.Counter(A)
d1 = {}
d2 = {}
for i in c:
    d1[str(i)] = (c[i]*(c[i]-1))/2
    d2[str(i)] = ((c[i]-1)*(c[i]-2))/2

s = sum(d1.values())

for i in range(N):
    ans = s - d1[str(A[i])]+d2[str(A[i])]
    print(int(ans))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N= int(input())
A = list(map(int,input().split()))
B = []
C = []

for i in range(1,N+1):
    n = A.count(i)
    B.append(n*(n-1)//2)
    C.append((n-1)*(n-2)//2 if n >1 else 0)

B_sum = sum(B)
print(B)
print(C)

for i in range(N):
    a = A[i]-1
    print(B_sum-B[a]+C[a])

N= int(input())
A = list(map(int,input().split()))
B = [0] * N

for i in A:
    B[i-1] +=1

B_sum = 0
for i in B:
    B_sum += i * (i-1) //2

print(A,B,B_sum)
for i in range(N):
    print(B_sum-B[A[i]-1]+1)

N= int(input())
A = list(map(int,input().split()))
B = [0] * N

for i in A:
    B[i-1] +=1

B_sum = 0
for i in B:
    B_sum += i * (i-1) //2

for i in range(N):
    print(B_sum-B[A[i]-1]+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
B = []
S = 0

for i in range(1, N+1):
    B[i] = A.count(i)
    S += B[i]*(B[i]-1)/2

for i in range(N):
    if B[A[i]] < 2:
        print(S)
    else:
        print(S-B[A[i]]+1)

N = int(input())
A = list(map(int, input().split()))
B = []
S = 0

for i in range(1, N+1):
	B[i] = A.count(i)
	S += B[i]*(B[i]-1)/2

for i in range(N):
	if B[A[i]] < 2:
		print(S)
	else:
		print(S-B[A[i]]+1)

N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
S = 0

for i in range(N):
    B[A[i]] += 1

for i in range(1, N+1):
    S += B[i]*(B[i]-1)//2

for k in range(N):
    print(S-B[A[k]]+1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import*
d={}
n,*a=map(int,open(0).read().split())
b=Counter(a)
for i in range(n):
    c=(b-Counter([a[i]]))
    if a[i]not in d:
        ans=sum([v*(v-1)//2 for k,v in c.items()if v>=2])
        d[a[i]]=ans
    else:
        print(d[a[i]])

from collections import*
n,*a=map(int,open(0).read().split())

b=Counter(a)

ans=sum(v*(v-1)//2 for k,v in b.items())

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
number = list(map(int,input().split()))
num = sorted(number)
num.append(0)
p = num[0]
combi = dict()
u = 0

for i in range (n+1) :
    q = num[i]
    if p != q :
        combi[p] = u
        u = 0
    u += 1
    p = q

t = 0

for j in combi.values() :
    t += j*(j-1)//2

for k in range (n) :
    x = combi[j]
    print(t + (combi[x]-1)*(combi[x]-2)//2 - combi[x]*(combi[x]-1)//2)

n = int(input())
number = list(map(int,input().split()))
num = sorted(number)
num.append(0)
p = num[0]
combi = dict()
u = 0

for i in range (n+1) :
    q = num[i]
    if p != q :
        combi[p] = u
        u = 0
    u += 1
    p = q

t = 0

for j in combi.values() :
    t += j*(j-1)//2

for k in range (n) :
    x = number[k]
    print(t + (combi[x]-1)*(combi[x]-2)//2 - combi[x]*(combi[x]-1)//2)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
from math import factorial

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

dic = {}
after = {}

newdata = np.unique(A)
for i in range(len(newdata)):
	x = np.sum(A == newdata[i])
	if x <= 1:
		dic[newdata[i]] = 0
	else:
		dic[newdata[i]] = factorial(x) / factorial(2) / factorial(x - 2)

	if x - 1 <= 1:
		after[newdata[i]] = 0
	else:
		after[newdata[i]] = factorial(x - 1) / factorial(2) / factorial(x - 1 - 2)

	print(dic, after)

numsum = 0
for dicv in dic.values():
	numsum += dicv 


for i in range(N):
	print(int(numsum - dic[A[i]] + after[A[i]]))


import numpy as np
from math import factorial

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

amount = np.array([])
for i in range(N):
	amount = np.append(amount, np.sum(A == i + 1))

for i in range(N):
	amount[A[i] - 1] -= 1
	ans = 0
	for j in range(N):
		if amount[j] <= 1:
			pass
		else:
			ans += factorial(amount[j]) / factorial(2) / factorial(amount[j] - 2)
	print(int(ans))
	amount[A[i] - 1] += 1


import numpy as np
import collections

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

dic = {}
after = {}

l = collections.Counter(A)

for key, val in l.items():
	dic[key] = val * (val - 1) // 2
	after[key] = (val - 1) * (val - 2) // 2

numsum = sum(dic.values())

ans = {}
for key in dic.keys():
	ans[key] = numsum - dic[key] + after[key]

for i in range(N):
	print(ans[A[i]])



Verdicts: Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
import collections
import math
N = int(input())
A = list(map(int, input().split()))
ans = 0

for i in range(N):
  li = A[:i] + A[i+1]
  c = collections.Counter(li)
  l = [i for i in C.items() if i > 1]
  for num in l:
    ans += math.factorial(num) // (math.factorial(num-2) * 2)
    
print(ans)

import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
total = 0

for n in c.items():
  if n[1] > 1:
    total += n*(n-1)//2

for i in range(N):
  ans = total
  ans -= A.count(A[i])-1
  print(ans)

import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
total = 1

for n in c.items():
  total += n[1]*(n[1]-1)//2

for i in range(N):
  print(total-c[A[i]])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from scipy.misc import comb
# from scipy.special import comb

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    for k, v in d.items():
        if v > 1:
            d[k] = [v, comb(v, 2)]
        else:
            d[k] = [v, 0]
    for a in al:
        ans = 0
        for k, v in d.items():
            if k == a:
                if v[0] > 2:
                    ans += comb(v[0]-1, 2)
            else:
                ans += v[1]
        print(int(ans))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)

from scipy.misc import comb

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    for a in al:
        d[a] -= 1
        ans = 0
        for v in d.values():
            if v > 1:
                ans += comb(v, 2)
        d[a] += 1
        print(int(ans))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)

# from scipy.misc import comb
# from scipy.special import comb
import math

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

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    ans = 0
    for k, v in d.items():
        if v > 1:
            ans += comb(v, 2)
            # d[k] = [v, comb(v, 2)]
        # else:
            # d[k] = [v, 0]
    # print(ans)
    for a in al:
        # for k, v in d.items():
        
        #         if v[0] > 2:
        #             ans += comb(v[0]-1, 2)
        #     else:
        #         ans += v[1]
        print(int(ans-(d[a]-1)))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
import bisect
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
Key = []
Val = []
for key,val in A.items():
    Key.append(key)
    Val.append(val)
ans = 0
ans1 = 0
for i in range(len(Val)):
    ans+= ((Val[i])*(Val[i]-1))//2
for i in range(n):
    s = bisect.bisect_left(Key,a[i])
    d1 = (Val[s]*(Val[s]-1))//2
    Val[s]-=1
    d2 = (Val[s]*(Val[s]-1))//2
    ans1 = ans - (d1-d2)
    print(ans1)
    Val[s]+=1
print(ans1)

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

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


c = collections.Counter(a)
maxa = 0
item = [0 for i in range(max(a))]
for key,value in c.items():
    item[key-1] = value
    maxa += (value)*(value-1)//2
for i in range(len(a)):
    d = (item[a[i]-1])*(item[a[i]-1]-1)//2-(item[a[i]-1]-1)*(item[a[i]-1]-2)//2
    print(maxa-d)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = []
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - d[a] + 1)

import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - d[a] + 1)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
N=int(input())
a=0
list1 = list(map(int, input().split()))
c = collections.Counter(list1)
for i in range(N):
    a+=int(c[i+1]*(c[i+1]-1)/2)
for i in range(N):
    print(a-c[list1[i]]*2+3)

import collections
N=int(input())
a=0
list1 = list(map(int, input().split()))
c = collections.Counter(list1)
for i in range(N):
    a+=int(c[i+1]*(c[i+1]-1)/2)
for i in range(N):
    if c[list1[i]]!=0:
        print(a-c[list1[i]]+1)
    else:
        print(a)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict.values():
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()


#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())
def comb(n):
  return int(math.factrial(n)/(math.factrial(n-2)*2))
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)


import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())
def comb(n):
  return math.factrial(n)/(math.factrial(n-2)*2)
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)

import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
def comb(n):
  return int(math.factrial(n)/(math.factrial(n-2)*2))
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)


#ABC159D
import sys, math
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
ans=0
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
for i in range(len(C)):
    ans+=Comb(L[A[i]-1],2)
for i in range(N):
    pri=ans
    pri=ans-Comb(L[A[i]-1],2)+Comb(L[A[i]-1]-1,2)
    print(pri)

def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
ans=0
B=set(A)
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
for i in B:
    ans+=Comb(L[i-1],2)
for i in range(N):
    pri=ans
    pri=ans-L[A[i]-1]+1
    print(pri)

Verdicts: Runtime Error

Accepted