Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

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

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

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

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

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5



Sample input:
5
1 1 2 1 2


Sample output:
2
2
3
2
3

Submission status: Runtime Error

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

n = int(input())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += nC2(ty[i])

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-nC2(ty[a[k]])+nC2(ty[a[k]]-1))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
def comb(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())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += comb(ty[i], 2)

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2)+comb(ty[a[k]]-1, 2))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
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())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += comb(ty[i], 2)

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2)+comb(ty[a[k]]-1, 2))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += comb(ty[i], 2)

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2)+comb(ty[a[k]]-1, 2))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += comb(ty[i], 2, exact=True)

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2, exact=True)+comb(ty[a[k]]-1, 2,exact=True))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

n = int(input())
a = [0]*n
a = list(map(int, input().split()))
map(lambda x: x-1, a)
ty=[0]*n

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

s = 0

for i in range(0, n):
    if ty[i]>=2:
        s += comb(ty[i], 2, exact=True)

for k in range(0, n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2, exact=True)+comb(ty[a[k]]-1, 2,exact=True))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

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

s = 0

for i in range(0,n):
    if ty[i]>=2:
        s += comb(ty[i], 2, exact=True)

for k in range(0,n):
    if ty[a[k]]==2:
        print(s-1)
    elif ty[a[k]]>2:
        print(s-comb(ty[a[k]], 2, exact=True)+comb(ty[a[k]]-1, 2,exact=True))
    else:
        print(s)

Submission status: Runtime Error

Solution code:
import collections

# input
N = int(input())
A = map(int,input().split())
# calculatioin
cnt = collections.Counter(A)
full_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))
for i in range(N):
  print(full_cnt - cnt[A[i]]+1)

Submission status: Runtime Error

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

L = [0 for i in range(N)]

for i in range(N):
  L[int(A[i])-1] +=1

c = 0
for i in range(N):
  n = L[i]
  if n >= 2:
    c += factorial(n) // factorial(2) // factorial(n - 2)

for i in range(N):
  n = L[A[i]-1]
  if n >= 2:
    print(c - n + 1)
  else:
      print(c)

Submission status: Runtime Error

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

L=0
C=[]
for i in range(N):
    C.append(A.count(i))
    L+=int(C[i]*(C[i]-1)/2)
    
