Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

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

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

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

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

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5



Sample input:
5
1 1 2 1 2


Sample output:
2
2
3
2
3

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7




n = 200000
a = I()
b = LI()
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod


inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod

L = [168769] * n
cnt = Counter(L)
ret = 0
for i in cnt.values():
    ret += comb(i, 2)
for l in L:
    if cnt[l] < 2:
        print(ret)
    else:
        print(ret - comb(cnt[l], 2) + comb(cnt[l] - 1, 2))

Submission status: Wrong Answer

Solution code:
n=int(input())
L=list(map(int,input().split()))
NW=[]
for i in range(n+1):
    NW.append(L.count(i))
print(NW)
for i in L:
    NW[i]=NW[i]-1
    num=0
    for j in range(n):
        if NW[j]>=2:
            num+=1
    print(num)
    NW[i]=NW[i]+1

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
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 ans:
    print(i)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
#最後の方のテストケースでREになってしまう。時間切れ。
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

N = int(input())

s = input().split()
p = [int(w) for w in s]
print('p:{}'.format(p))

number_list = []
'''
for i in range(N):
    counter = 0
    for j in range(N):
        if(p[j] == i+1):
            counter +=1
    number_list.append(counter)
'''
for i in range(N):
    #print(mylist.count("A"))
    number_list.append(p.count(i+1))
#print('number_list:{}'.format(number_list))

def n_C_2(n):
    if(n == -1):
        return 0
    else:
        return int(n * (n-1) / 2)


full_combi = []
pickup_combi = []
print_combi = []

for i in range(N):
    full_combi.append(n_C_2(number_list[i]))
    pickup_combi.append(n_C_2(number_list[i] - 1))
#print('full_combi:{}'.format(full_combi))
#print('pickup_combi:{}'.format(pickup_combi))

for i in range(N):
    print_combi.append(sum(full_combi) - full_combi[i] + pickup_combi[i])
#print('print_combi:{}'.format(print_combi))

for i in range(N):
    index = p[i] - 1
    print(print_combi[index])

