Problem:


Score : 400 points

Problem Statement

We have N balls. The i-th ball has an integer A_i written on it.

For each k=1, 2, ..., N, solve the following problem and print the answer.  

Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Constraints

3 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

For each k=1,2,...,N, print a line containing the answer.

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.

From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5



Sample input:
5
1 1 2 1 2


Sample output:
2
2
3
2
3

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*k-1)/2 in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)

Submission status: Runtime Error

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

b = set(a)

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

e = {}
for i in a:
    e[i] = c[i]*(c[i]-1)//2

for k in a:
    if d.get(k, "hello") == "hello":
        ans = 0
        for i in b:
            if i != k:
                ans += e[i]
            else:
                ans += e[i]+1-c[i]
        d[k] = ans
    else:
        ans = d[k]
    print(ans)

Submission status: Runtime Error

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

b = set(a)

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

d = {}

for k in a:
    if d.get(k, "hello") == "hello":
        ans = 0
        for i in b:
            if i != k:
                ans += c[i]*(c[i]-1)//2
            else:
                ans += (c[i]-1)*(c[i]-2)//2
        d[k] = ans
    else:
        ans = d[ans]
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))

import collections
 
c = collections.Counter(l)

for i in c.values():
    ans += i * (i - 1) // 2
    
for i in l:
    print(ans - c[i] - 1)

Submission status: Runtime Error

Solution code:
r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
  t,v,l=[],-1,1
  for j in r(h):
    if i>>j&1:t+=j+1,;l+=1
  t+=h,
  c=[0]*l
  for i in r(w):
    b=f=g=0;u=[]
    for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
    v+=f
    if f:c=u
  if not g:m=min(m,v+l)
print(m)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
def combi(count):
  if n==1:return 0
  elif n==2:return 1
  else:return int(count*(count-1)/2)


n=int(input())
alis=list(map(int,input().split()))
dick=dict()
for i in range(n):
  p=alis[i]
  dick[p]+=1

point=0
for k,v in dick:
  point+=combi(v)


for i in range(n):
  idx=alis[i]
  minus=dick[idx]-1
  print(point-minus)

Submission status: Runtime Error

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

ls = [0]*N
for i in range(N):
    ls[A[i]] += 1
s = 0
for i in range(N):
    s += ls[i]*(ls[i]-1)//2

for k in range(N):
    print(s-ls[A[k]] + 1)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
b=[0] * mx
ans = 0
for i in range(n):
    b[a[i]-1] += 1

for i in range(mx):
    if(b[i] == 0 or b[i] == 1):
        ans += 0
    else:
        ans = ans + math.factorial(b[i])/2 / math.factorial(b[i]-2)
ans1 = 0


for i in range(n):
    ans1 = ans
    if(b[a[i]-1] >2):
        ans1 = ans1 -(math.factorial(b[a[i]-1])/2 / math.factorial(b[a[i]-1]-2)) + (math.factorial(b[a[i]-1]-1)/2 / math.factorial(b[a[i]-1]-3))
        print(int(ans1))
    elif(b[a[i]-1] == 2):
        print(int(ans1-1))
    elif(b[a[i]-1] < 2):
        print(int(ans1))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
b=[0] * mx
ans = 0
for i in range(n):
    b[a[i]-1] += 1

for i in range(mx):
    if(b[i] == 0 or b[i] == 1):
        ans += 0
    else:
        ans = ans + math.factorial(b[i])/2 / math.factorial(b[i]-2)
ans1 = 0


for i in range(n):
    ans1 = ans -(math.factorial(b[a[i]-1])/2 / math.factorial(b[a[i]-1]-2))
    if(b[a[i]-1]-1 < 2):
        print(int(ans1))
    else:
        ans1 = ans1 + (math.factorial(b[a[i]-1]-1)/2 / math.factorial(b[a[i]-1]-3))
        print(int(ans1))

Submission status: Runtime Error

Solution code:
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)

#総数から(a_dict[k]-1)の値を引いていく。
#例えば5C2のものが一つ減った場合、4C2になる。この差分は5C2-4C2=10-6=4 
#例えば6C2のものが一つ減った場合、5C2になる。この差分は6C2-5C2=15-10=5 
#例えば7C2のものが一つ減った場合、6C2になる。この差分は7C2-6C2=21-15=6

total = 0

