TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
"""
"""
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):
    if cache.get(x) is not None:
        return cache[x]
    ans = factorial(x)
    cache[x] = ans
    return ans


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
    ways_cache = {}
    for k in array:
        if ways_cache.get(k) is not None:
            return ways_cache[k]
        ways = 0
        for x, count in counts.items():
            adjusted_count = counts[x]
            if x == k:
                adjusted_count -= 1
            ways += choose_combination(adjusted_count, 2)
        ways_cache[k] = ways
        print(ways)


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


"""
"""
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)))
    # return (fac(n) // fac((n - 2)) * (1 / 2))
    # return fac((n // n - 2)) * (1 / 2))
    return (n * (n-1)) // 2


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 - choose_combination(counts[k], 2))


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


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math
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)
    out=0
    for j in set(A):
        if A.count(j)>1:
            base = comb(A.count(j),2)
            out=out+base
    print(out)

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)


import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
#include<bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), count(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        count[A[i]]++;
    }
    long long answer = 0;
    for (int i = 0; i < N; i++) {
        answer += count[i] * (count[i] - 1) / 2;
    }
    for (int i = 0; i < N; i++) {
        cout << answer - count[A[i]] + 1 << endl;
    }
    return 0;
}

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    count = {}
    for aa in a:
        if aa in count:
            count[aa] += 1
        else:
            count[aa] = 1
    all_way = 0
    for c in count.values():
        all_way += c * (c - 1) // 2
    for i in range(n):
        if a[i] in count:
            print(all_way - count[a[i]] + 1)
        else:
            print(all_way)


if __name__ == '__main__':
    main()



Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
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]]))

from functools import reduce
n=int(input())
a=list(map(int,input().split()))
c=list(range(1,n+1))
num=[0]*n
for i in range(n):
    num[a[i]-1]=num[a[i]-1]+1
preans=reduce(lambda x,y:x+y*(y-1)/2,num,0)

for i in range(n):
    print(int(preans-num[a[i]-1]+1))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
A = list(map(int, input().split()))
num = [0]*n
import numpy as np
for i in A:
  num[i-1] += 1
num = np.array(num)
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = np.sum(np.array(num))
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)

n = int(input())
A = list(map(int, input().split()))
num = [0]*n
for i in A:
  num[i-1] += 1
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = 0
for i in num:
  ans_sub += comb(i)
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<int> uniqueA = A;
    sort(uniqueA.begin(), uniqueA.end());
    uniqueA.erase(unique(uniqueA.begin(), uniqueA.end()), uniqueA.end());

    int sum_comb_all = 0;
    for (int i = 0; i < uniqueA.size(); i++) {
        int num_A = count(A.begin(), A.end(), uniqueA[i]);
        int comb  = (num_A * (num_A-1)) / 2;
        sum_comb_all += comb;
    }


    for (int i = 0; i < N; i++) {

        int num_A     = count(A.begin(), A.end(), A[i]);
        int prev_comb = (num_A * (num_A-1)) / 2;
        int new_comb  = ((num_A-1) * (num_A-2)) / 2;

        int sum_comb  = sum_comb_all - prev_comb + new_comb;
        cout << sum_comb << endl;

    }

}

from collections import Counter

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

def main(N, lst_A):

    dct_cntA = Counter(lst_A)
    sum_comb = 0

    for cntA in dct_cntA.values():
        comb = (cntA * (cntA - 1)) // 2
        sum_comb += comb

    for A in lst_A:
        print(sum_comb - (dct_cntA[A] - 1))

    return 0

if __name__ == "__main__":

    main(N, lst_A)
    

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
ans=0
for i in range(n):
    l[a[i]]+=1
for j in range(n):
    if l[j]>1:
        ans+=(l[j])*(l[j]-1)//2
