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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# 要素を計算
A_unique = set(A)
cnt = dict()

total = 0

# 組み合わせ数
for a in A_unique :
  total += int(A.count(a) * (A.count(a) -1) / 2)
  cnt[a] = A.count(a)

for a2 in A :
  print(total - cnt[a2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 書かれた番号の頻度
Freq = dict(sorted(Counter(A).items(), key=lambda x: x[1], reverse=True))

# 答えの最大値
ans_max = 0
for kv in Freq.items():
  if kv[1] < 2: break
  ans_max += kv[1] * (kv[1] - 1) // 2

for a in A:
  # 1個しか存在しない番号は、取り除いても答えに影響しない
  if Freq.get(a) == 1:
    print(ans_max)
    continue

  # x個の場合と、x-1個の場合と、の差分
  x = Freq.get(a)
  diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)

  # そのぶんだけ、答えの最大値から減らす
  ans = ans_max - diff
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

  # 書かれた番号の頻度
  Freq = dict(sorted(Counter(A).items(), key=lambda x: x[1], reverse=True))

  # 答えの最大値 (1個しか存在しない番号は、取り除いても答えに影響しない)
  ans_max = 0
  for kv in Freq.items():
    if kv[1] < 2: break
    ans_max += kv[1] * (kv[1] - 1) // 2

  # 答えのメモ (複数回計算しないように)
  memo = dict()

  for a in A:
    # 取り除いても答えに影響しない
    if Freq.get(a) == 1:
      print(ans_max)
      continue

    # 過去に計算済みの番号
    if memo.get(a) != None:
      print(memo[a])
      continue

    ans = 0
    for kv in Freq.items():
      # 大きい順に見ているので1個になったら終了
      if kv[1] < 2: break
      # key -> value : 番号 -> ボール個数
      cnt = kv[1]
      # 自身は取り除く
      if kv[0] == a: cnt -= 1
      # 2個未満はスキップ
      if cnt < 2: continue
      # 2つ選ぶ方法は n*(n-1)//2
      ans += cnt * (cnt-1) // 2
    print(ans)
    memo[a] = ans

solve()

Submission status: Wrong Answer

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


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

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

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

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

    return result


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

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A_new=sorted(A)
n=0
sum_number=0
index=[]
number=[]
for i in range(N-1):
    if A_new[i]==A_new[i+1]:
        n=n+1
    else:
        sum_number=n*(n+1)/2+sum_number
        index.append(i)
        number.append(n+1)
        n=0
if n!=0:
    sum_number=n*(n+1)/2+sum_number
if all(number):
    number.append(n+1)
    index.append(N-1)
I=len(index)
print(index)
print(number)
print(A)
print(A_new)
for i in range(N):
    for s,S in enumerate(index):
        if A[i]==A_new[S]:
            L=s
            break
    print(int(sum_number+1-number[L]))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    print(factorial(n) / factorial(r) / factorial(n-r) )
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))

Submission status: Wrong Answer

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

d={}
sum=0
for i in range(n):
  if l[i] not in d:
    d[l[i]]=1
  else:
    d[l[i]]+=1
   