for i in range(N):
    print(L-C[A[i]]+1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
import collections as col
 
num _list= set(A)
ca = col.Counter(A)

num = 0

for i in num_list:
    if ca[i] == 1:
        continue
    else:
        num += (ca[i]*(ca[i]-1))//2
        
for i in A:
    ans = num - (ca[i]-1)
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
Ax = np.tile(A, (N, 1))
Ay = np.rot90(Ax, 3)
for a in sum(Ax == Ay):
    print((a-1)*(a-2)//2)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
Ax = np.tile(A, (N, 1))
Ay = np.rot90(Ax, 3)
for a in sum(Ax == Ay):
    print(a-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

no=int(input())
k=list(map(int,input().split()))
u=list(set(k))
#print(u)
c=[]
for x in u:
    c.append(k.count(x))
#print(c)

for i in range(no):
    ind=u.index(k[i])
    #print(ind)
    c[ind]-=1
    #print(c)
    summ=0
    for j in c:
        if(j>=2):
            summ=summ+(math.factorial(j)/math.factorial(2)/math.factorial(j-2))
    c[ind]+=1
    print(int(summ))

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=list(np.fromstring(input(),int,sep=' '))
a_=list(set(a))
dic={}
ans={}
for i in a_:
    dic[i]=a.count(i)
    
def check(x):
    lst_=lst
    count=0
    ans=0
    dic_=dic
    for i in a_:
        if x==i:
            dic_[x]-=1
            break
    for i in dic_.values():
        ans+=i*(i-1)//2
    dic_[x]+=1
    return ans

for i in a_:
    ans[i]=check(i)

for i in a:
    print(ans[i])

Submission status: Runtime Error

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

a_set = sorted(set(a))

count = [0] * n


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


sum = 0
for i in a_set:
    count[i] = a.count(i)
    sum += f(count[i])

for i in a:
    print(sum - (count[i] - 1))

Submission status: Runtime Error

Solution code:
import numpy as np
h,w = [int(i) for i in input().split()]
s = np.zeros((h,w),dtype=int)
for i in range(h):
    for j,v in enumerate(input()):
        s[i][j] = 1 if v == '#' else 2

s_r = np.zeros((h,w),dtype=int)

m = h * w + 1
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        r = m
        if 0 <= j + 1 < w:
            r = s_r[i][j + 1]
        if 0 <= i + 1 < h:
            r = min(r, s_r[i + 1][j])
        if r == m:
            r = 0
        if s[i][j] == 1:
            r += 1
        s_r[i][j] = r
print(s_r[0][0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii();
        int[] count = new int[N+1];
        for (int i = 0; i < N; i++) {
            count[A[i]]++;
        }
        long sum = 0;
        for (int i = 1; i <= N; i++) {
            sum += (long)count[i] * (count[i] - 1) / 2;
        }
        for (int i = 0; i < N; i++) {
            out.println(sum - count[A[i]] + 1);
        }
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
    }
}

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
x = Counter(a)
y = []
for i in a_:
    t = x[i]
    y.append(t*(t-1)//2)
res = sum(y)
for i in a:
    t = x[i]
    t_ = y[i-1]
    print(res-t_+(t-1)*(t-2)//2)

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter
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()))
B = list(Counter(A).items())

#N個のボールから、書かれている整数が等しいような異なる 2 つのボールを選び出す方法の数
for i in range(N):
    B = sorted(B,key=itemgetter(1),reverse = True)
    T = 0
    for j in range(len(B)):
        if B[j][1] > 1:
            T += combinations_count(B[j][1],2)
        else :
            break
#print(B)
#Print(T)
for i in range(N):
    T1 = 0
    T2 = 0
    for j in range(len(B)):
        if A[i] == B[j][0]:
            if B[j][1]-1 > 1:
                T1 = combinations_count(B[j][1],2)
                T2 = combinations_count(B[j][1]-1,2)
            else:
                T1 = combinations_count(B[j][1],2)
                T1 = 1
    print(T - T1 + T2)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.misc import comb
N = int(input())
A = 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 = count + comb(j, 2, exact=True)
        print(count)
        C[A[i]] += 1
banned_count(A)

Submission status: Runtime Error

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=10

n=I()
a=LI()
m=[0]*N
ans=0
for i in a:
    m[i]+=1
for i in m:
    ans+=i*(i-1)//2

for i in a:
    print(ans-(m[i]-1))

Submission status: Runtime Error

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

from operator import mul
from functools import reduce

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

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: Runtime Error

Solution code:
N = int(input())
A = input().split()
tmp = 0
idx = list(set(A))
value = [ A.count(_) for _ in idx ]
for n in value:
    tmp += combi(n)
#sum = 0
for i in A:
    j = idx.index(i)
    #sum += tmp - combi(j) + combi(j-1)
    print(int(tmp - combi(value[j]) + combi(value[j]-1)))

Submission status: Runtime Error

Solution code:
def fac(x):
    if x==1:return 0
    return fac(x-1)+x-1

from collections import Counter
N=int(input())
A=list(map(int,input().split()))
d=dict(Counter(A))
s={}
sum=0
for key,value in d.items():
    k=fac(value)
    s[key]=k
    sum+=k
for x in A:
    print(sum-(d[x]-1))

Submission status: Runtime Error

Solution code:
def fac(x):
    if x==1:return 0
    return fac(x-1)+x-1

from collections import Counter
N=int(input())
A=list(map(int,input().split()))
l=len(A)
d=dict(Counter(A))
s={}
sum=0
for key,value in d.items():
    k=fac(value)
    s[key]=k
    sum+=k
for x in A:
    print(sum-s[x]+fac(d[x]-1))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, ans=0, a=0;
  cin >> n;
  vector<int> vec1(n);
  vector<int> vec2(n);
  vector<int> vec3(n);
  
  for (int i = 0; i < n; i++) {
    cin >> vec1.at(i);
  }
  
  vec2 = vec1;
  sort(vec2.begin(), vec2.end());
  vec2.erase(unique(vec2.begin(), vec2.end()), vec2.end() );
  
  for (int i = 0; i < vec2.size(); i++) {
    a = count(vec1.begin(), vec1.end(), vec2.at(i));
    vec3.at(i) = a;
    ans += a*(a-1)/2;
  }
  
  for (int j = 0; j < n; j++) {
    cout << ans-1-vec3.at(vec1.at(j)) << endl;
  }
}

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
d=collections.Counter(a)
total=sum([(v-1)*v//2, for v in d.values()])
for x in a:
    print(total-d[x]+1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x) is None:
        d[x]=1
        continue
    d[x]+=1
total=0
for v in d.values():
    total+=(y-1)*y//2
for x in a:
    print(total-d[x]+1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
ua=list(set(a))
total=sum([sum(range(a.count(x))) for x in ua])
d={}
total=0
for x in ua:
    c=a.count(x)
    d[x]=c
    total+=sum(range(c))
for i in range(n):
    print(total-d[i]+1)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

Cnt = [(a-1) for a in A]

tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
num_list = list(map(int,input().split()))
a = Counter(num_list)
count = 0
for i in a.values():
  count += (i*(i-1))//2
for j in num_list:

Submission status: Runtime Error

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

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

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

num = dict()
for i in AS:
    if i not in num:
        num[i] = 1
    else:
        num[i] += 1

comb_list = [-1]*(max(num.values())+1)
all_num = 0
for i in num:
    if comb_list[i] == -1:
        all_num += comb(num[i])
        comb_list[i] = comb(num[i])
    else:
        all_num += comb_list[i]
    
for i in range(n):
    j = num[AS[i]]
    ans = all_num - (j-1)
    print(ans)

Submission status: Runtime Error

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

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

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

num = dict()
for i in AS:
    if i not in num:
        num[i] = 1
    else:
        num[i] += 1

print(num)

comb_list = [-1]*(max(num.values())+1)
all_num = 0
for i in num:
    if comb_list[i] == -1:
        all_num += comb(num[i])
        comb_list[i] = comb(num[i])
    else:
        all_num += comb_list[i]
print(comb_list)
    
for i in range(n):
    j = num[AS[i]]
    ans = all_num - (j-1)
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
import math
def calculateProb(counts):
    ways = 0
    for key in counts.keys():
        if counts[key] < 2:
            continue
        if counts[key] in cache:
            ways += cache[counts[key]]
        else:
            val = counts[key]
            cache[val] = math.factorial(val)/math.factorial(2)/math.factorial(val - 2)
            ways += cache[val]
    return ways

def getfact(val):
    if val < 2:
        return 0
    return math.factorial(val)/math.factorial(2)/math.factorial(val - 2)


n = int(input())

values = list(map(int, input().split(' ')))
counts = collections.Counter(values)

cache = {}
ways = calculateProb(counts)
for k in range(n):
    curVal = values[k]
    count = counts[curVal]
    temp = ways
    ways = ways - getfact(count)  + getfact(count - 1)
    print(int(ways))
    ways = temp

Submission status: Runtime Error

Solution code:
import collections
import math
def calculateProb(counts):
    ways = 0
    for key in counts.keys():
        if counts[key] < 2:
            continue
        if counts[key] in cache:
            ways += cache[counts[key]]
        else:
            val = counts[key]
            cache[val] = math.factorial(val)/math.factorial(2)/math.factorial(val - 2)
            ways += cache[val]
    return ways

        


n = int(input())

values = list(map(int, input().split(' ')))
counts = collections.Counter(values)

cache = {}

for k in range(n):
    curVal = values[k]
    counts[curVal] -= 1
    print(int(calculateProb(counts)))
    counts[curVal] += 1

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n=int(input())
a=list(map(int,input().split()))
b=[0]*max(a)
for i in range(len(a)):
    b[a[i]-1]+=1
for i in range(len(a)):
    ans=0
    b[a[i]-1]-=1
    for j in range(len(b)):
        if b[j]<2:
            ans=ans
        else:
            ans+=comb(b[j],2)
    print(ans)
    b[a[i]-1]+=1

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(N):
  if A[i] in dic1:
    dic1[A[i]] += 1
    dic2[A[i]].append(i)
  else:
    dic1[A[i]] = 1
    dic2[A[i]].append(i)

for j in range(N):
  ans = 0
  for k, v in dic1.items():
    if j in dic2[k]:
      ans += ((v-1)*(v-2))//2
    else:
      ans += (v*(v-1))//2
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ao = list(map(int, input().split(' ')))
a = list(set(ao))
ac = 0
acount = []
text = ""
count = 0
la = len(a)
for i in range(n):
    c = ao.count(i+1)
    if c == 1:
        acount[i] = 0
    else:
        ac += int(c*(c-1)/2)
        acount.append(c)
count = 0


count = 0
for i in range(n):
    text += "{0}\n".format(ac-acount[ao[i]-1]+1)
    count += 1
print(text[0:-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
an= list(map(int, input().split()))

datas = [0] * n
for a in an:
    datas[a] += 1

for k in range(0,n):
    ans=0
    for i in range(1,n):
        if datas[i] > 1:
            if i == an[k]:
                ans += (datas[i]-1) * (datas[i]-2)/2
            else:
                ans += datas[i] * (datas[i]-1)/2
    print(int(ans))

Submission status: Runtime Error

Solution code:
import time

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

dict = {}
for num in a:
    if num not in dict:
        if a.count(num) >=2:
            dict[num] = a.count(num)

total = 0
for key in dict:
    total += dict[key]*(dict[key]-1)/2

for num in a:
    print(int(total - dict[num]+1))

Submission status: Runtime Error

Solution code:
def CountFrequency_mod(my_list): 
  
    # Creating an empty dictionary  
    freq = {} 
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else: 
            freq[item] = 1
    
    freq_mod = freq
    freq_val = list(freq.values())
    all_sum=0
    
    for i in freq_val:
        all_sum+=i*(i-1)/2
        
    for i in freq:
        freq_mod = all_sum - freq[i]*(freq[i]-1)/2 + (freq[i]-1)*(freq[i]-2)/2
    return freq_mod


N = int(input())

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

dic = CountFrequency_mod(A)

for i in A:
    print(int(dic[i]))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        del unique[t]
        continue
    else:
        uniqueNum.append(E.count(unique[t]))
for l in range(len(uniqueNum)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(uniqueNum)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    if int(E[k]) in unique:
        print(int(uniqueAns[E[k]]))
    else:
        print(int(full))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        del unique[t]
        continue
    uniqueNum.append(E.count(unique[t]))
for l in range(len(uniqueNum)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(uniqueNum)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    if int(E[k]) in unique:
        print(int(uniqueAns[E[k]]))
    else:
        print(int(full))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
e=list(set(a))                                                                     s=0                                                                                t=[0]*200000                                                                       for i in a:
    t[i]+=1                                                                        for j in e:                                                                            k=t[j]                                                                             s+=(k*(k-1))//2
for u in a:
    print(s-t[u]+1)

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        del unique[t]
        continue
    uniqueNum.append(E.count(unique[t]))
for l in range(len(uniqueNum)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(uniqueNum)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    try:
        print(int(uniqueAns[E[k]]))
    except:
        print(int(full))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
al=[0]*n
for i in a:
    al[i]+=1
for j in aset:
    k=al[j]
    ans+=(k*(k-1))//2
for u in a:
    print(ans-al[u]+1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
alist=[0]*n
for j in aset:
    k=a.count(j)
    alist[j]=k
    ans+=(k*(k-1))//2
for u in a:
    print(ans-alist[u]+1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
alist=[ 0 for i in range(n)]
for _ in a:
    alist[_ - 1] += 1
for j in aset:
    k=a.count(j)                                                                       ans += (k*(k-1)) // 2                                                          for u in a:
    print(ans - alist[u - 1]+1)

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        del unique[t]
        t -= 1
        continue
    uniqueNum.append(E.count(unique[t]))
    full = full + uniqueNum[t] * (uniqueNum[t]-1)/2
for m in range(len(unique)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    print(int(uniqueAns[E[k]]))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        unique.pop(t)
        continue
    uniqueNum.append(E.count(unique[t]))
    full = full + uniqueNum[t] * (uniqueNum[t]-1)/2
for m in range(len(unique)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    print(int(uniqueAns[E[k]]))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(map(int,numpy.unique(E)))
uniqueNum = []
uniqueAns = {}
full =0
for t in range(len(unique)):
    if E.count(unique[t]) == 1:
        unique.pop(t)
        t -= 1
        continue
    uniqueNum.append(E.count(unique[t]))
    full = full + uniqueNum[t] * (uniqueNum[t]-1)/2
for m in range(len(unique)):
    uniqueAns[unique[m]] = full - uniqueNum[m]+1
for k in range(N):
    print(int(uniqueAns[E[k]]))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = []

for t in range(len(unique)):
    uniqueNum.append(E.count(unique[t]))
    full = full + uniqueNum[t] * (uniqueNum[t]-1)/2
uniqueAns = []
full =0

for m in range(len(unique)):
    uniqueAns.append(full - uniqueNum[m]+1)
for k in range(N):
    ans.append(uniqueAns[unique.index(E[k])])
    print(int(ans[k]))

Submission status: Runtime Error

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = []
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = []

for t in range(len(unique)):
    uniqueNum.append(E.count(unique[t]))
    full = full + uniqueNum[t] * (uniqueNum[t]-1)/2
uniqueAns = []
full =0
for l in range(len(unique)):

for m in range(len(unique)):
    uniqueAns.append(full - uniqueNum[m]+1)
for k in range(N):
    ans.append(uniqueAns[unique.index(E[k])])
    print(int(ans[k]))

Submission status: Runtime Error

Solution code:
import collections
import bisect
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
Key = []
Val = []
for key,val in A.items():
    Key.append(key)
    Val.append(val)
ans = 0
ans1 = 0
for i in range(len(Val)):
    ans+= ((Val[i])*(Val[i]-1))//2
for i in range(n):
    s = bisect.bisect_left(Key,a[i])
    d1 = (Val[s]*(Val[s]-1))//2
    Val[s]-=1
    d2 = (Val[s]*(Val[s]-1))//2
    ans1 = ans - (d1-d2)
    print(ans1)
    Val[s]+=1
print(ans1)