for k in range(n):
    s=l[a[k]]
    if s<2:
        print(ans)
    else:
        print(ans-(s+1)*s//2+s*(s-1)//2)

n=int(input())
A=list(map(int,input().split()))
a=sorted(A)
counter=1
ans=0
value=a[0]
dict={}
for i in range(1,n):
    if a[i]==value:
        counter+=1
    else:
        dict[value]=counter
        if counter<2:
            pass
        else:
            ans+=counter*(counter-1)//2
        counter=1
        value=a[i]
dict[value]=counter
if counter<2:
    pass
else:
    ans+=counter*(counter-1)//2
for j in range(n):
    count=dict[A[j]]-1
    if count==0:
        print(ans)
    elif count==1:
        print(ans-1)
    else:
        c=ans-(count+1)*count//2+count*(count-1)//2
        print(c)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
s = n*[0]
for i in a:
    s[i]+=1
for i in range(0,n):
    s[a[i]]-=1
    ans=max(s)*(max(s)-1)/2
    s[a[i]]+=1
    print(int(ans))

import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = [a for a in map(int, input().split())]



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


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)

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



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


for i in range(N):
    if A[i] in dic1.keys():
        dic1[A[i]] += 1

dic2 = {}

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

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

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] 
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2 
    print(int(ans2))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count:
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)


from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import 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 = []

#     cut_list=[]

#     for n,yn in enumerate(reversed(list(bin(l))[2:])):

#             cut_list.append(li_hw[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)
        
        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))

import collections
n = int(input())
a = map(int, input().split())
li = []
for i in a:
    li.append(i)
collections.Counter(li)
m = 0
dic = collections.Counter(li)
for i in dic.values():
    m += int(i*(i-1)*0.5)
for k in range(n):
      print(m-dic[li[k]]+1)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

if all_count == 0:
    all_count = 1

for i in range(n):
    print(all_count - c[i])


from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

for i in range(n):
    print(all_count - c[i])


from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

if all_count == 0:
    all_count = 1

for i in a_list:
    print(all_count - c[i])


from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

print(all_count)

for i in range(n):
    print(all_count - c[i])


from collections import Counter

n = int(input())

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

ans_dict = {}
ans_keys = []
value_dict = {1: 0}
value_keys = [1]
for i in range(n):
    num = a_list[i]
    if num in ans_keys:
        print(ans_dict[num])
    else:
        buff = a_list[:i]
        buff.extend(a_list[i+1:])
        c = Counter(buff)

        tmp_ans = 0
        for value in c.values():
            if value in value_keys:
                tmp_ans += value_dict[value]
            else:
                tmp = (value * (value - 1))/2
                tmp_ans += tmp
                value_dict[value] = tmp
                value_keys.append(value)
        ans_dict[num] = tmp_ans
        ans_keys.append(num)
        print(int(tmp_ans))



from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

for i in a_list:
    print(all_count - c[i] + 1)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
# coding: utf-8
N = int(input())
A = input().split()


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))

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product

#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    count = [0] * (N+1)
    for val in A:
        count[val] += 1
    base_sum = 0
    for val in count:
        if val <= 1:continue
        base_sum += val * (val-1) // 2
    for i in range(N):
        if count[A[i]] == 1:
            print(base_sum)
        else:
            print(base_sum - count[A[i]] + 1)
if __name__ == "__main__":
    run()


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N=int(input())
m=list(map(ine,input().split()))
t=[]
for i in range(N):
  t.append(0)
for i in range(N):
  t[m[i]-1]+=1
total=0
for i in range(N):
  total+=(t[i]*(t[i]-1))//2
for i in range(N):
  if t[m[i]-1]<2:
    print(total)
  else:
    print(total-(t[m[i]-1]-1))

N=int(input())
m=list(map(int,input().split()))
t=[]
for i in range(N):
  t.append(0)
for i in range(N):
  t[m[i]-1]+=1
total=0
for i in range(N):
  total+=(t[i]*(t[i]-1))//2
for i in range(N):
  if t[m[i]-1]<2:
    print(total)
  else:
    print(total-(t[m[i]-1]-1))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
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()))


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())
    return "\n".join(str(b - c[_a] + 1) for _a in a)


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


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
print(ls)
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))

N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
nsum = 0

for i in setnum:
    dicnum[i] = numlist.count(i)
    if dicnum[i] >= 2:
        nsum += dicnum[i]*(dicnum[i]-1)//2
    else:
        del dicnum[i]

for j in range(n):
    ans = nsum
    if numlist[j] in dicnum:
        ans = ans - dicnum[numlist[j]] + 1
    print(ans)

