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):
import collections

N = 8#int(input())
#A = list(map(int, input().split()))
A = [1, 2, 1, 4, 2, 1, 4, 1]

c = collections.Counter(A)
#print(c)

count_dic = {}
for i in c.keys():
    count = 0
    c_copy = c.copy()
    c_copy[i] = c[i]-1
    #print(c_copy)
    for k in c.keys():
        count += int(c_copy[k]*(c_copy[k]-1)/2)
        count_dic[i] = count
        #print(count)
    #print(count_dic)

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

from collections import Counter
import numpy as np
 
N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])
    
for i in A:
    print(int(count_sum-count_dict[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):
from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    l = a[i]
    a[i] = ''
    ans = 0
    a_s = set(a)
    for j in a_s:
        c = a.count(j)
        ans += comb(c,2,exact=True)
    print(ans)
    a[i] = l

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
a_s = set(a)
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    for j in a_s:
        ans += comb(a.count(j),2)
    print(int(ans))
    a[i] = l

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
a_s = set(a)
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    for j in a_s:
        ans += comb(a.count(j),2,exact=True)
    print(ans)
    a[i] = l

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    a_s = set(a)
    for j in a_s:
        c = a.count(j)
        if c < 2:
            continue
        ans += comb(c,2,exact=True)
    print(ans)
    a[i] = l

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    a_s = set(a)
    for j in a_s:
        ans += comb(a.count(j),2,exact=True)
    print(ans)
    a[i] = l


from collections import Counter
n = int(input())
a = list(map(int,input().split()))

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

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

Verdicts: Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

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):
from operator import mul
from functools import reduce

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

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

divided = []
for i in range(N):
    divided.append(A_list.count(i + 1))

ans = 0
for j in divided:
    ans += combinations_count(j, 2)

# print(divided)

for k in range(1, N + 1):
    n = divided[A_list[k - 1] - 1]
    # print(n)
    ans_k = ans
    if n > 1:
        ans_k -= n - 1

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

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

divided = []
for i in range(N):
    divided.append(A_list.count(i + 1))

ans = 0
for j in divided:
    ans += combinations_count(j, 2)

# print(divided)

for k in range(1, N + 1):
    n = divided[A_list[k - 1] - 1]
    # print(n)
    ans_k = ans
    if n > 1:
        ans_k -= n - 1

    print(int(ans_k))

import collections


#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

counts = collections.Counter(A_list)
ans = 0
for _, v in counts.items():
    ans += v * (v - 1) / 2

for k in range(1, N + 1):
    n = counts[A_list[k - 1]]
    ans_k = ans
    if n > 1:
        ans_k -= n - 1

    print(int(ans_k))

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):
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
nCr = {}
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * n-1 /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in range(N):
    a = A[i]
    s += cmb(a)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(s-x)

import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
nCr = {}
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * n-1 /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
for i in range(N):
    s = 0
    a = A[i]
    mydict[a] -= 1
    for j in mydict.values():
        s += cmb(j)
    print(s)
    mydict[a] += 1

import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * (n-1) /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in mydict.values():
	s += cmb(i)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(int(s-x))

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())
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 si:
		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)


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]
	l = di[k]
	su_ch = su
	su_ch -= l*(l-1)/2
	su_ch += (l-1)*(l-2)/2
	print(int(su_ch))
	

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

n = int(input())
a = input().split()
freq = Counter(a)
print(freq)
total=0
    
for key,val in freq.items():
    total+=(val*(val-1))//2

for k in range(n): 

    kth = (freq[a[k]]*(freq[a[k]]-1))//2
    newkth = ((freq[a[k]]-2)*(freq[a[k]]-1))//2  

    total -= kth
    total += newkth
    
    print(total)
    
    total -=newkth
    total +=kth

from collections import Counter

n = int(input())
a = input().split()
freq = Counter(a)
print(freq)
total = []



for k in range(n): 
    freq[a[k]]-=1
    total=0
    
    for key,val in freq.items():
        total+=(val*(val-1))//2
        
    freq[a[k]]+=1
    
    print(total)

from collections import Counter

n = int(input())
a = input().split()
freq = Counter(a)
#print(freq)
total=0
    
for key,val in freq.items():
    total+=(val*(val-1))//2

for k in range(n): 

    kth = (freq[a[k]]*(freq[a[k]]-1))//2
    newkth = ((freq[a[k]]-2)*(freq[a[k]]-1))//2  

    total -= kth
    total += newkth
    
    print(total)
    
    total -=newkth
    total +=kth

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 copy
import math
import scipy.special import comb

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