l1=[]
for i in d:
  if d[i]>1:
    l.append((d[i]*(d[i]-1))//2)
    sum+=((d[i]*(d[i]-1))//2)

#print(d,sum)
for i in range(n):
  if d[l[i]]==2:
    print(sum-1)
  elif d[l[i]]>2:
    we=((d[l[i]]*(d[l[i]]-1))//2-((d[l[i]]-1)*(d[l[i]]-2))//2)
    print(sum-we)
  else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
ans=0
for i in dic.values():
  if i>1:
    ans+=i*(i-1)/2
for i in range(n):
  bk=dic[a[i]]
  print(int(ans-bk+1) if bk>1 else ans)

Submission status: Wrong Answer

Solution code:

def Get_nC2(n):
    return int(n*(n-1) / 2);


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

cnt_dict = {}
for a_i in A_i:
    cnt = 0
    if a_i in cnt_dict:
        print(cnt_dict[a_i])
        continue
    else:
        for j in range(min(A_i), max(A_i)+1):
            j_cnt = A_i.count(j)
            if a_i == j:
                j_cnt -= 1

        cnt += Get_nC2(j_cnt)

        cnt_dict[a_i] = cnt

        print(cnt)

Submission status: Wrong Answer

Solution code:

def Get_nC2(n):
    return int(n*(n-1) / 2);


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

for a_i in A_i:
    cnt = 0
    for j in range(min(A_i), max(A_i)):
        j_cnt = A_i.count(j)
        if a_i == j:
            j_cnt -= 1

        cnt += Get_nC2(j_cnt)

    print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
L = {key:(B[key] * (B[key] - 1) // 2) for key in B}
total = sum(L.values())
#print(f"A = {A}\nB = {B}\nL = {L}\ntotal = {total}")
[print(0 if L[i] == 0 else total - L[i] + ((B[i] - 1) * (B[i] - 2)) // 2) for i in A]

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=[0]*n
#a[i]は1以上n以下で、cの要素番号は0~n-1(acは1ずれている。)
all=0
for i in range(n):
  c[a[i]-1]+=1
for i in range(n):
  if c[i]>=2:
    d=c[i]*(c[i]-1)/2
    all+=d
for i in range(n):
  print(all-(c[a[i]-1]-1))

Submission status: Wrong Answer

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

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

#print(combinations_count(N, 2))
V=[]
for v in itertools.permutations(A, 2):
    #print(v)
    if v[0]==v[1]:
        V.append(v)
#print(V,len(V))

for i in range (0,N):
    stock=A[0]
    #print(stock)
    del A[0]
    
    count=0
    for j in range (0,len(A)):
        
        if A[j]==stock:
            count+=1
            
    print(int(len(V)/2)-count)
        
    A.append(stock)

Submission status: Wrong Answer

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

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

for i in ball:
    num[i] += 1

for i in range(n):
    data[i] = num[i] * (num[i] - 1) // 2

x = sum(data)

for i in ball:
    print(x - num[i] + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = list(map(int, input().split()))
n_list = [0]*n

for i in range(n):
  n_list[an[i]-1] += 1

for j in range(n):
  n_list1 = n_list[:]
  n_list1[an[j]-1] -= 1
  answer = 0
  for k in n_list1:
    answer += k*(k-1)/2
  print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)  # aの要素の数と値の辞書を出してくれる
print(c)
#print(c.keys())
#print(c.values())
for m in c.values():  # Counterで出した辞書の値（values)のリストの中身でfor
    ans += int((m*(m-1))/2)  # mC2をしている


for k in range(n):
    print(c[a[k]])
    print(ans - (c[a[k]] - 1))
    """
    c[a[k]]-1というのはｋ番目のボールを隠す前と隠した後についての差。
    隠す前、aのリストにA_kがｍ個あったとする。隠した後、aのリストにA_kはｍ－１個
    なので、mC2 - (m-1)C2 = m-1 である。ここでｍとはc[a[k]]なので、上が成り立つ。
    """

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
uA = list(set(A))
c = {u:A.count(u) for u in uA}

la = {}
lb = {}

for a in uA:
  la[a] = int(c[a]*(c[a]-1)/2)
  lb[a] = int((c[a]-1)*(c[a]-2)/2)
  
for a in A:
  ks = list(la.values())
  b = lb[a] + sum([k for k in ks if k !=a])
  print(b)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
# from scipy.special import comb

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

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

banned(al)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

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

banned(al)

Submission status: Wrong Answer

Solution code:
from collections import deque

def sta(n):
  sta = 1
  if n >= 1:
    for i in range(1, n + 1):
      sta *= i
  return sta

N = int(input())
num = list(map(int, input().split()))
count = 0
sum = 0
list =[]

for k in range(N):
  outnum = 0
  out = num[k]
  for i in range(N):
    if num[i] == out:
      outnum += 1
  minus = outnum - 1
  list.append(minus)

num.sort()

d = deque(num)

for i in range(N - 1):
  if d[0] == d[1]:
    count += 1
  else:
    sum += sta(count + 1)/ (sta(2) * sta(count - 1))
    count = 0
  d.popleft()
if not count == 0:
  sum += sta(count + 1)/ (sta(2) * sta(count - 1))
  
for i in range(N):
  print(sum - list[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]


ans = 0
for i in range(n):
    j = l.count(i)
    ans += int(j * (j - 1) / 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

m = []
for i in range(N):
  b = [a for a, j in enumerate(A) if j != i]
  c = Counter(b).values()
  for j in c:
    if j != 1:
      print(int(c*(c-1)/2))

Submission status: Wrong Answer

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

a_ol = {}
def_count = 0
for i in a_uni:
    a_co = a.count(i)
    a_ol[i] = a_co
    def_count += a_co * (a_co - 1)

def_count *= 0.5

for k in range(n):
    print(def_count - a_ol[a[k]] + 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=[int(item)for item in input().split()]
c=Counter(A)
full = {i: c[i] * (c[i] - 1) / 2 for i in c.keys()}
#full = [full[item-1] for item in A]
print(full)
#ichiheri = [c[i]-1 * (c[i]-1) / 2 for i in range(1,1+len(c))]
ichiheri = {i:(c[i]-2) * (c[i]-1) / 2 for i in c.keys()}
print(ichiheri)

for a in A:
    sumA = sum(full.values())
    sumA-=full[a]
    sumA += ichiheri[a]
    print(int(sumA))

Submission status: Wrong Answer

Solution code:
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
c=list(range(1,n+1))
a.insert(0,0)
num=list(map(lambda t:reduce(lambda a,b:a+1 if b==t else a,a),c))
"""
test=list(map(lambda t:map(lambda x,y:x if (y!=t or x==0) else x-1,num,c),c))
for i in range(5):
    print(list(test[i]))
"""
ans=list(map(lambda t:reduce(lambda x,y:x+y*(y-1)/2,map(lambda x,y:x if (y!=t or x==0) else x-1,num,c),0),c))

for i in range(n):
    print(int(ans[a[i]]))

Submission status: Wrong Answer

Solution code:
N,A = [input() for i in range(2)]
A=A.split()
N=int(N)
A=[int(i) for i in A]

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

ans=[]
b=[]
for k in range(N):
    b_k=0
    for i in range(N-1):
        if A[k]==A[i]:
            b_k+=1
    ans.append(a-b_k)

for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
def main():
    ball_count = int(input())
    balls = list(map(int, input().split()))
    variants = {}

    for k in range(ball_count):
        count = 0
        nums = {}
        total = 0

        for i in set(balls):
            nums.update({i: balls.count(i)})

        nums[balls[k]] -= 1

        for v in nums.values():
            if v not in variants:
                if v >= 2:
                    count += 1
                    for i in range(3, v + 1):
                        count = count - 1 + i
                variants.update({v: count})
                total += count
                count = 0
                print(variants)
            else:
                total += variants[v]

        print(total)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = 8
a = list(map(int, '1 2 1 4 2 1 4 1'.split()))
count_dict = {}
total_sum = 0
for i in a:
    if i not in count_dict:
        count_dict[i] = a.count(i)
        total_sum += (a.count(i))*(a.count(i)-1)//2
for i in a:
    print(total_sum - (a.count(i)*(a.count(i)-1)//2) + (a.count(i)-1)*(a.count(i)-2)//2)

Submission status: Wrong Answer

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

c = Counter(A)
# print(c)
cou = 0
for x in c:
    if c[x]>1:
        y = c[x]
        cou+=y*(y-1)//2
    else:
        break


for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//2
    print(ans)

Submission status: Wrong Answer

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

c = Counter(A)
print(c)
cou = 0
for x in c:
    if c[x]>1:
        y = c[x]
        cou+=y*(y-1)//2
    else:
        break


for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//2
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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


c = collections.Counter(A)

for i in range(N):
  p += (c[i])*(c[i]-1)//2

for i in range(N):
  print(p-c[A[i]]+1)

Submission status: Wrong Answer

Solution code:
import collections

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


c = collections.Counter(A)

for i in range(N):
  if c[i] > 1:
    p += (c[i])*(c[i]-1)//2

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

Submission status: Wrong Answer

Solution code:
import collections

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


c = collections.Counter(A)

for i in range(N):
  if c[i] > 1:
    p += (c[i])*(c[i]-1)//2

for i in range(N):
  if c[A[i]] > 1:
    print(p-(c[A[i]]-1))
  else:
    print(0)

Submission status: Wrong Answer

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

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

ans=0
for i in range(n):
    ans+=l[i]*(l[i]-1)//2

for i in a:
    print(ans-l[i]*(l[i]-1)//2+(l[i]-1)*(l[i]-2)//2)

Submission status: Wrong Answer

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

box = [lis[0]]
num = []

def Cn2(i):
    x = i*(i-1)/2
    return int(x)

#だぶっている数を消したbox作る
for i in range(len(lis)):
    for j in range(len(box)):
        if lis[i] == box[j]:
            break
        elif j == len(box)-1:
            if not lis[i] == box[j]:
                box.append(lis[i])
        else:continue

#boxに入っている数がlisとのダブリ数を数える
for i in range(len(box)):
    a = 0
    for j in range(len(lis)):
        if box[i] == lis[j]:
            a = a + 1
        else:continue
    num.append(a)


for k in range(len(lis)):
    al = 0
    for i in range(len(num)):
        if num[i] == 0 or num[i] == 1:
            continue
        al = al + Cn2(num[i])
    if lis[k] == 0 or lis[k] == 1:
        print(al)
        continue
    for j in range(len(box)):
        if lis[k] == box[j]:
            al = al - (num[j]-1)
    print(al)

Submission status: Wrong Answer

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

from scipy.misc import comb
def combi(n):
    if n<=1:
        return 0
    if n==2:
        return 1
    return comb(n,2)

c=[a.count(i) for i in range(1,n+1)]
d=[combi(m) for m in c]
s=sum(d)

for i in range(n):
    print(s-d[a[i]-1]+combi(c[a[i]-1]-1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

for k in range(n): 

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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



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

Submission status: Wrong Answer

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

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

count=Counter(A)
ans=0
for i in range(len(count)):
	ans+=ch_2(count[A[i]])
print(ans)
for j in range(N):
	ttl=ans
	ttl-=ch_2(count[A[j]])
	ttl+=ch_2(count[A[j]]-1)
	print(int(ttl))

Submission status: Wrong Answer

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

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

count=Counter(A)
ans=0
for i in range(len(count)):
	ans+=ch_2(count[i])
for j in range(N):
	print(ans-ch_2(count[A[j]]-1))

Submission status: Wrong Answer

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

ANSWER = []
for i in range(N):
    A_ = A.copy()
    del A_[i]
    unique_i = list(set(A_))

    answer_i = 0
    for j in unique_i:
        answer_i += (A_.count(j) * (A_.count(j)-1)/2)
    
    ANSWER.append(int(answer_i))
    
print(ANSWER)

Submission status: Wrong Answer

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

ANSWER = []
for i in range(N):
    A_ = A.copy()
    del A_[i]
    unique_i = list(set(A_))

    answer_i = 0
    for j in unique_i:
        answer_i += (A_.count(j) * (A_.count(j)-1)/2)
    
    ANSWER.append(int(answer_i))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int,input().split()))
S = Counter(A)
B = []
C = []
#print(S)
for i in S.keys():
    try:
        B.append(combinations_count(S[i],2))
    except:
        B.append(0)
#print(B)
for j in S.keys():
    try:
        C.append(combinations_count(S[j]-1,2))
    except:
        C.append(0)
D = sum(B)
#print(A)
for k in range(N):
    try:
        print(D - combinations_count(S[A[k]],2) + combinations_count(S[A[k]]-1,2))
    except:
        try:
            print(D - combinations_count(S[A[k]],2))
        except:
            print(0)
    #print(S[A[k]])
    #print(D - combinations_count(S[A[k]],2) + combinations_count(S[A[k]]-1,2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
i = int(0)
j = int(0)
B = [-1]*N
C = []
sum = int(0)

D = set(A)


if len(D) == 1:
    for i in range(N):
        print("0")
elif len(D) == N:
    i = 0
    sum = (N-1)*(N-2)/2
    for i in range(N):
        print(sum)
else:
    for i in range(N):
        if B[i] == -1:
            count = int(0)
            j = i
            for j in range(N):
                if A[i]==A[j]:
                    count = count + 1
                    B[j] = i
                j = j + 1
            pair = int(count*(count-1)/2)
            C.append([A[i],pair - int((count-1)*(count-2)/2)])
            sum = sum + pair
        i = i + 1

    i = 0
    L = len(C)

    for i in range(N):
        for j in range(L) :
            if A[i] == C[j][0]:
                print(sum-C[j][1])
                break
            else:
                j = j + 1
        i = i + 1

Submission status: Wrong Answer

Solution code:
import math

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

N = int(input())

A = list(map(int, input().strip().split()))
sort_A = list(set(A))
print(sort_A)
num = [0 for i in range(len(sort_A))] #sort_A[i]がAに入っている個数

for i in range(len(A)):
    num[sort_A.index(A[i])] += 1

for k in range(len(A)):
    count = 0
    for i in range(len(sort_A)):
        if sort_A[i] == A[k] and num[i] >= 3:
            count += Comninations_count(num[i] - 1, 2)
        elif sort_A[i] != A[k] and num[i] >= 2:
            count += Comninations_count(num[i], 2)
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
i = int(0)
j = int(0)
B = [-1]*N
C = []
sum = int(0)

D = set(A)

if len(D) == 1:
    for i in range(N):
        print("0")
    exit

if len(D) == N:
    i = 0
    sum = (N-1)*(N-2)/2
    for i in range(N):
        print(sum)
    exit

i = 0

for i in range(N):
    if B[i] == -1:
        count = int(0)
        j = i
        for j in range(N):
            if A[i]==A[j]:
                count = count + 1
                B[j] = i
            j = j + 1
        pair = int(count*(count-1)/2)
        C.append([A[i],pair - int((count-1)*(count-2)/2)])
        sum = sum + pair
    i = i + 1

i = 0
L = len(C)

for i in range(N):
    for j in range(L) :
        if A[i] == C[j][0]:
            print(sum-C[j][1])
            break
        else:
            j = j + 1
    i = i + 1

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split(" ")))
count = [0]*(n+1)
for i in range(n):
    count[data[i]] = count[data[i]]+1

val = [0]*(n+1)
sumval = 0
for i in range(n):
    if(count[i] >= 2):
        val[i] = count[i]-1
        sumval = sumval + int(count[i]*(count[i]-1)/2)

for i in range(n):
    print(sumval - val[data[i]])

Submission status: Wrong Answer

Solution code:
import collections 
from collections import Counter
*l, = map(int, input().split())
c = Counter(l)

A = [int(i*(i-1)/2) for i in c.values()]
A_sum = sum(A)

for j in l:
	print(A_sum - c[j] + 1)

Submission status: Wrong Answer

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
for x in C:
  if x==0:
    break
  count+=x*(x-1)/2
for x in A:
  ans=count-C[V.index(x)]+1
  print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections

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

num_count = collections.Counter(a)
total = sum([num*(num-1)//2 for num in num_count.values()])

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

Submission status: Wrong Answer

Solution code:
#TLE
n = int(input())
a = input().split()
dic = {}
ans = 0
for i in range(n):
    if a[i] in dic:
        ans += dic[a[i]]
    else:
        num = a.count(a[i]) - 1
        ans += num
        dic[a[i]] = num
ans /= 2
for i in range(n):
    print(int(ans - dic[a[i]]))
print(dic)

Submission status: Wrong Answer

Solution code:
#TLE
n = int(input())
a = input().split()
dicti = {}
ans = 0
for i in range(n):
    if i in dicti:
        ans += dicti[i]
    else:
        num = a.count(a[i])
        ans += num
        dicti[i] = num
ans /= 2
for i in range(n):
    answer = ans - dicti[i] - 1
    print(int(answer))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 先にk番目を抜かない場合を求めておく
ans = 0
for n in c.values():
    ans += n*(n-1)//2

# k番目を抜く場合の差分を加える
for k in range(N):
    m = c[A[k]]
    ans -= m-1  # -m*(m-1)//2 + (m-1)*(m-2)//2
    print(ans)

Submission status: Wrong Answer

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

all_c = 0		# 総組み合わせ数
idx = B[0]
idx_count = 0
idx_set = []
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つ除いたときの組合せ数
    all_c += tmp1
    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つ除いたときの組合せ数
  all_c += tmp1
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)

Submission status: Wrong Answer

Solution code:
N = int(input())
ball_list = []
ball_list = list(input().split())
#種類を把握・カウント
#削除後の種類ごとに計算

for i in range(N):
    tmp_list = []
    tmp_list = ball_list.copy()
    tmp_list.pop(i)
    tmp_list.sort()

    num = 0
    amount = 0
    for v in range(len(tmp_list)):
        if v == 0:
            num = tmp_list[v]
            cnt = tmp_list.count(tmp_list[v])
            amount += cnt * (cnt-1) // 2
        elif num == tmp_list[v]:
            continue
        else:
            cnt = tmp_list.count(tmp_list[v])
            amount += cnt * (cnt-1) // 2

    print(amount)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
ball_number_list = list(map(int, input().split()))
print(ball_number_list)
def choose2(p):
    return (p*(p-1))/2
def findfind(list1, k):
    c = 0
    list2 = copy.copy(list1)
    del list2[k]
    kinds = list(set(list2))
    for i in kinds:
        c += choose2(list2.count(i))
    return int(c)

for k in range(n):
    print(findfind(ball_number_list,k))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
ans = np.zeros(N)
total = 0
for i in range(N):
  ans[A[i] - 1] += 1
for i in range(N):
  total += ans[i] * (ans[i] - 1) // 2
for i in range(N):
  print(total - max(ans[A[i]-1]-1,0))

Submission status: Wrong Answer

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 = []
Total = 0

Number = [A.count(i+1) for i in range(N)]
Total = sum([Number[i]*(Number[i]-1)/2 for i in range(N)])

#for Ak in A:
#    print(int(Total - Number[Ak-1]+1))

print('\n'.join([str(Total-Number[Ak-1]+1) for Ak in A]))

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):
  print(N - cnt[A[i]])

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-2)*(n-1)/2 for n in cn.values()])
for k in range(n):
  print(sumC - cn[A[k]] +1)

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-2)*(n-1)/2 for n in cn.values()])
for k in range(n):
  print(sumC - cn[k] +1)