#組み合わせの総数を求める。
for j in a_dict.values():
    total += comb(j,2)

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

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * N
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        #print(comb-(nums[A[k]]-1))
        t = nums[A[k]]
        print(comb - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools as iter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * N
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  print(c)
  for i in a:
    print(c[i])
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import factorial    N = int(input())
A = list(map(int, input().split()))

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

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

Submission status: Runtime Error

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

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

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

Submission status: Runtime Error

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

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

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    # print(f"a:{a} n:{n}", file=sys.stderr)
    print(combination_all - (combi[a] - combi2[a]))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
counter_comb = list(map(lambda y: int(y*(y-1)/2), counter.values()))
sum_counter = sum(counter_comb)
for i in range(n):
    z = counter[A[i]-1]
    if z>0:
        print(ssum_counter-(z-1))
    else:
        print(sum_counter)

Submission status: Runtime Error

Solution code:
def cmb(n):
    return n * (n-1) / 2

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

#dic1はその要素を含む、dic2はその要素を含まない解
dic1 = {}
#a[i]の要素に対する組み合わせが計算されていない場合
#計算後辞書に保存
#辞書から解を出力
for i in range(n):
    if not a[i] in dic1:
        ball_n = a.count(a[i])
        if ball_n >= 2:
            ans1 = cmb(ball_n, 2)
            dic1[a[i]] = ans1


sum = sum(dic1.values())
for i in range(n):
    ball_n = a.count(a[i])
    c = 0
    b = 0
    if a[i] in dic1:
        b = dic1[a[i]]
        c = int(dic1[a[i]] * (ball_n-2) / ball_n)
    ans = sum - b + c
    print(ans)

Submission status: Runtime Error

Solution code:
def nCr(n, r): 
  
    return (fact(n) / (fact(r)  
                * fact(n - r))) 
  
# Returns factorial of n 
def fact(n): 
  
    res = 1
      
    for i in range(2, n+1): 
        res = res * i 
          
    return res
n=int(input())
a=[*map(int,input().split())]
b=[0]*(n+1)
ans=0
for i in a:
    b[i]+=1
for j in a:
    b[j]-=1
    for k in b:
        if k>=2:
            ans+=int(nCr(k,2))
    b[j]+=1
    print(ans)
    ans=0

Submission status: Runtime Error

Solution code:
from math import factorial

n = int(input())
A = list(map(int,input().split()))
dict = {}

for i,a in enumerate(A):
  if a in dict:
    dict[a].append(i)
  else:
    dict[a]=[i]

ans = 0    
    
for k,v in dict.items():
  if len(v) >= 2:
    ans += factorial(len(v)) / 2 / factorial(len(v) - 2)

#print(dict)
#print(int(ans))
#print("kk")
  
for i in range(n):
  wnum = A[i]
  l=dict[wnum]
  if 2 < len(dict[wnum]):
    print(int(ans -(factorial(len(l)) / 2 / factorial(len(l) - 2)) + factorial(len(l)-1) / 2 / factorial(len(l)-1 - 2)))
  elif 2 == len(dict[wnum]):
    print(int(ans - 1))
  else:
    print(int(ans))

Submission status: Runtime Error

Solution code:
#5
#1 1 2 1 2
from math import factorial

n = int(input())
A = list(map(int,input().split()))
dict = {}

for i,a in enumerate(A):
  if a in dict:
    dict[a].append(i)
  else:
    dict[a]=[i]

ans = 0    
    
for k,v in dict.items():
  if len(v) >= 2:
    ans += factorial(len(v)) / 2 / factorial(len(v) - 2)

#print(dict)
#print(int(ans))
#print("kk")
  
for i in range(n):
  wnum = A[i]
  l=dict[wnum]
  if 2 < len(dict[wnum]):
    print(int(ans -(factorial(len(l)) / 2 / factorial(len(l) - 2)) + factorial(len(l)-1) / 2 / factorial(len(l)-1 - 2)))
  elif 2 == len(dict[wnum]):
    print(int(ans - 1))
  else:
    print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
al=list(map(int,input().split()))

counter=[0]*(n+1)
for a in al:
    nums[a]+=1

sum=0
for c in counter:
    sum+=c*(c-1)//2

for a in al:
    print(sum-(counter[a]-1))

Submission status: Runtime Error

Solution code:
n=int(input())
al=list(map(int,input().split()))

counter=[0]*n
for a in al:
    nums[a]+=1

sum=0
for c in counter:
    sum+=c*(c-1)//2

for a in al:
    print(sum-(counter[a]-1))

Submission status: Runtime Error

Solution code:
import math

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

n = (int)(input())
a = list(map(int, input().split(" ")))
temp = []
for i in range(n):
  temp.append(a.count(i))
  
ans = 0
#print(temp)#各数字の出現回数
for i in range(n):
  if temp[i] >= 2:
    ans += comb(temp[i], 2)
    
#print(ans)#ansは全体の組み合わせの合計。割れない

for i in range(n):
  kotae = ans
  if temp[a[i]] >= 3:
    #print(ans, comb(temp[a[i]], 2), comb(temp[a[i]] - 1, 2))
    kotae = ans - comb(temp[a[i]], 2) + comb(temp[a[i]] - 1, 2)
  elif temp[a[i]] == 2:
    kotae = ans -1
  print(kotae)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.misc import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    if counter[a] < 3:
        print(0)
    else:
        print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    if counter[a] < 3:
        print(0)
    else:
        print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))

