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:
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
i=0
dict={}
for x in C:
  if x==1:
    break
  count+=x*(x-1)/2
  dict[V[i]]=x
  i+=1
for x in B:
  ans=count-dict[x]+1
  print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = A
count=0
while len(B)!=0:
  b=B[1]
  C=[i for i in B if i != b]
  count+=(len(B)-len(C))*(len(B)-len(C)-1)/2
  B=C
ans=list(map(lambda x: count-(A.count(x)-1),A))
for x in ans:
  print(int(x))

Submission status: Runtime Error

Solution code:
def f(n):
  return (n*(n-1))//2
N=int(input())
A=list(map(int,input().split()))
d=dict()
ans=0
#それぞれが何個あるかを辞書に登録
for i in range(len(A)):
  if A[i] not in d:
    d[i]=0
  d[i]+=1
for i in d:
  ans+=f(d[i])
for i in range(len(A)):
  print(ans-d[A[i]]-1)

Submission status: Runtime Error

Solution code:
n = int(input())
 
li = list(map(int, input().split()))
 
ans = [0]*n
for i in range(n):
    li2 = li.copy()
    del li2[i]
    li3 = list(set(li2))
    for j in range(len(li3)):
        m = li2.count(li3[j])*(li2.count(li3[j])-1)/2
        ans[i] += m
for l in range(len(ans)):
    print(int(ans[l]))

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dict[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力 : N
# 入力 : A1 A2 ... AN
N = int(input())
A = list(map(int, input().split()))

Number = []
PosNum = []
NegNum = []

for i in range(N):
    Number.append(A.count(i+1))
    PosNum.append(Number[i]*(Number[i]-1)/2)
    NegNum.append(- Number[A[i]-1]*(Number[A[i]-1]-1)/2 + (Number[A[i]-1]-1)*(Number[A[i]-1]-2)/2)

Total = sum(PosNum)

for k in range(N):
    print(int(Total + NegNum[k]))

Submission status: Runtime Error

Solution code:
import collections
from scipy import special

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

for i in range(0, n):
    target_list = num_list[0:i] + num_list[i+1:]
    target_items = collections.Counter(target_list).items()
    ans = 0

    for item in target_items:
        if item[1] > 1:
            ans += special.comb(item[1], 2, True)

    print(ans)

Submission status: Runtime Error

Solution code:
import collections
from scipy import special

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

for i in range(0, n):
    target_list = num_list[0:i] + num_list[i+1:]
    target_items = collections.Counter(target_list).items()
    ans = 0

    for item in target_items:
        if item[1] > 1:
            ans += special.comb(item[1], 2, True)

    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    for j in range(n):
        if i!=j:
            for k in range(j+1,n):
                if a[j]==a[k]:
                    ans[i]+=1
for i in range(n):
    print(ans[n])

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
for k in range(N):
  ak=A[k]
  del A[k]
  AA=sorted(A)
  AA.append(0)
  s=1
  ans=0
  for i in range(N-1):
    d=AA[i+1]-AA[i]
    if d == 0:
      s+=1
    else:
      ans+=int(s*(s-1)/2)
      s=1
  del AA[N-1]
  print(ans)
  A.insert(k,ak)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
for k in range(N):
  del A[k]
  AA=sorted(A)
  s=1
  for i in range(N-3):
    d=AA[i+1]-AA[i]
    if d == 0:
      s+=1
    else:
      ans+=int(s*(s-1)/2)
      s=1
  print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
for k in range(N):
  del A[k]
  AA=sorted(A)
  s=0
  for i in range(N-3):
    d=A[i+1]-A[i]
    if d == 0:
      s+=1
    else:
      ans+=int(s*(s-1)/2)
      s=0
  print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	long long n, a[200005], fre[200005];
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		fre[a[i]] ++;
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans = (ans + (fre[i] * (fre[i] - 1)) / 2);
	}
	for (int i = 1; i <= n; ++i)
	{
		cout << ans - fre[a[i]] + 1 << '\n';
	}
	return 0;
}

Submission status: Runtime Error

Solution code:
import copy

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

for i in range(N):
    k=i+1
    B = copy.copy(A)
    B.pop(i)
    C = [0]*(N-1)
    for l in range(N-1):
        C[B[l]] += 1
    temp = 0
    for m in range(N-1):
        temp += int(C[m]*(C[m]-1)/2)
    print(temp)

Submission status: Runtime Error

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を消さない場合の場合分けの個数
ans = 0
for d in dict.values():
    if d > 1:
        ans += (d * (d - 1)) // 2