n = int(input())
nums = [ int(s) for s in input().split() ]


for i in range(n):
    ans = 0

    cpl = copy.copy(nums)
    cpl.pop(i)
    ct = collections.Counter(cpl)

    for key, val in ct.items():
        if val > 1:
            ans += comb(val, 2, exact=True)
    
    print(ans)


import collections
import copy
import math
import scipy.misc import comb

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

n = int(input())
nums = [ int(s) for s in input().split() ]


for i in range(n):
    ans = 0

    cpl = copy.copy(nums)
    cpl.pop(i)
    ct = collections.Counter(cpl)

    for key, val in ct.items():
        if val > 1:
            ans += comb(val, 2, exact=True)
    
    print(ans)


import collections
import copy
import math
from scipy.misc import comb

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

n = int(input())
nums = [ int(s) for s in input().split() ]


for i in range(n):
    ans = 0

    cpl = copy.copy(nums)
    cpl.pop(i)
    ct = collections.Counter(cpl)

    for key, val in ct.items():
        if val > 1:
            ans += comb(val, 2, exact=True)
    
    print(ans)





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

# counter
from collections import Counter
cntr = Counter(lst)

# combination
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

total = 0
# countSameNames
for value in cntr.values():
    if value > 1:
        total += combinations_count( value, 2 )


for l in lst:
    print(total - (cntr[l]-1))

Verdicts: Runtime Error

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):
from collections import Counter

N = int(input())
al = list(map(int, input().split()))
C = Counter(al)
# print(C)
# print(C.values())
ans = 0
for i in C.values():
    ans += i * (i - 1) / 2

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


import math
from collections import Counter
import itertools
n = int(input())
al = list(map(int,input().split()))
C_al = Counter(al)

all = 0
for i in C_al.values():
    all += i*(i-1)/2