Submission status: Runtime Error

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

import collections
import math

dicA = collections.Counter(A)

total = 0
for x in list(dicA.values()):
  total += math.factorial(x) // (math.factorial(x - 2)*2)

for i in range(N):
  print(total - dicA[A[i]] +1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
def possibleCombos(num):
    num2 = num - 1
    return (num2*num2 + num2)//2
N = int(input())
A = [int(i) for i in input().split()]
data = [0] * N
total = 0
for i in A:
    data[i] +=1
for i in data:
    total += possibleCombos(i)
for i in A:
    result = total - possibleCombos(data[i]) + possibleCombos(data[i]-1)
    print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
c = [0 for i in range(n)]
b = sorted(a)
cnt = 1
for i in range(n-1):
  if b[i]==b[i+1]:
    cnt += 1
  else:
    c[b[i]] = cnt
    cnt = 1
  if i==n-2:
    c[b[n-1]] = cnt
ans = 0
for i in range(n):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))

Submission status: Runtime Error

Solution code:
N = int(input())
K = list(map(int,input().split()))
A = [0]*N
for i in range(N):
    A[K[i]] += 1
r = 0
for k in range(N):
    r += 0.5*(A[k]*(A[k]-1))
An =[]
for j in range(N):
    D = A[K[j]]-1
    An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))
for i in range(len(An)):
    print(An[i])

Submission status: Runtime Error

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

for k in range(n):
    print(al - (l[a[k]] - 1))

Submission status: Runtime Error

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

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in enumerate(a_count.items()):
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

count = Counter(A)