n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for j in numdic:
    nsum += numdic[j] * (numdic[j] - 1) // 2

for k in range(n):
    ans = nsum
    if numdic[numlist[k]] >= 2:
        ans -= (numdic[numlist[k]]-1)
    print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math

def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2


n=int(input())
a=list(map(int,input().split()))
d1=dict()
for i in a:
    if i not in d1:
        d1[i]=1
    else:
        d1[i] += 1
#print(d1)
d2={i:ABC159D(j) for i,j in d1.items()}
d3={i:ABC159D(j-1)-d2[i] for i,j in d1.items()}
#print(d2,d3)
p=sum(d2.values())
print(''.join([p+d3[i] for i in a]))

import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return (a*(a-1))//2

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

#    d=mycounter(d,i)
dd=Counter(a)
#print(d)
p=0
for i in dd.values():p+=ABC159D(i)
print('\n'.join(map(str,[p-dd[i]+1 for i in a])))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

# N = 5
# A = [1, 1, 2, 1, 2]

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0

# print(lst)
    
for i in range(N):
    lst[A[i]] += 1

# print(lst)

              

for i in lst:
#     print('i: {}'.format(i))
    c[i] = 0
    tmp_lst = dict(lst)
#     print('tmp_lst {}'.format(tmp_lst))
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    tmp_lst[i] -= 1
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    for j in tmp_lst:
#         print(tmp_lst[j])
        c[i] += tmp_lst[j]*(tmp_lst[j]-1)//2
#         print('c[i]: {}'.format(c[i]))
        
for i in range(N):
    print(int(c[A[i]]))

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

# N = 5
# A = [1, 1, 2, 1, 2]

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0

# print(lst)
    
for i in range(N):
    lst[A[i]] += 1

# print(lst)

              

for i in lst:
#     print('i: {}'.format(i))
    c[i] = 0
    tmp_lst = dict(lst)
#     print('tmp_lst {}'.format(tmp_lst))
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    tmp_lst[i] -= 1
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    for j in tmp_lst:
#         print(tmp_lst[j])
        c[i] += tmp_lst[j]*(tmp_lst[j]-1)//2
#         print('c[i]: {}'.format(c[i]))
        
for i in range(N):
    print(c[A[i]])

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

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

c = dict(lst) 
              
              
c_all = 0
for j in lst:
    c_all += lst[j]*(lst[j]-1)//2

for i in lst:
    c[i] = c_all
    c[i] = c[i] - lst[i]*(lst[i]-1)//2 + (lst[i]-1)*(lst[i]-2)//2
        
for i in range(N):
    print(c[A[i]])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
#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)

#TLE
n = int(input())
a = input().split()
ans = 0
import collections
dic = collections.Counter(a)
for i in dic.values():
    ans += i * (i-1)
ans /= 2
for i in range(n):
    print(int(ans - dic[a[i]] + 1))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
 
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))

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


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

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


import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

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


import functools
import math
import collections
import scipy
import fractions
import itertools

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


import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

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


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
maxim = max(A)
select_num = [0 for i in range(0,maxim+1)]
select_num2 = [0 for i in range(0,maxim+1)]
count_num = [0 for i in range(0,maxim+1)]
for i in range(1,maxim+1):
  count_num[i] = A.count(i)
  if(count_num[i] > 1):
    select_num[i] = (count_num[i] - 0)*(count_num[i] - 1)//2
  	select_num2[i] = count_num[i] - 1
sumS = sum(select_num)
for i in range(N):
  print(sumS -select_num2[A[i]])

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

select_num = 0
count_num = [0]*(N+1)
for i in A:
  count_num[i] += 1