Submission status: Wrong Answer

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))
        return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2

    '''
    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():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[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: Wrong Answer

Solution code:
# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

# 各数字を連続でとる場合の数
from math import factorial
def kumiawase_num(n, r): # 組み合わせ n「C」r
    if  n<r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

for i,v in enumerate(k):
    D[i] =[ kumiawase_num(A[ij]-1,2) for ij,vj in A.items() if v == ij ]
    D2[i] = [ kumiawase_num(A[ij] ,2) for ij,vj in A.items() if v != ij ] 

D3 = [ sum(i) + sum(v) for i,v in zip(D.values(),D2.values()) ]

Submission status: Wrong Answer

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)
  s=1
  ans=0
  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)
  A.insert(k,ak)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (N+1)
ans = 0
for i in range(N):
  cnt[A[i]] += 1
for i in range(N):
  ans += cnt[i] * (cnt[i] - 1) // 2
for i in range(N):
  print(ans - cnt[A[i]] + 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    c = Counter(a)
    b = sum(v * (v - 1) // 2 for v in c.values())
    print(c, b)
    return "\n".join(str(b - c[_a] + 1) for _a in a)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = [0] * (n + 1)
total = 0

for v in a:
    count[v] += 1

for i in range(1, n):
    total += int(count[i] * (count[i] - 1) / 2)

for v in a:
    print(total - count[v] + 1)

Submission status: Wrong Answer

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

# 1が3個、2が５個、、、みたいなものを管理する配列
counter = [0 for i in range(N+1)]
for i in range(N):
    counter[As[i]] += 1

# kC2を求める。（2C2 ~ NC2まで）
k_C_2 = [0 for i in range(N+1)]
k_C_2[2] = 1
for i in range(3, N+1):
    k_C_2[i] = k_C_2[i-1] * i / (i-2)


# 全体を求める
all_case = 0
for i in range(N):
    if counter[i] >= 2:
        all_case += k_C_2[counter[i]]

# 除く
for i in range(N):
    if counter[As[i]] == 2:
        print(int(all_case - 1))
    elif counter[As[i]] >= 3:
        print(int(all_case - k_C_2[counter[As[i]]] + k_C_2[counter[As[i]]-1]))
    else:
        print(int(all_case))

Submission status: Wrong Answer

Solution code:
n=int(input())
array=list(map(int,input().split()))
tot=0
x=0
count=[0]*10000000
for c in range(n):
  count[array[c]]+=1
for c in range(n):
  if x<array[c]:
    x=array[c]
    t=count[array[c]]
    tot+=int(t*(t-1)/2)
for i in range(n):
  ans=tot
  l=count[array[i]]
  ans-=int(l*(l-1)/2)
  ans+=int((l-1)*(l-2)/2)
  print(ans)

Submission status: Wrong Answer

Solution code:
mod = 7+10**9
def ncr(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod

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 += ncr(k, 2, mod)

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

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

Submission status: Wrong Answer

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

sum =0

for i in range(N):
  for j in range(N):
    if AList[i] == AList[j]:
      sum += 1
  print(sum-1)
  sum = 0

Submission status: Wrong Answer

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.misc import comb

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: Wrong Answer

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

for i in A:
    temp = c.copy()
    temp[i] = temp[i]-1
    counter = 0
    for j in c.keys():
        n = temp[j]
        if n >= 2:
            counter += n*(n-1)/2
    print(counter)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

for i in A:
    temp = c.copy()
    temp[i] = temp[i]-1
    counter = 0
    for j in c.keys():
        n = temp[j]
        if n >= 2:
            counter += n*(n-1)/2
    print(counter)

Submission status: Wrong Answer

Solution code:
n=int(input())
array=list(map(int,input().split()))
tot=0
x=0
count=[0]*1000000
for c in range(n):
  count[array[c]]+=1
for c in range(n):
  if x<array[c]:
    x=array[c]
    t=count[array[c]]
    tot+=int(t*(t-1)/2)
for i in range(n):
  ans=tot
  l=count[array[i]]
  ans-=int(l*(l-1)/2)
  ans+=int((l-1)*(l-2)/2)
  print(ans)

Submission status: Wrong Answer

Solution code:
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

for i in A:
    t = 0
    for k in a.keys():
        c = a[k]
        if k == i:
            c -= 1
        t += (c * (c-1)) // 2
    print(t)

Submission status: Wrong Answer

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

ans = [-1] * N

for A_ in range(len(A)):
    K = A[A_]
    for B_ in range(len(A)):
        if K == A[B_]:
            ans[A_] += 1
    print(ans[A_])

Submission status: Wrong Answer

Solution code:
"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


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


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    return factorial(x)


def choose_combination(n, r):
    if r > n:
        return 0
    return int((fac(n) / fac((n - r))) * (1 / fac(r)))


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    total_ways = 0
    for x, count in counts.items():
        total_ways += choose_combination(counts[x], 2)
    for k in array:
        ways = choose_combination(counts[k] - 1, 2)
        print(total_ways - ways - 1)


N = read_int()
array = read_array()
solve(N, array)

Submission status: Wrong Answer

Solution code:
import collections

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

C = collections.Counter(A).most_common()
w1 = C[0][0]
w2 = C[-1][0]
n1 = C[0][1]
n2 = C[-1][1]

if n1 == n2 and w1 != w2:
    for _ in range(N):
        print(n1*(n1-1)//2)
else:
    for a in A:
        if a != w1:
            print(n1*(n1-1)//2)
        else:
            print((n1-1)*(n1-2)//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

cnt = [0] * n
sum_count = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        if a[i] == a[j]:
            cnt[i] += 1
            cnt[j] += 1
            sum_count = 1


for i in range(n):
    print(sum_count-cnt[i])

Submission status: Wrong Answer

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

dic={}
for i in A:
    if i in dic.keys():
        dic[i]+=1
    else:
        dic.setdefault(i,1)

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

for k in A:
    print(hoge-(dic[k]-1))

Submission status: Wrong Answer

Solution code:
info = input("").split(" ")
N = int(info[0])
A = list(map(lambda x : int(x),info[1:]))
for i in range(N):
    count = 0
    n_list = []
    B = A[0:i] + A[i + 1:]
    for j in B :
        c = B.count(j)
        if c != 1 and not j in n_list:
            n_list.append(j)
            count += c*(c-1)/2
    print(int(count))

Submission status: Wrong Answer

Solution code:
info = input("").split()
N = int(info[0])
A = list(map(lambda x : int(x),info[1:]))
for i in range(N):
    count = 0
    n_list = []
    B = A[0:i] + A[i + 1:]
    for j in B :
        c = B.count(j)
        if c != 1 and not j in n_list:
            n_list.append(j)
            count += c*(c-1)/2
    print(int(count))

Submission status: Wrong Answer

Solution code:
info = input(" ").split()
N = int(info[0])
A = list(map(lambda x : int(x),info[1:]))
for i in range(N):
    count = 0
    n_list = []
    B = A[0:i] + A[i + 1:]
    for j in B :
        c = B.count(j)
        if c != 1 and not j in n_list:
            n_list.append(j)
            count += c*(c-1)/2
    print(int(count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]

for i, a in enumerate(A):
	num = A.count(a)
	B[i] = num * (num-1) // 2

total_pair = sum(B)
for i in range(N):
	print(total_pair - B[i])

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import Counter
N=int(input())
a=sys.stdin.readline().split()
A=[int(b) for b in a]
numbers=[0]*N
count=Counter(A)
kotae=0
for a in range(N):
    b=count[a]
    kotae+=b*(b-1)//2
for a in A:
    print(kotae+1-count[a])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0

for i in counter.values():
	ans = i * (i - 1) // 2

for j in A:
	cnt = counter[j]
	if cnt <= 1:
		print(ans)
	else:
		print(ans - cnt + 1)

Submission status: Wrong Answer

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

count = [0] * (n + 1)
total = 0

for v in a:
    count[v] += 1

for i in range(n):
    total += int(count[i] * (count[i] - 1) / 2)

for v in a:
    sub = int(count[v] * (count[v] - 1) / 2)
    add = int((count[v] - 1) * (count[v] - 2) / 2)
    print(total - sub + add)

Submission status: Wrong Answer

Solution code:
def com(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] = com(num,2)-num+1 if num >= 2 else 0

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

Submission status: Wrong Answer

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

num = [0] * (n + 1)
for i in ball:
    num[i] += 1

data = [0] * (n + 1)
sentaku = [0] * (n + 1)

for i in range(n):
    if num[i] <= 1:
        continue
    else:
        data[i] = num[i] * (num[i] - 1) // 2
        sentaku[i] = (num[i] - 1) * (num[i] - 2) // 2
x = sum(data)

for i in ball:
    print(x - data[i] + sentaku[i])

Submission status: Wrong Answer

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

for i in range(n):
    pop = list_nums.pop(i)
    new_list = sorted(list_nums)
    num_old = None
    count =1
    sum = 0

    for _ in range(n-1):
        num = new_list.pop(0)
        if num == num_old:
            count += 1

        else:
            num_old = num
            sum += int( count * (count-1) / 2)
            count = 1


    sum += int( count * (count-1) / 2)

    print(sum)
    list_nums.insert(i, pop)
print("Q.E.D.")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = input().split()

# total count
dict = set(A)
total_count = 0
for val in dict:
  tmp = A.count(val)
  tmp = int(tmp*(tmp-1)/2)
  total_count += tmp

# substracted count
for k in range(N):
  tmp = A.count(A[k])
  sub_count = int(tmp*(tmp-1)/2)
  print('{}'.format(total_count - sub_count))

Submission status: Wrong Answer

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

num = [0] * (n + 1)
for i in range(n):
    num[ball[i]] += 1

data = [0] * (n + 1)
sentaku = [0] * (n + 1)

for i in range(n):
    if num[i] <= 1:
        continue
    else:
        data[i] = num[i] * (num[i] - 1) // 2
        sentaku[i] = (num[i] - 1) * (num[i] - 2) // 2
x = sum(data)

for i in range(n):
    print(x - data[ball[i]] + sentaku[ball[i]])

Submission status: Wrong Answer

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

num = [0] * (n + 1)
for i in range(n):
    num[ball[i]] += 1

data = [0] * (n + 1)
sentaku = [0] * (n + 1)

for i in range(n):
    data[i] = num[i] * (num[i] - 1) // 2
    sentaku[i] =(num[i] - 1) * (num[i] - 2) // 2
x = sum(data)
for i in range(n):
    print(x - data[ball[i]] + sentaku[ball[i]])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
a = 0
b = []

for i in range(N):
    c=0
    for j in range(N):
        if A[i] == A[j]:
            c+=1
    c-=1
    b.append(c)
    a+=c
a/2
for i in range(N):
    print(a-b[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
print(A)
a = 0
for i in range(N):
    tmp = A[:i]
    tmp.extend(A[i+1:])
    for j in range(N-2):
        for k in range(N-1-j):
            if tmp[j] == tmp[k]:
                a += 1
print(a)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
import math
from bisect import bisect_left

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

N = int(input())
A = list(map(int,input().split()))
P = list(set(A))
P.sort()
li = Counter(A).most_common()
S = sum(comb(li[i][1],2) for i in range(len(li)) if li[i][1]>=2)
for i in A:
    ans = S
    IDX = search_index(P,i)
    if li[IDX][1]>2:
        ans -= comb(li[IDX][1],2)-comb(li[IDX][1]-1,2)
    elif li[IDX][1]==2:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import collections
import copy

# 標準入力 <int>
N = int(input())

# 標準入力 <str> list[]
A = list(map(str, input().split()))

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np

N = int(input()) #1行目のNを取得する
li = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる

#print(N)
#print(li)


for k in range(N):
    ans = 0
    LI = li.copy()
    LI_k = LI.pop(k)
    #print(LI)
    counter = Counter(LI)
    #print(counter)
    #print(len(counter))
    #print(counter.values())
    counter_value_array = np.array(list(counter.values()))
    for i in range(len(counter_value_array)):
        ans = ans + counter_value_array[i] * (counter_value_array[i]-1)/2
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, *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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = []
for i in range(N):
  a = A[i]
  A[i] = 0
  B = Counter(A)
  for v in B.values():
    if v != 1:
      C.append(math.factorial(v)//2)
  print(sum(C))
  C.clear()
  A[i] = a

Submission status: Wrong Answer

Solution code:
N_ = int(input())

A_ = input().split()
#print(A_)

U_ = set(A_)
#print(U_)


def xC(num):
    return (num * (num - 1)) //2
num = 0
dict = {}
judge = {}

for u in U_:
    #dict[u] = xC(A_.count(u))
    num += xC(A_.count(u))

for u in U_:
    judge[u] = False
    dict[u] = num



for a in A_:
    if dict[a]:
        if judge[a]:
            print(dict[a])
        else:
            judge[a] = True
            dict[a] = dict[a] - xC(A_.count(a)) + xC(A_.count(a) - 1)
            print(dict[a])

Submission status: Wrong Answer

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

flag = 1
for i in range(N-1):
  if B[i] != B[i+1]:
    flag = 0
    break

idx = 1
idx_count = 0
idx_set = []
if flag == 1:	# 要素が全て同じ場合
  tmp = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
  for i in range(N):
    print(tmp)
else:
  for i in range(N):
    if idx != B[i]:
      tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
      tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
      idx_set.append([idx, tmp1, tmp2])
      idx_count = 0
      idx = B[i]
    idx_count+=1
  if idx_count != 0:
    tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
    idx_set.append([idx, tmp1, tmp2])
  #print(idx_set)

  for i in range(N):
    tmp = 0
    for j in range(len(idx_set)):
      if A[i] == idx_set[j][0]:
        tmp += idx_set[j][2]
      else:
        tmp += idx_set[j][1]
    print(tmp)

Submission status: Wrong Answer

Solution code:
import itertools

# 入力
N = int(input())
An = [int(x) for x in input().split()]

# 組み合わせ
L = []
for i in range(0,N+1):
    l = [0] * i
    L.append(len(list(itertools.combinations(l,2))))
    
# 各数字の個数を求める
Cn = [An.count(i) for i in range(1,N+1)]

# 全部の組み合わせ
Dn = [L[Cn[i-1]] for i in range(1,N+1)]
s = sum(Dn)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
ans = []
for i in A:
    num[i-1]+=1
sums = 0
for i in A:
    num[i-1]-=1
    for j in range(N):
        if num[j] > 1:
            sums += 1/2*num[j]*(num[j]-1)
    ans.append(int(sums))
    sums = 0
    num[i-1]+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
ans = []
for i in A:
    num[i-1]+=1
sums = 0
print(num)
for i in A:
    num[i-1]-=1
    for j in range(N):
        if num[j] > 1:
            sums += 1/2*num[j]*(num[j]-1)
    ans.append(int(sums))
    sums = 0
    num[i-1]+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
import math
result=0
for i in range(N):
  b=a.copy()
  b.pop(i)
  b=sorted(b)
  res=0
  n=b[0]
  c=1
  for j in range(1,N-1):
    if n==b[j]:
      c+=1
    else:
      res+=math.factorial(c)//2
      c=1
      n=b[j]
  res+=math.factorial(c)//2
  print(res)

Submission status: Wrong Answer

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

for aa in A:
    count = 0
    for ab in A:
        if(aa == ab):
            count += 1
    print(count - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())))
for i in range(N):
    print(len(a[a == a[i]])-1)

Submission status: Wrong Answer

Solution code:
import math
num=int(input())
target=list(map(int, input().split()))

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

for i in range(num):
    A=target.copy()
    A.pop(i)
    B=[x for x in set(A) if A.count(x) > 1]
    out=0
    if len(B)>1:
        for j in B:
            base = comb(A.count(j),2)
            out=out+base
    print(out)

Submission status: Wrong Answer

Solution code:
import sys
import os
import collections


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    L = int(sys.stdin.buffer.readline().decode().rstrip())
    print(L ** 3 / 27)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1, end=" ")

Submission status: Wrong Answer

Solution code:
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in range(n):
    print(result-conbi[balls[k]-1]+1)

Submission status: Wrong Answer

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

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

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

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

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

    return result

list_B = list(set(list_A))
an = 0
for i in range(len(list_B)):
    c = list_A.count(list_B[i])
    an += cmb(c, 2)


for i in range(n):
    c = list_A.count(list_A[i])
    if c != 2:
        ans = an - cmb(c, 2) + cmb(c-1, 2)
    else:
        ans = an -1
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

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

b = collections.Counter(a)
cl = np.array([b[x] for x in sorted(list(b.keys()))])
c = {}
m = len(cl)
i = 0
for k, v in b.items():
    e = np.zeros(m)
    e[i] = 1
    c[k] = int(sum((cl - e)*(cl - e - 1))/2)
    i += 1
for i in a:
    print(c[i])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from scipy.misc import comb
N = int(input())
A = [int(x) for x in input().split()]
C = Counter(A)
def banned_count(seq):
    for i in range(N):
        count = 0
        C[A[i]] -= 1
        for j in C.values():
            if j >= 2:
                count += comb(j, 2)
        print(int(count))
        C[A[i]] += 1
banned_count(A)

Submission status: Wrong Answer

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

import collections
count_dic = collections.Counter(a_list)

count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2

fund_values = sum(list(count_dic_new.values()))

for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (n-1)

    print(a_value)

Submission status: Wrong Answer

Solution code:
N = int(input())
K = list(map(int, input().split()))
counter = dict()
for i in range(N):
  if K[i] not in counter:
  	counter[K[i]] = 1
  else:
   	counter[K[i]] += 1

results = 0
remove_counter = dict()
for key, value in counter.items():
  remove_counter[key] = (value * (value - 1) / 2) - ((value - 1) * (value - 2) / 2)
  results += value * (value - 1) / 2
for i in range(N):
  print(results - remove_counter[K[i]])

Submission status: Wrong Answer

Solution code:
# ncr再びって感じ(Aもncrだった)
# 登場回数が2以上のものが対象になる 多そうなのでncr自体をメモ化しておくか
# TLEくらった もうすこしメモ化してみる（どうせ同じ数があるのでncrの計算を減らすべく、答え自体をメモ化した(memo2)）
# それでもTLEくらった
# あ クエリに対してあらかじめ答えを用意しておけばいいか

n = int(input())
arr = list(map(int, input().split()))
memo = {}

dic = {}
for a in arr:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1


def ncr(n, r):
    # ささやかなメモ化
    if (n, r) in memo:
        return memo[(n, r)]
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    memo[(n, r)] = res
    return res


ans = {}
for k, v in dic.items():
    if k in ans:
        continue
    if v < 2:
        ans[k] = 0
        continue
    tmp = 0
    dic[k] -= 1
    for kk, vv in dic.items():
        if vv >= 2:
            tmp += ncr(vv, 2)
    dic[k] += 1
    ans[k] = tmp
for a in arr:
    print(ans[a])