ans = sum([v ** (v - 1) // 2 for v in count.values()])

for a in A:
  value = count[a] -1
  ans2 = value * (value -1) // 2
  print(ans - ans2)

Submission status: Runtime Error

Solution code:
n = int(input())

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

int i = 0

for int i in range(n):
  C[i] = A.count(A[i])

if(C[i] == 0) print(0)
else print(int(C[i]*(C[i]-1)/2)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from scipy.special import comb


def nCr(n, r):
    return comb(n, r, exact=True)


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

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

for k in range(N):
    t = A[k]
    h[t] -= 1

    ans = 0
    for a, n in h.items():
        if n >= 2:
            ans += nCr(n, 2)
    print(ans)

    h[t] += 1

Submission status: Runtime Error

Solution code:
# D - Banned K

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

def f(i, ls, chosen):
    n1 = len(ls)
    n2 = len(chosen)
    if n1 <= i or n2 == 2:
        if n2 == 2 and chosen[0] == chosen[1]:
            return 1
        return 0
    return f(i + 1, ls, chosen) + f(i + 1, ls, chosen + [ls[i]])

for i in range(N):
    print(f(0, A[:i] + A[i + 1:], []))

Submission status: Runtime Error

Solution code:
import copy
import collections

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

nCr = {}
def cmb(n,r):
    if (n,r) in nCr:
        return nCr[(n,r)]
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

col = collections.Counter(A)
for a in A:
    s = 0
    if a in col.keys():
        col[a] = col[a] - 1
        for i in col:
            s += cmb(col[i],2)
        col[a] = col[a] + 1         
    print(s)

Submission status: Runtime Error

Solution code:
import copy
import collections

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

nCr = {}
def cmb(n,r):
    if (n,r) in nCr:
        return nCr[(n,r)]
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

col = collections.Counter(A)
for a in A:
    c = col.copy()
    c[a] = c[a] - 1
    s = 0
    for i in c:
        s += cmb(c[i],2)
    print(s)

Submission status: Runtime Error

Solution code:
import copy
import collections

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

nCr = {}
def cmb(n,r):
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n,r) in nCr:
        return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

col = collections.Counter(A)
for a in A:
    c = col.copy()
    c[a] = c[a] - 1
    s = 0
    for i in c:
        s += cmb(c[i],2)
    print(s)

Submission status: Runtime Error

Solution code:
"""from operator import mul
from functools import reduce
 
def cmb(n,r):
  if n<2: return 0
  r = min(n-r,r)
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
"""
from math import factorial
def cmb(n,r=2):
  
  return factorial(n) / factorial(r) / factorial(n - r)
 
 
N=int(input())
a_lis=list(map(int,input().split()))
 
olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
#print(olt)
for j in range(N):
  index=a_lis[j]
  olt[index]-=1
  #print(olt)
  san=0
  for i in set(a_lis):
    if olt[i] <2:
      continue
    #print(i,olt[i])
    san+=cmb(olt[i])
  
  print(int(san))
  olt[index]+=1

Submission status: Runtime Error

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

def cmb(n,r):
  if n<2: return 0
  r = min(n-r,r)
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
"""
from math import factorial
def cmb(n,r=2):
  
  return factorial(n) / factorial(r) / factorial(n - r)


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

olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
#print(olt)
for j in range(N):
  index=a_lis[j]
  olt[index]-=1
  #print(olt)
  san=0
  for i in set(a_lis):
    if olt[i] <2:
      continue
    #print(i,olt[i])
    san+=cmb(olt[i])
  
  print(int(san))
  olt[index]+=1

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
  	if n == 1 or n == 0: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
for j in range(n):
  index=a_lis[j]
  olt[index]-=1
  
  z=sum([cmb(k,2) for key,k in olt])
  print(z)
  olt[index]+=1

Submission status: Runtime Error

Solution code:
import math

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

equal = 0
elements = set(A)
for e in elements:
    tmp = A.count(e)
    equal += math.factorial(tmp) // (2 * math.factorial(tmp - 2))

for i in range(n):
    A_tmp = A[: i] + A[i + 1: ]
    equal_i = A_tmp.count(A[i])
    print(equal - equal_i)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))

C = list(itertools.combinations(A, 2))
C = list(c for c in C if c[0] == c[1])
equal = len(C)

for i in range(n):
    A_tmp = A[: i] + A[i + 1: ]
    equal_i = A_tmp.count(A[i])
    print(equal - equal_i)

Submission status: Runtime Error

Solution code:
import collections
import copy
import math


def combinations_count(n, r=2):
    return n * (n-1) // 2


def main(N, A):
    for i in range(N):
        copy_A = copy.copy(A)
        copy_A.pop(i)
        dic_copy_A = dict(collections.Counter(copy_A))

        count = 0
        for v in dic_copy_A.values():
            if v >= 2:
                count += combinations_count2(v, 2)

        print(count)
        
        
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)

Submission status: Runtime Error

Solution code:
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return int(factorial(n) / factorial(r) / factorial(n - r))
  elif n == 1:
      return 1
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

Submission status: Runtime Error

Solution code:
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return int(factorial(n) / factorial(r) / factorial(n - r))
  elif n == 1:
      return 1:
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

Submission status: Runtime Error

Solution code:
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return int(factorial(n) / factorial(r) / factorial(n - r))
  elif:
    n == 1:
      return 1:
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

Submission status: Runtime Error

Solution code:
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return int(factorial(n) / factorial(r) / factorial(n - r))
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

Submission status: Runtime Error

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()
    c = collections.Counter(d)
    nCr = {}

    def cmb(n, r):
        if r == 0 or r == n: return 1
        if n < r: return 0
        if r == 1: return n
        if (n, r) in nCr: return nCr[(n, r)]
        nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
        return nCr[(n, r)]

    total = 0
    for v in c.values():
        total += cmb(v, 2)

    for i in range(n):
        v = c[d[i]]
        tmp1 = cmb(v, 2) - cmb(v-1, 2)

        print(int(total - tmp1))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()
    c = collections.Counter(d)

    total = 0
    for v in c.values():
        if v - 2 > -1:
            total += math.factorial(v) / math.factorial(2) / math.factorial(v - 2)

    for i in range(n):
        v = c[d[i]]
        tmp1 = 0
        if v - 2 > -1:
            tmp1 = math.factorial(v) / math.factorial(2) / math.factorial(v - 2) * (2 / v)

        print(int(total - tmp1))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n= int(input())
a=list(map(int, input().split()))
b = [0]*(n+1)
c = [0]*(n+1)
su = 0

for x in range(n):
    b[a[x]] += 1

for y in range(len(b)):
    if b[y] >=2:
        c[y]=combinations_count(b[y], 2)
    else:
        c[y]=0
    su += c[y]

for z in range(n):
    if c[a[z]] > 0:
        ans = su - (b[a[z]] - 1)
    else:
        ans = su

    print(str(ans))

Submission status: Runtime Error

Solution code:
from math import factorial
def comb(n,r=2):
    if n == 1 or n == 0:
        return 0
    return int(factorial(n) / factorial(r) / factorial(n - r))

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

count = {}
ans = 0

for i in range(n):
    count.setdefault(a[i], 0)
    count[a[i]] += 1

for v in count.values():
    ans += comb(v)


for i in range(n):
    v = count[a[i]]
    print(ans - comb(v) + comb(v-1))

Submission status: Runtime Error

Solution code:
from math import factorial
def comb(n,r=2):
    if n == 1:
        return 0
    return int(factorial(n) / factorial(r) / factorial(n - r))

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

count = {}
ans = 0

for i in range(n):
    count.setdefault(a[i], 0)
    count[a[i]] += 1

for v in count.values():
    ans += comb(v)


for i in range(n):
    v = count[a[i]]
    print(ans - comb(v) + comb(v-1))

Submission status: Runtime Error

Solution code:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Submission status: Runtime Error

Solution code:
import copy
# In=[list(map(int,i.split())) for i in Input.split('\n')]
# N=In[0][0]
# A=In[1]
N=int(input())
I=list(map(int,input().split()))
for j in range(N):
    counter=[0 for i in range(N+1)]
    A=copy.deepcopy(I)
    A.pop(j)
    B=[]
    for i in A:
        counter[i]+=1
    for i in counter:
        if i>1:
            B.append(f(i)/(f(2)*f(i-2)))
    print(int(sum(B)))

Submission status: Runtime Error

Solution code:
import copy
# In=[list(map(int,i.split())) for i in Input.split('\n')]
# N=In[0][0]
# A=In[1]
N=int(input())
In=list(map(int,input().split()))
for j in range(N):
    counter=[0 for i in range(N+1)]
    A=copy.deepcopy(In)
    A.pop(j)
    B=[]
    for i in A:
        counter[i]+=1
    for i in counter:
        if i>1:
            B.append(f(i)//(f(2)*f(i-2)))
    print(sum(B))

Submission status: Runtime Error

Solution code:
import copy
# In=[list(map(int,i.split())) for i in Input.split('\n')]
# N=In[0][0]
# A=In[1]
N=int(input())
A=list(map(int,input().split()))
for j in range(N):
    counter=[0 for i in range(N+1)]
    A=copy.deepcopy(In[1])
    A.pop(j)
    B=[]
    for i in A:
        counter[i]+=1
    for i in counter:
        if i>1:
            B.append(f(i)//(f(2)*f(i-2)))
    print(sum(B))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
dic={}
for i in set(A):
  dic[i]=A.count(i) 
def ans(k,dic):
  dic[A[k-1]]+=-1
  c=0
  for i in dic.values():
    c+=i*(i-1)/2
  dic[A[k-1]]+=1  
  return int(c)
for k in range(1,N+1):

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)
for each in a_types:
    count_dict[each - 1] += A.count(each)

count_dict = [0] * N
for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))

count_dict = [0] * N
for each in A:
    count_dict[each] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a] + 1)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)

count_dict = [0] * N
for each in A:
    count_dict[each] = A.count(each)

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a] + 1)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)

count_dict = [0] * N
for each in a_types:
    count_dict[each] = A.count(each)

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a] + 1)