for i in range(1,N+1):
  select_num += (count_num[i])*(count_num[i] - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
m = int(input())
q_list = list(map(int, input().strip().split()))
n = [0] * m
k = [0] * m

for i in q_list:
    n[i - 1] += 1
for j, l in zip(range(m), n):
    k[j] = int(l * (l - 1)/2)
sum_n = sum(k)

for j in q_list:
    print(sum_n - n[j - 1]-1)


m = int(input())
q_list = list(map(int, input().strip().split()))
n = [0] * m
k = [0] * m

for i in q_list:
    n[i - 1] += 1
for j, l in zip(range(m), n):
    k[j] = int(l * (l - 1)/2)
sum_n = sum(k)

for j in q_list:
    print(sum_n - n[j - 1] + 1)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0
print(c)

for i in c.values():
    result+=i * (i - 1)//2

for a in a_list:
    print(result - c[a] + 1)  

import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0

for i in c.values():
    result+=i * (i - 1)//2

for a in a_list:
    minus=-(c[a]) * (c[a]-1)//2
    plus=(c[a]-1) * (c[a]-2)//2
    print(result + minus + plus)  

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    li=[[0,0] for _ in range(N+1)]
    di=dict()
    print(li)
    for i in range(N):
        if A[i] not in di:
            di[A[i]]=1
        else:
            di[A[i]]+=1
    
    for k,v in di.items():
        li[k][0]=v*(v-1)//2
        li[k][1]=(v-1)*(v-2)//2

    s=0
    for i in range(N):
        s+=li[i][0]

    for i in range(N):
        print(s-li[A[i]][0]+li[A[i]][1])
if __name__=="__main__":
    main()

from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    li=[[0,0] for _ in range(N+1)]
    di=dict()
    for i in range(N):
        if A[i] not in di:
            di[A[i]]=1
        else:
            di[A[i]]+=1
    
    s=0
    for k,v in di.items():
        li[k][0]=v*(v-1)//2
        s+=v*(v-1)//2
        li[k][1]=(v-1)*(v-2)//2

    for i in range(N):
        print(s-li[A[i]][0]+li[A[i]][1])

if __name__=="__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
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)
  

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

for i in range(n):
  n_list[an[i]-1] += 1
n_sum = int(sum([x*(x-1)/2 for x in n_list]))

for j in range(n):
  n_remove = n_list[an[j]-1] - 1
  print(n_sum - n_remove)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
## coding: UTF-8

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])

## coding: UTF-8

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 = [0 for i in range(N)]
'''
for i in range(N):
    counter = 0
    for j in range(N):
        if(p[j] == i+1):
            counter +=1
    number_list.append(counter)
'''
#print(number_list)

for i in range(N):
    number_list[p[i] - 1] += 1
#print(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))

all_full = sum(full_combi)
for i in range(N):
    print_combi.append(all_full - 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])

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import copy
from scipy.misc import comb
from collections import Counter

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   

f_cnt=Counter(A)
f_dic=dict(f_cnt)

for i,item in enumerate(A):
  if B[item-1]>-1:
    print(B[item-1])
  else:
    D=copy.deepcopy(f_dic)
    D[item] -= 1
    opt=0
    for item3 in D:
      if D[item3]>=2:
        opt += comb(D[item3],2,exact=True)
    B[item-1]=opt
    print(opt)


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

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   

f_cnt=Counter(A)
f_dic=dict(f_cnt)

for i,item in enumerate(A):
  if B[item-1]>-1:
    print(B[item-1])
  else:
    D=copy.deepcopy(f_dic)
    D[item] -= 1
    opt=0
    for item3 in D:
      if D[item3]>=2:
        opt += D[item3]*(D[item3]-1)//2
    B[item-1]=opt
    print(opt)


from scipy.misc import comb
from collections import Counter

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   

for i,item in enumerate(A):
  if B[item-1]>-1:
    
    #print(i,B[item-1],"done")
    print(B[item-1])
  else:
    C=A[0:i]+A[i+1:] 
    cnt = Counter(C)
    D=dict(cnt)
    E=[]
    for item2 in D:
      if D[item2]>=2:
        E.append(D[item2])
    #print(i,E)
    opt=0
    for item3 in E:
      opt += comb(item3,2,exact=True)
    B[item-1]=opt
    #print(i,opt)
    print(opt)
    #print(i,E,opt)
    #print(C,cnt)

N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))
print(d)
cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2

print("cnt",cnt)
   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)

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

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   

f_cnt=Counter(A)
f_dic=dict(f_cnt)
#print("first",f_dic)
#f_dic[1] += -1 
#print(f_dic)