for i in al:
    k = C_al[i]
    print(int(all - (k * (k - 1) / 2) + (k - 1) * (k - 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):
import collections

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

c=collections.Counter(a)
num=0
for i in c.values():
    num+=i*(i-1)/2
    
for i in range(x):
    print(num-c[a[i]]+1)

import collections

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

c=collections.Counter(a)
num=0
for i in c.values():
    num+=i*(i-1)/2
    
for i in range(x):
    print(int(num-c[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):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*n
    for i in range(n):
        cnt[a[i]-1]+=1
    res=0
    for i in range(n):
        if cnt[i]>1:
            res+=cnt[i]*(cnt[i]-1)//2
    ans=[0]*n
    for i in range(n):
        if cnt[i]>=1:
            ans[i]=res-(cnt[i]-1)
    print(cnt)
    print(ans)
    for i in range(n):
        print(ans[a[i]-1])
        
if __name__=="__main__":
    main()

def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*n
    for i in range(n):
        cnt[a[i]-1]+=1
    res=0
    for i in range(n):
        if cnt[i]>1:
            res+=cnt[i]*(cnt[i]-1)//2
    ans=[0]*n
    for i in range(n):
        if cnt[i]>=1:
            ans[i]=res-(cnt[i]-1)
    for i in range(n):
        print(ans[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):
import math
N = (int(input()))
items = list(map(int,input().split()))
for i in range(len(items)):    
    rest = items[:i] + items[i+1:]
    rest_unique = list(set(rest))
    out = 0
    for j in rest_unique:
        cnt = sum([1 for x in rest if x == j])
        if cnt < 2:
            out = out
        else:
            out = out + math.factorial(cnt)/math.factorial(cnt-2)/2
    print(out)

import math
input()
items = list(map(int,input().split()))
d = {}
for i in items:
    if i in d.keys():
        d[i] = d[i]+1
    else:
        d[i] = 1

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

total = sum(p.values())

for item in items:
    print(int(total - d[item] + 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):
N = int(input())
d = {}
for i in range(1,N+1):
    d[i] = 0
A = list(map(int,input().split()))
for i in range(N):
    a = A[i]
    d[a] += 1
s = 0
for i in range(1,N+1):
    x = d[a]
    s += (x*(x-1))//2
for i in range(N):
    y = A[i]
    z = s + 1 - d[y]
    print(z)

N = int(input())
d = {}
for i in range(1,N+1):
    d[i] = 0
A = list(map(int,input().split()))
for i in range(N):
    a = A[i]
    d[a] += 1
s = 0
for i in range(1,N+1):
    x = d[i]
    s += (x*(x-1))//2
for i in range(N):
    y = A[i]
    z = s + 1 - d[y]
    print(z)

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()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

for i in num:
    cnt += i * (i - 1)//2

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


n = int(input())
a = list(map(int, input().split()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

for i in num:
    cnt += i * (i - 1)//2

for i in range(n):
    tmp = num[a[i]-1]
    ans = cnt - (tmp-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()))
import collections

c = collections.Counter(A)
keys = c.keys()
ans_dict = {}
ans_dict2 = {}
for key in keys:
    ans_dict[key] = cmb(c[key]-1,2)
    ans_dict2[key] = cmb(c[key],2)

SUM  = sum(ans_dict2.values())

# print(ans_dict)
# print(ans_dict2)

for key in A:
    print(SUM-ans_dict2[key]+ans_dict[key])

def cmb(n, r):
    if r > n: return 0
    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())
A = list(map(int,input().split()))
import collections

c = collections.Counter(A)
keys = c.keys()
ans_dict = {}
ans_dict2 = {}
for key in keys:
    ans_dict[key] = cmb(c[key]-1,2)
    ans_dict2[key] = cmb(c[key],2)

SUM  = sum(ans_dict2.values())

# print(ans_dict)
# print(ans_dict2)

for key in A:
    print(SUM-ans_dict2[key]+ans_dict[key])

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())
arr = list(map(int,input().split()))
cnt = collectioms.Counter(arr)
total = 0

for key in cnt.keys():
  total += cnt[key] * (cnt[key] - 1)//2
  
for i in range(n):
  tmp = total
  tmp -= cnt[arr[i]]*(cnt[arr[i]] - 1)//2
  tmp += (cnt[arr[i]] - 1)*(cnt[arr[i]] - 2)//2
  print(tmp)

import collections

n = int(input())
arr = list(map(int,input().split()))
cnt = collections.Counter(arr)
total = 0

for key in cnt.keys():
  total += cnt[key] * (cnt[key] - 1)//2
  
for i in range(n):
  tmp = total
  tmp -= cnt[arr[i]]*(cnt[arr[i]] - 1)//2
  tmp += (cnt[arr[i]] - 1)*(cnt[arr[i]] - 2)//2
  print(tmp)


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 = input().split()

L = [0 for i in range(N)]

for i in range(N):
  L[int(A[i])-1] +=1

c = 0
for i in range(N):
  n = L[i]
  if n >= 2:
    c += factorial(n) // factorial(2) // factorial(n - 2)

for i in range(N):
  n = L[A[i]-1]
  if n >= 2:
    print(c - n + 1)
  else:
      print(c)

from math import factorial

N = int(input())
A = input().split()

L = [0 for i in range(N)]

for i in range(N):
  L[int(A[i])-1] +=1

c = 0
for i in range(N):
  n = L[i]
  if n >= 2:
    c += factorial(n) // factorial(2) // factorial(n - 2)

for i in range(N):
  n = L[int(A[i])-1]
  if n >= 2:
    print(c - n + 1)
  else:
      print(c)

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())
*li,=map(int, input().split())
from collections import Counter
c = Counter()
for i in li:
    c[i] += 1
ans=0
from math import comb
for i in c.values():
    ans += comb(i, 2)
for i in li:
    print(ans - comb(c[i], 2) + comb(c[i-1], 2))
  

def f():
  n = int(input())
  *li,=map(int, input().split())
  from collections import Counter
  c = Counter()
  for i in li:
    c[i] += 1
  ans=0
  from math import comb
  for i in c.values():
    ans += comb(i, 2)
  for i in li:
    print(ans - comb(c[i], 2) + comb(c[i]-1, 2))
f()
  

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 python3

import collections

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

c = collections.Counter(A)
values = c.keys()
counts = c.values()


ans = 0
for i in range(len(values)):
    tmp = counts[i]
    ans += (tmp * (tmp-1))//2

for i in range(N):
    num = A[i]
    index = values.index(num)
    print(ans - counts[index] + 1)


#!/usr/bin/env python3

import collections

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

c = collections.Counter(A)
values, counts = c.keys(), c.values()

ans = 0
for i in range(len(values)):
    tmp = counts[i]
    ans += (tmp * (tmp-1))//2

for i in range(N):
    num = A[i]
    index = values.index(num)
    print(ans - counts[index] + 1)


#!/usr/bin/env python3

import collections

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

c = collections.Counter(A)
values = c.keys()
counts = c.values()

subs = {}
a_sum = 0
for v, c in zip(values, counts):
    subs[v] = c
    a_sum += (c * (c-1)) // 2

for i in range(N):
    print(a_sum - subs[A[i]] + 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):
import copy
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    ac=copy.deepcopy(A)
    del ac[i]
    ak=collections.Counter(ac)
    aj=list( ak.values() )
    s=0
    for j in range(len(aj)):
        s=s+com(aj[j],2)
    res[i]=s
print(' '.join(map(str,res)))
    

import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s+(1/2)*(res2[j][1]-1)*(res2[j][1]-1)-(1/2)*(res2[j][1])*(res2[j][1])
for i in range(n):
    res[i]=res3[A[i]-1]

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

import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s-res2[j][1]+1
for i in range(n):
    res[i]=res3[A[i]-1]

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


Verdicts: Time Limit Exceeded

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 defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

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

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)






total = 0


for j in a_dict.values():
    total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1) + 1))