# k番目の値を除いた場合に減る場合の数を引いて答えを出力
memo = {}
for k in range(N):
    w = dict[A[k]]
    # 減る数
    if w == 1:
        pass
    elif w == 2:
        decrease = -1
    elif w > 2:
        decrease = ((w - 1) * (w - 2) // 2) - (w * (w - 1) // 2 )
    print(ans + decrease)

Submission status: Runtime Error

Solution code:
import collections as cl
N = int(input())
A = list(map(int,inpput().split()))
cn = cl.Counter(A)
sumC = sum([n*(n-1)//2 for n in cl.values()])
for k in range(N):
  print(sumC - cn[A[k]] +1)

Submission status: Runtime Error

Solution code:
import collections as cl
N = int(input())
A = list(map(int,inpput().split()))
cn = cl.Counter(A)
sumC = sum([n*(n-1)//2 for n in cl.values()])
for k in range(N):
  print(sumC - cn[k] +1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = [0]*n
count = 0
for el in a:
    temp = d[el]
    if temp == 0:
        temp = a.count(el)
        d[el] = temp
    count += temp-1
count //= 2
for el in a:
    print(count - d[el] + 1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = [0]*n
count = 0
for el in a:
    temp = a.count(el)
    count += temp-1
    d[el] = temp
count //= 2
for el in a:
    print(count - d[el]+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
  res += choose2(k, 2)

for k in A:
  temp = res
  m = d[k]
  temp -= choose2(m, 2, mod)

  d[k] -= 1
  temp += choose2(d[k], 2, mod)
  print(temp)
  d[k] += 1

Submission status: Runtime Error

Solution code:
def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0

    def comb(m, n):
        return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''

    C = collections.Counter(A)
    for i in C.values():
        f = i
        if f>=2:
            tt = tt + comb(f, 2)

    for i in A:
        f = C[A[i]] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(ann)

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
array = list(map(int, input().split()))
sameNum = [0]*(N)

for i in range(N):
    sameNum[array[i]-1] += 1

for k in range(1, N+1):
    answer = 0
    sameNumT = sameNum.copy()
    sameNumT[array[k-1]-1] -= 1
    for l in range(N):
        answer += sameNumT[l]*(sameNumT[l]-1)//2
    print(answer)

Submission status: Runtime Error

Solution code:

N = int(input())
a = [int(i) for i in input().split()]
for i in range(N):
  ans = 0
  tmp = []
  tmp = a.copy()

  count = {}
  tmp.pop(i)
  for j in tmp:
    if ((j in [k for k in count.keys()]) == False):
      count[j] = 1
    else:
      count[j] += 1

  for k in count.keys():
    # aCb
    l = count[k]
    r = 2
    ans += (l * (l - 1)) / 2
  print(ans)

Submission status: Runtime Error

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

arr = [0]*(n+1)
for i in range(n):
    arr[a[i]] += 1

from scipy.special import comb
base = comb(5, 3, exact=True)

c = [0]*(n+1)
for i in range(n+1):
    c[i] = int(comb(arr[i],2))

d = [0]*(n+1)
for i in range(n+1):
    d[i] = int(comb(arr[i]-1,2))


for k in range(n):
    ans = sum(c[:a[k]]) + sum(c[a[k]+1:]) + d[a[k]]
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
IND = list(set(A))
CNT = [A.count(x) for x in IND]
# print(IND)
# print(CNT)
# CONB = [A.count(x)*(A.count(x)-1)//2 for x in IND]
CONB = [CNT[x]*(CNT[x]-1)//2 for x in range(len(CNT))]
# print(CONB)
SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i-1] + 1
    print(ans)

Submission status: Runtime Error

Solution code:
import functools
from collections import Counter


@functools.lru_cache(maxsize=None)
def factorial(N):
    if N == 0:
        return 1
    if N == 1:
        return 1
    else:
        return N * factorial(N - 1)


def c(n, r):
    if n < r:
        return 0
    return factorial(n) // (factorial(r) * factorial(n-r))


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

C = dict(Counter(A))
for a in A:
    n = 0
    for k, N_k in C.items():
        n += c(N_k - (k == a), 2)
    print(n)

Submission status: Runtime Error

Solution code:
n =int(input()),l = list(map(int, input().split()))
for i in l:
  a=l.copy()
  a.remove(i)
  print(sum([a.count(j) * (a.count(j) - 1) // 2 for j in set(a) if a.count(j)>1]))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[*map(int,input().split())]
for i in range(n):
    res=[]
    for j in sorted(set(l)):
        m=l.count(j) if(j!=l[i]) else l.count(j)-1
        m*=(m-1)
        m//=2
        res.append(m)
    print(sum(res))

Submission status: Runtime Error

Solution code:
import collections
import math

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)


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

sum_count = sum([combinations_count(n, 2) for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)

Submission status: Runtime Error

Solution code:
import collections
import math

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

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)

sum_count = sum([combinations_count(n, 2) for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[*map(int,input().split())]
for i in range(n):
    k=l[i]
    res=[0]
    for j in set(l):
        m=l.count(j) if(j!=k) else l.count(j)-1
        m*=(m-1)
        m//=2
        res.append(m)
    print(sum(res) )

Submission status: Runtime Error

Solution code:
n=int(input())
l=[*map(int,input().split())]
for i in range(n):
    k=l[i]
    res=[]
    for j in set(l):
        m=l.count(j) if(j!=k) else l.count(j)-1
        m*=(m-1)
        m//=2
        res.append(m)
    print(sum(res))

Submission status: Runtime Error

Solution code:
from math import factorial

N = int(input())
line = input()
l = []
counts = {}
for n in line.split(' '):
  n = int(n)
  if n not in counts:
    counts[n] = 0
  counts[n] += 1
  l.append(n)

results = {}

for n in counts:
  results[n] = 0
  for m in counts:
    count = counts[m]
    if m == n:
      count -= 1
    if count > 1:
      results[n] += factorial(count) / 2 / factorial(count - 2) 

for n in l:
  print(int(results[n]))

Submission status: Runtime Error

Solution code:
def comb(n,k):
  x,y=1,1
  for i in range(k):
    x*=n-i
    y*=k-i
  return x//y

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

for i in range(n):
  num = a.count(a[i])
  comb[i] = comb(num,2)-num+1 if num >= 2 else 0

print(*comb,sep='\n')

Submission status: Runtime Error

Solution code:
N = int(input())
A = [a for a in map(int, input().split())]

#N個のボールに対して、書かれている数字は1~Nまで

dic1 = {}
for i in range(N):
    dic1[i] = 0

#dicにkeyとなる数字の個数を入れていく
for i in A:
    if i in dic1.keys():
        dic1[i] += 1

dic2 = {}
#組み合わせの数を入れる   
for i in range(N):
    dic2[i] = dic1[i]*(dic1[i]-1)/2

ans1 = 0
for i in range(N):
    ans1 += dic2[i]

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] #組み合わせの数を引く
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2 #新たな組み合わせの数を足す
    print(int(ans2))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [a for a in map(int, input().split())]

#N個のボールに対して、書かれている数字は1~Nまで

dic1 = {}
for i in range(N):
    dic1[i] = 0

#dicにkeyとなる数字の個数を入れていく
for i in A:
    if i in dic1.keys():
        dic1[i] += 1

dic2 = {}
#組み合わせの数を入れる   
for i in range(N):
    dic2[i] = dic1[i]*(dic1[i]-1)/2

ans1 = 0
for i in range(N):
    ans1 += dic2[i]

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] #組み合わせの数を引く
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2
    print(ans2)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split(" ")))
m = Counter(A)
def nck(n, k): 
    C = [[0 for x in range(k+1)] for x in range(n+1)] 
  
    # Calculate value of Binomial Coefficient in bottom up manner 
    for i in range(n+1): 
        for j in range(min(i, k)+1): 
            # Base Cases 
            if j == 0 or j == i: 
                C[i][j] = 1
  
            # Calculate value using previously stored values 
            else: 
                C[i][j] = C[i-1][j-1] + C[i-1][j] 
  
    return C

CHOOSE_MATRIX = nck(max(A) + 1, 2)
total = 0
for key, value in m.items():
        # if key == A[i]:
        #     continue
        # else:
        total += CHOOSE_MATRIX[value][2]


for i in range(len(A)):
    newtotal = total
    # m[A[i]] -= 1
    # for key, value in m.items():
    #     # if key == A[i]:
    #     #     continue
    #     # else:
    #     total += CHOOSE_MATRIX[value][2]
    # m[A[i]] += 1
    tosubtract = CHOOSE_MATRIX[m[A[i]]][2]
    newtotal -= tosubtract
    newtotal += CHOOSE_MATRIX[m[A[i]]- 1][2]
    print(newtotal)
    # print(uniquethings*(uniquethings)//2)
    # print(total)

Submission status: Runtime Error

Solution code:


from collections import Counter
N = int(input())
A = list(map(int, input().split(" ")))
def nck(n, k):
    if k > n:
        return 0
    else:
        return factorial(n)//(factorial(n-k)*factorial(k))

def factorial(n):

    if n<= 1:
        return 1
    else:
        return n*factorial(n-1)


for i in range(len(A)):
    total =0
    m = Counter(A[:i] + A[i+1:])
    for key, value in m.items():
        total += nck(value, 2)

    # print(uniquethings*(uniquethings)//2)
    print(total)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]]+1)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]]-1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=(input().split())
for i in range(n):
    x=0
    for j in range(n):
        for k in range(n):
            if j>k and a[j]==a[k] and j!=i and k!=i:
                x=x+1
    print(x)

Submission status: Runtime Error

Solution code:
from math import factorial

n = int(input())
li_a = list(map(int, input().split()))
d_cnt = dict()
for a in li_a:
    d_cnt[a] = d_cnt.get(a, 0) + 1

for a in li_a:
    w_d = d_cnt.copy()
    w_d[a] -= 1
    w_answer = 0
    for key, value in w_d.items():
        if value >= 2:
            w_answer += factorial(value) / factorial(2) / factorial(value - 2)
    print(int(w_answer))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
D = defaultdict(int)
for a in A:
    D[a] += 1
 
ans_base = 0
for v in D.values():
    ans_base += v * (v - 1) // 2
 
for a in A:
    print(ans_base - (D[a] * (D[a] - 1) // 2) + ((D[a] - 1) * (D[a] - 2) // 2))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
mat = [0 for i in range(n+1)]
for i in range(n):
    if mat[a[i]] != 0:
        print(mat[a[i]])
    else:
        count = [0 for i in range(n+1)]
        for j in nange(n):
            if count[a[j]] != 0:
                count[a[j]]
            for k in range(n):
                if j != i and k != i and j != k and a[j] == a[k]:
                    count += count[a[j]]

def c(num):
    if num >= 2:
        return (num*(num-1))/2
    return 0

Submission status: Runtime Error

Solution code:
#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

#dic_sum = dic.copy()
s = 0
#calcurate
for d in dic:
  s += int(dic[d]*(dic[d]-1)/2)
  
for i in range(inp):
  #dic_sum_n = dic_sum.copy()
  t = dic[lis[i]]
  print(s-int(t*(t-1)/2)+int((t-1)*(t-2)/2))

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
cnts = Counter(a)

_sum = 0
for key,value in cnts.items():
    _sum +=  value*(value-1)//2

for ai in a:
    ans = _sum
    c = cnts.count(ai)
    ans -= c*(c-1)//2
    ans += (c-1)*(c-2)//2
    print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
    B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
    u = np.unique(ar, return_index=True)[1]
    u = np.concatenate([u, np.array([N-1])])
    ans = 0
    for i in range(len(u)-1):
        n = u[i+1] - u[i]
        ans += comb(n, 2)
    return ans

#ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)
for i in range(len(B)):
    print(uniq_2_comb(N, B[i]))
  

#for a in ans_ar:
#    print(a)

Submission status: Runtime Error

Solution code:
tmp = int(input())
numbers = [map(int,input().split())]
dic = {}
for i, num in enumerate(numbers):
  if not num in dic:
    dic[num] = 0
  dic[num] = dic[num] + 1
for i in range(tmp):
  num = numbers[i]
  ans = 0
  for k,v in dic.items():
    if k == num:
      ans = ans + int((v-1) * (v-2) / 2)
    else:
      ans = ans + int(v * (v-1) / 2)
  print(ans)

Submission status: Runtime Error

Solution code:
tmp = int(input())
numbers = [map(int,input().split())]
dic = {}
for i, num in numbers.enumerate():
	dic[num] = dic[num] + 1
for i in range(tmp):
	num = numbers[i]
    ans = 0
    for k,v in dic.items:
      if k == num
      	ans = ans + (v-1) * (v-2)/2 
      else
      	ans = ans + v * (v-1)/2
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
h, w, k = map(int, input().split())
li_hw =  [list(f) for f in [input() for _ in range(h)]]
all_h = []
score = []
# for l in range(2**(h-1)):
#     ind = []
#     pre = 0
#     cut_list=[]
#     hline_num = 0
#     for n,yn in enumerate(reversed(list(bin(l))[2:])):
#         if yn == "1":
#             cut_list.append(li_hw[pre:n+1])
#             pre = n+1
#     cut_list.append(li_hw[pre:h])
for i in itertools.product([0, 1], repeat=h-1):
    cut_list=[]
    hline_num = 0
    pre = 0
    cut_list = []
    for n, i2 in enumerate(i):
        if i2 == 1:
            cut_list.append(li_hw[pre:n+1])
            pre = n+1
    cut_list.append(li_hw[pre:h])
    hline_num = i.count(1)
    pred = 0
    wline_num = 0
    #print("list is {}".format(cut_list))
    
    
    for y in range(w):
        wcounter_list = []
        for c in cut_list:
            wcounter = 0
            for c2 in c:
                wcounter += c2[pred:y+1].count("1")
            wcounter_list.append(wcounter)
        #print("wcounter{}".format(wcounter_list))
        if max(wcounter_list) > k:
            pred = y
            wline_num += 1
            #print("line between{}and{}".format(y-1, y))
    #print("wline{}, hline{}".format(wline_num, hline_num))
    score.append(wline_num+hline_num)
print(min(score))

Submission status: Runtime Error

Solution code:
import collections
import math

# 組み合わせ算出
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':
    N= int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    result = 0
    for i in set(a):
        result += combinations_count(c[i], 2)

    for i in a:
        d = c[i]
        print(result -  combinations_count(d, 2) + combinations_count(d-1, 2))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = input().split()
an = 0
ck = 0
tmp0 = a
beforeai = 0
beforei = 0

for i in range(n):
    #print("tmp1[i]")
    #rint(a[i])
    beforeai = a[i]
    beforei = i
    a[i] = ' '#配列nを''に変更 
    #print("Counter:tmp1")
    print(a)
    tmp2 = Counter(a)
    #print("Counter:tmp2")
    #print(tmp2)
    an = 0
    for key in tmp2.keys():#keyごとの足し算ができた
        ck = tmp2[key]
        #print("ck")
        if ck == 1:
            an = an + 1
        else:
            an = an + (ck*(ck-1)//2)
    print(an - 1)
    a[beforei] = beforeai

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
    B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
    u = np.unique(ar, return_index=True)[1]
    u = np.concatenate([u, np.array([N-1])])
    ans = 0
    for i in range(len(u)-1):
        n = u[i+1] - u[i]
        ans += comb(n, 2)
    return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for a in ans_ar:
    print(a)

Submission status: Runtime Error

Solution code:
import math

# 組み合わせ算出
def combinations_count(n, r):
    if n == 1:
        return 0
    if n == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':

    N= int(input())

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

    for i in range(N):
        total = 0

        b = a[:i] + a[i+1:]

        c = collections.Counter(b)

        for j in set(a):

            total = total + combinations_count(c[j], 2)

        print(total)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
    B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
    u = np.unique(ar, return_index=True)[1]
    u = np.concatenate([u, np.array([N-1])])
    ans = 0
    for i in range(len(u)-1):
        n = u[i+1] - u[i]
        ans += comb(n, 2)
    return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
    print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
  if n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N-1])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N-1])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)

Submission status: Runtime Error

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

ad = dict((i, a.count(i)) for i in set(a))

for i in range(n):
  ans = 0
  for v in list(ad):
    ans += ad[v]*(ad[v]-1)//2 if a[v] != v else (ad[v]-1)*(ad[v]-2)//2
   
  print(ans)

Submission status: Runtime Error

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

for e in A:
    d = dict((i, A.count(i)) for i in set(A))
    d[e]-=1
    
    ans = 0
    for i in list(d):
        if d[i] < 2:
            continue
        ans += d[i]*(d[i]-1)/2
    print(int(ans))

Submission status: Runtime Error

Solution code:
import math
N = input()
A = map(int,inp.split())

for e in A:
    d = dict((i, A.count(i)) for i in set(A))
    d[e]-=1
    
    ans = 0
    for i in list(d):
        if d[i] < 2:
            continue
        ans += d[i]*(d[i]-1)/2
    print(int(ans))

Submission status: Runtime Error

Solution code:
import math
N, *A = map(int,inp.split())

for e in A:
    d = dict((i, A.count(i)) for i in set(A))
    d[e]-=1
    
    ans = 0
    for i in list(d):
        if d[i] < 2:
            continue
        ans += d[i]*(d[i]-1)/2
    print(int(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)