for i,item in enumerate(A):
  if B[item-1]>-1:
    
    #print(i,B[item-1],"done")
    print(B[item-1])
  else:
    
    #cnt = Counter(C)
    #D=dict(cnt)
    D=copy.deepcopy(f_dic)
    D[item] -= 1
    E=[]
    for item2 in D:
      if D[item2]>=2:
        E.append(D[item2])
    #print(i,f_dic,D,E)
    opt=0
    for item3 in E:
      opt += comb(item3,2,exact=True)
    B[item-1]=opt
    #print(i,opt)
    print(opt)
    #print(i,E,opt)
    #print(C,cnt)


N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))
#print(d)
cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2

#print("cnt",cnt)
   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
c=[0]*n

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))

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

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(int(all-(c[a[i]-1]-1)))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter

def main():
    n = int(input())
    balls = [int(i) for i in input().split()]

    # v - value written on ball
    # b - ball index in [0, n)
    # ct - number of times a value occurs

    # hist[v] = ct
    hist = Counter(balls)

    # counts[b] = ct 
    counts = [ hist[balls[b]] for b in range(n) ]

    diff_counts = set(hist.values())
    # combos[ct] = number of combos with ct - 1
    combos1 = { ct: 0 if ct == 1 else (ct-1) * (ct-2) // 2 for ct in
            diff_counts }
    combos = { ct: ct * (ct-1) // 2 for ct in diff_counts  }

    for k in range(n):
        ans = sum(combos.values()) - combos[counts[k]] + combos1[counts[k]]
        print(ans)



from collections import Counter

def main():
    n = int(input())
    balls = [int(i) for i in input().split()]

    # v - value written on ball
    # b - ball index in [0, n)
    # ct - number of times a value occurs

    # hist[v] = ct
    hist = Counter(balls)
    diff_counts = set(hist.values())
    combos1 = { ct: 0 if ct == 1 else (ct-1) * (ct-2) // 2 for ct in
            diff_counts }
    combos = { ct: ct * (ct-1) // 2 for ct in diff_counts  }

    tot = sum(combos[hist[v2]] for v2 in hist.keys())

    for b in range(n):
        v = balls[b]
        ct = hist[v]
        print(tot - combos[ct] + combos1[ct])

main()


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections

N = int(input())
num_list = list(map(int,input().split()))
memo = [0]*(N+1)
memo_flg = [False]*(N+1)
counter = [0] * (N+1)
counter_ans = [0] * (N+1)

for i in range(N):
    counter_ans[i] = (counter[i]*(counter[i]-1))//2

for i in num_list:
    counter[i] += 1

all_sum = sum(counter_ans)
def calc(k):
    num = num_list[k]
    
    if(memo_flg[num] is True):
        return memo[num]
    ans = 0
    
    wrong = counter_ans[num]
    c = counter[num]-1
    right = (c*(c-1))//2
    
    ans = all_sum - wrong + right
    memo[num] = ans
    memo_flg[num] = True
    return ans

[print(calc(i)) for i in range(N)]


import collections

N = int(input())
num_list = list(map(int,input().split()))
memo = [0]*(N+1)
memo_flg = [False]*(N+1)
counter = [0] * (N+1)
counter_ans = [0] * (N+1)

for i in num_list:
    counter[i] += 1
for i in range(N+1):
    counter_ans[i] = (counter[i]*(counter[i]-1))//2

all_sum = sum(counter_ans)
def calc(k):
    num = num_list[k]
    
    if(memo_flg[num] is True):
        return memo[num]
    ans = 0
    
    wrong = counter_ans[num]
    c = counter[num]-1
    right = (c*(c-1))//2
    
    ans = all_sum - wrong + right
    memo[num] = ans
    memo_flg[num] = True
    return ans

[print(calc(i)) for i in range(N)]


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
al=list(map(int,input().split()))

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

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

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


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

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

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

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


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

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

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

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


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import 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)

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))

import collections
import math


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

    for i in a:
        d = c[i]
        print(int(result - (d*(d-1))/2 + ((d-1)*(d-2))/2))

Verdicts: Runtime Error

Runtime Error

Accepted