from collections import defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

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

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)






total = 0


for j in a_dict.values():
    if j != 1:
        total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1)))

from collections import defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

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

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)






total = 0


for j in a_dict.values():
    total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1)))

from collections import defaultdict
from pprint import pprint
#from scipy.special import comb

n = int(input())

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

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)






total = 0


for j in a_dict.values():
    total += j*(j-1)/2

for k in a_list:
    print(int(total - (a_dict[k]-1)))

Verdicts: Wrong Answer

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 cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

a = list(set(A))
a_n = []
c = []
new = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(cmb(x,2, mod))
    if x >= 2: new.append(cmb(x-1,2, mod))
    else: new.append(0)

  ans = sum(c)
  for i in range(N):
    n = a.index(A[i])
    print(ans-c[n]+new[n])
else:
  for _ in range(N):
    print(0)

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

a = list(set(A))
a_n = []
c = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(x*(x-1)//2)

  ans = sum(c)
  print(c)
  for i in range(N):
    n = a.index(A[i])
    new = (a_n[n]-1)*(a_n[n]-2)//2
    print(ans-c[n]+new)
else:
  for _ in range(N):
    print(0)

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = {}
ANS = 0
for x,y in Counter(A).items():
    if y >= 2: 
        a[x] = [y, (y*(y-1))//2]
        ANS += (y*(y-1))//2
for i in range(n):
    ans = ANS
    if A[i] in a:
        x = a[A[i]][0]-1
        ans -= a[A[i]][1]
        ans += (x*(x-1))//2
    print(ans)

Verdicts: 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):
n = int(input())
a = list(map(int, input().split()))

from collections import Counter

c = Counter(a)

from scipy.misc import comb

s = set(c.values())

dic = {}
for ss in s:
    if ss not in dic.keys():
        dic[ss] = comb(ss, 2)
for ss in s:
    ss -= 1
    if ss not in dic.keys():
        dic[ss] = comb(ss, 2)

base = 0
for k in c.keys():
    base += dic[c[k]]

for k in range(len(a)):
    print(int(base - dic[c[a[k]]] + dic[c[a[k]] - 1]))


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

from collections import Counter

c = Counter(a)

def comb(x):
    return x * (x - 1) // 2

base = 0
for aa in c.keys():
    x = c[aa]
    base += comb(x)

for aa in a:
    ans = base - comb(c[aa]) + comb(c[aa] - 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 copy import deepcopy
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c= Counter(A)
    values = a_c.values()
    val_cnt = Counter(values
    for a in A:
        val_cnt_c = deepcopy(val_cnt)
        val_cnt_c[a_c[a]] -= 1
        val_cnt_c[a_c[a]-1] += 1
        cnt = {int(k*(k-1)/2*v) if k > 1 else 0 for k, v in val_cnt_c.items()}
        print(sum(cnt))
    
if __name__ == '__main__':
    main()

from collections import Counter
 
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        ans = (cnt - (a_c[a]-1))
        print(ans)
 
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):
n = int(input())
a = list(map(int,input().split()))
c = [0 for _ in range(n)]
r = []
for i in range(n):
    c[a[i-1]-1] += 1
for i in range(n):
    r.append(c[i-1])
kai = []
v = []
for i in range(len(r)):
    kai.append((r[i]*(r[i]-1)//2))
    v.append(kai[i] - max(((r[i]-1)*(r[i]-2)//2),0))

ans = sum(kai)
for i in range(len(v)):
    for j in range(v[i]+1):
        print(ans - v[i])

n = int(input())
a = list(map(int,input().split()))
c = [0 for _ in range(n+1)]
r = []
for i in range(n):
    c[a[i-1]-1] += 1
for i in range(n):
    r.append(c[i])
kai = []
v = []
for i in range(len(r)):
    kai.append((r[i]*(r[i]-1)//2))
    v.append(kai[i] - max(((r[i]-1)*(r[i]-2)//2),0))

ans = sum(kai)
for i in range(len(a)):
    print(ans - v[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):
N=int(input())
A=list(map(int,input().split()))
keys=[]
values=[]
for i in A:
  if i in keys:
    pass
  else:
    counts=A.count(i)
    keys.append(i)
    values.append(counts)
ans=0
for j in values:
  ans+=j*(j-1)/2
for k in A:
  a=keys.index(k)
  print(ans-values[a]+1)

N=int(input())
A=list(map(int,input().split()))
dic={}
for i in A:
  if i not in dic.keys():
    dic.update({i:1})
  else:
    dic[i]+=1
ans=sum([int(j*(j-1)/2) for j in dic.values()])
for k in A:
  num=dic[k]
  if num>=1:
    print(int(ans-num+1))
  else:
    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
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    c = Counter(A)

    sum_count = sum([v * (v - 1) // 2 for v in c.values()])
    for i, v in c.items():
        if v < 2:
            continue
        value = v * (v - 1) // 2
        print(sum_count - value + value * (v - 2) // v)

if __name__ == '__main__':
    main()


import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    c = Counter(A)

    data = [0] * (N+1)
    sum_count = 0
    for i, v in c.items():
        if v < 2:
            continue
        value = v * (v - 1) // 2
        data[i] = value - value * (v - 2) // v
        sum_count += value

    print('\n'.join([str(sum_count - data[a]) for a in A]))

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):
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
count=0
for i in range(1,N+1):
  a=B["i"]
  count+=(a*(a-1))/2

  
for i in range(1,N+1):
  a=B["i"]
  print(int(count-(a*(a-1))/2))

import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
count=0
for i in range(1,N+1):
  a=B[i]
  count+=(a*(a-1))/2
for i in A:
  a=B[i]
  print(int((count-(a*(a-1))/2)+(a-1)*(a-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())
A = []
A = [int(i) for i in input().split()]

number_set = list(set(A))
#print("number set is :", number_set)    
    
for k in range(n):
    out = 0
    ans = []
    ans += A[0:k]
    ans += A[k+1:n]
    #print(ans)
    for i in range(len(number_set)):
        #print(ans.count(number_set[i]))
        out += ans.count(number_set[i]) * (ans.count(number_set[i]-1)) //2
        
    print(out)    

import collections
N = int(input())
li = list(map(int, input().split()))
cn = collections.Counter(li)
sumC = sum([n*(n-1)//2 for n in cn.values()])
for k in range(N):
    print(sumC - (cn[li[k]]-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):
def main():
  H,W,K = map(int,input().split())
  import numpy as np
  from collections import deque
  ans = 10000
  S = np.array([list(map(int,list(input()))) for _ in range(H)])
  cum = [[0]*W for _ in range(H+1)]
  for j in range(W):
    for i in range(1,H+1):
      cum[i][j] = cum[i-1][j]+S[i-1][j]

  cum = np.array(cum)
  for i in range(2**(H-1)):
    q = deque([0])
    for h in range(H):
      if (i>>h)&1:
        q.append(h+1)
    q.append(H)
    p = deque()
    judge = False
    for a in range(len(q)-1):
      x = cum[q[a+1]]-cum[q[a]]
      if (x>K).any():
        judge = True
        break
      else:
        p.append(x)

    if judge:
      continue

    t_a = len(q)-2
    l = [0]*len(p)
    for w in range(W):
      for x,a in enumerate(p):
        l[x]+=a[w]
        if l[x]>K:
          t_a+=1
          l = [0]*len(p)
          for z,b in enumerate(p):
            l[z] = b[w]
          break
    ans = min(ans,t_a)

  print(ans)
  
main()

N = int(input())
A = list(map(int,input().split()))
A_set = list(set(A))
l = [0]*(N+2)
ans = [0]*(N+2)
for a in A:
  l[a]+=1
comb = [0]*(N+2)
for i in range(2,N+1):
  comb[i] = i*(i-1)//2
  
for i in range(2,N+1):
  ans[i]=comb[i]-comb[i-1]
  
total = 0
for a in A_set:
  total += comb[l[a]]

for a in A:
  print(int(total-ans[l[a]]))

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
n = int(input())
s = [int(i) for i in input().split()]

s_set = set(s)

counted = Counter(s)
ans = sum(i*(i-1)/2 for i in counted.values())
print(ans)

for i in s:
    x = counted[i]
    print(int(ans - x + 1))

from collections import Counter
n = int(input())
s = [int(i) for i in input().split()]

s_set = set(s)

counted = Counter(s)
ans = sum(i*(i-1)/2 for i in counted.values())

for i in s:
    x = counted[i]
    print(int(ans - x + 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):

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

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in b:
    total += choose2(a.count(i))

for i in a:
    print(total - choose2(s[i]) + choose2(s[i]-1))


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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-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 = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])

import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum += val
print('\n'.join([int(sum - data[i]) for i in a])

import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
c = collections.Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])


import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum += val
print('\n'.join([int(sum_count - data[i]) for i in a])

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
c = Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) / 2
    dif[i] = v - 1
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])

from collections import Counter


def main():
    n = int(input())
    A = list(map(int, input().split()))
    a_c = Counter(A)
    a_s = list(set(A))
    tot = 0
    for a in a_s:
        tot += a_c[a] * (a_c[a] - 1) // 2
    ans = list(map(lambda x: tot - (a_c[x] - 1), a_s))
    ans_dic = dict(zip(a_s, ans))
    for a in A:
        print(ans_dic[a])


if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Runtime Error

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):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
values, counts = zip(*c.most_common())
values, counts = list(values), list(counts)
k = 0
for i in range(len(counts)):
  k += counts[i]*(counts[i]-1)//2
output = [0]*len(a)
for i in range(len(a)):
  temp = c[a[i]]
  if temp == 1:
    output[i] = k
  else:
    output[i] = k-temp*(temp-1)//2+(temp-1)*(temp-2)//2
print(output)

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
values, counts = zip(*c.most_common())
values, counts = list(values), list(counts)
k = 0
for i in range(len(counts)):
  k += counts[i]*(counts[i]-1)//2
output = [0]*len(a)
for i in range(len(a)):
  temp = c[a[i]]
  if temp == 1:
    output[i] = k
  else:
    output[i] = k-temp*(temp-1)//2+(temp-1)*(temp-2)//2
  print(output[i])

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 defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(int)
    ans = []
    for i in A:
        dd[i] += 1
    for i in range(n):
        ng = A[i]
        dd[ng] -= 1
        cnt = 0
        for key, val in dd.items():
            cnt += val * (val-1) // 2
        ans.append(cnt)
        dd[ng] += 1
    print(*ans, sep='\n')

from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    cnt_common = cnt.most_common()
    ans = 0
    for i in range(len(cnt_common)):
        num, val = cnt_common[i]
        ans += val * (val - 1) // 2
    for i in A:
        c = cnt[i]
        print(ans - c * (c - 1) // 2 + (c-1) * (c-2) // 2 )

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):
n=int(input())
S=list(map(int,input().split()))
set_S=list(set(S))
ans_stock={}
number={}
for i in set_S:
  number[i] = S.count(i)
comb = 0
for i in set_S:
  comb += number[i]*(number[i]-1)/2

for i in S:
  if i in list(ans_stock.keys()):
    print(ans_stock[i])
  else:
    ans = comb -  number[i]*(number[i]-1)/2 +  (number[i]-1)*(number[i]-2)/2
    print(ans)
    ans_stock[i]=ans

n=int(input())
S=list(map(int,input().split()))
for i in S:
  print(len(S)-S.count(i)+1)

from collections import Counter
n=int(input())
S=list(map(int,input().split()))
number=Counter(S)
comb=0
stock={}
for i in list(number.values()):
  comb += i*(i-1)/2
for i in S:
  ans = int(comb - number[i]*(number[i]-1)/2 + (number[i]-1)*(number[i]-2)/2)
  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):
from collections import Counter

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

table = set(a)

con = {}
dic = {}
ans = []

con = Counter(a)
dic = {}

#    con[i] = a.count(i)


for x in a:
    if dic[x] == None:
        ex = (con[x] - 1) * (con[x] - 2) / 2
        no = (con[x]) * (con[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))


from collections import Counter

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

c = Counter(a)
dic = {}

for x in a:
    if x not in dic:
        ex = (c[x] - 1) * (c[x] - 2) / 2
        no = (c[x]) * (c[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][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())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = L.count(i)
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]-1]-1)*(dn[L[i]-2])/2))

n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Verdicts: Runtime Error

Runtime Error

Accepted