alexjercan/bugnet huggingface dataset:
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())

print(int(N * (N - 1) / 2 + M * (M - 1) / 2))


Error: TypeError: list expected at most 1 argument, got 2
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s321382416.py", line 1, in <module>
    N, M = list(int, input().split())
TypeError: list expected at most 1 argument, got 2


Fixed submission:

N, M = list(int, input().split())

print(int(N * (N - 1) / 2 + M * (M - 1) / 2))
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

from math import factorial

n, m = map(int, input().split())

if n > 2 and m > 2:
    print(
        factorial(n) // (factorial(n - 2) * factorial(2))
        + factorial(m) // (factorial(m - 2) * factorial(2))
    )
elif n < 2 and m < 2:
    print(0)
elif n < 2:
    print(factorial(m) // (factorial(m - 2) * factorial(2)))
elif m < 2:
    print(factorial(n) // (factorial(n - 2) * factorial(2)))


Error: ModuleNotFoundError: No module named 'scipy'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s504439278.py", line 1, in <module>
    from scipy.special import comb
ModuleNotFoundError: No module named 'scipy'


Fixed submission:

from scipy.special import comb

n, m = map(int, input().split())

print(comb(n, 2, exact=True) + comb(m, 2, exact=True))
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

from math import factorial

n, m = map(int, input().split())
if n in [0, 1] and m in [0, 1]:
    ans = 0
elif n in [0, 1]:
    ans = factorial(m) // (factorial(m - 2) * factorial(2))
elif m in [0, 1]:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
else:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
    ans += factorial(m) // (factorial(m - 2) * factorial(2))
print(ans)


Error: 0

Fixed submission:

from math import factorial

n, m = map(int, input().split())
if n == 1 and m == 1:
    ans = 0
elif n == 1:
    ans = factorial(m) // (factorial(m - 2) * factorial(2))
elif m == 1:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
else:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
    ans += factorial(m) // (factorial(m - 2) * factorial(2))
print(ans)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
print((n * (n - 1)) // 2 + (m * (m - 1)) // 2)


Error: 0

Fixed submission:

import math


def f(x):
    return math.factorial(x)


arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
cnt = 0
cnt += int(f(n) / (2 * f(n - 2)))
if m > 1:
    cnt += int(f(m) / (2 * f(m - 2)))
print(int(cnt))
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())

print(N * (N - 1) // 2 + M * (M - 1) // 2)


Error: TypeError: 'int' object is not callable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s193391695.py", line 3, in <module>
    print(N(N - 1) // 2 + M(M - 1) // 2)
TypeError: 'int' object is not callable


Fixed submission:

N, M = map(int, input().split())

print(N(N - 1) // 2 + M(M - 1) // 2)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

from math import factorial

N, M = map(int, input().split())

if N <= 1:
    combN = 0
else:
    combN = factorial(N) // (factorial(N - 2) * factorial(2))

if M <= 1:
    combM = 0
else:
    combM = factorial(M) // (factorial(M - 2) * factorial(2))

print(combN + combM)


Error: ValueError: factorial() not defined for negative values
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s805116877.py", line 13, in <module>
    combM = factorial(M) // (factorial(M - 2) * factorial(2))
ValueError: factorial() not defined for negative values


Fixed submission:

from math import factorial

N, M = map(int, input().split())

if N == 0:
    combN = 0
else:
    combN = factorial(N) // (factorial(N - 2) * factorial(2))

if M == 0:
    combM = 0
else:
    combM = factorial(M) // (factorial(M - 2) * factorial(2))

print(combN + combM)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

import math

n, m = map(int, input().split())


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


if n >= 2 and m >= 2:
    ans = combinations_count(m, 2) + combinations_count(n, 2)
elif n < 2 and m < 2:
    ans = 0
elif n < 2:
    ans = combinations_count(m, 2)
elif m < 2:
    ans = combinations_count(n, 2)


print(ans)


Error: ValueError: factorial() not defined for negative values
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s072089097.py", line 10, in <module>
    ans = combinations_count(m, 2) + combinations_count(n, 2)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s072089097.py", line 7, in combinations_count
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ValueError: factorial() not defined for negative values


Fixed submission:

import math

n, m = map(int, input().split())


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


ans = combinations_count(m, 2) + combinations_count(n, 2)

print(ans)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))

# 求解処理
result = int(N * (N - 1) / 2 + M * (M - 1) / 2)

# 結果出力
print(result)


Error: ModuleNotFoundError: No module named 'scipy'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s222855902.py", line 3, in <module>
    from scipy.special import comb
ModuleNotFoundError: No module named 'scipy'


Fixed submission:

# -*- coding: utf-8 -*-
# モジュールのインポート
from scipy.special import comb

# 標準入力の取得
N, M = list(map(int, input().split()))

# 求解処理
result = comb(N, 2, exact=True) + comb(M, 2, exact=True)

# 結果出力
print(result)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())

count = 0
if n > 1:
    count += n * (n - 1) // 2
if m > 1:
    count += m * (m - 1) // 2
print(count)


Error: ValueError: invalid literal for int() with base 10: '2 1'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s013867231.py", line 1, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '2 1'


Fixed submission:

n = int(input())
m = int(input())

sum = 0

if n > 1:
    sum += 2 ** (n // 2)
else:
    sum += 1

if m > 1:
    sum += 2 ** (m // 2)
else:
    sum += 1

print(sum)
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

import math


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


def main():
    n, m = map(int, input().split())
    if n < 2:
        even = 0
    else:
        even = combinations_count(n, 2)
    if m < 2:
        odd = 0
    else:
        odd = combinations_count(m, 2)
    print(even + odd)


if __name__ == "__main__":
    main()


Error: ValueError: factorial() not defined for negative values
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 14, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 10, in main
    print(combinations_count(n, 2) + combinations_count(m, 2))
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 5, in combinations_count
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ValueError: factorial() not defined for negative values


Fixed submission:

import math


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


def main():
    n, m = map(int, input().split())
    print(combinations_count(n, 2) + combinations_count(m, 2))


if __name__ == "__main__":
    main()
Problem p02729 (Python) — buggy submission, verdict: Runtime Error

m, n = list(map(int, input().split()))
print(int(m * (m - 1) / 2 + n * (n - 1) / 2))


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s164214433.py", line 2, in <module>
    m, n = list(map(int, input().split()))
EOFError: EOF when reading a line


Fixed submission:

while True:
    m, n = list(map(int, input().split()))
    print(m * (m - 1) / 2 + n * (n - 1) / 2)
Problem p02731 (Python) — buggy submission, verdict: Runtime Error

f = int(input()) / 3.0
print("{:.9f}".format(f * f * f))


Error: AttributeError: 'float' object has no attribute '9f'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02731/Python/s178614375.py", line 2, in <module>
    print("{.9f}".format(f * f * f))
AttributeError: 'float' object has no attribute '9f'


Fixed submission:

f = int(input()) / 3.0
print("{.9f}".format(f * f * f))
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections

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

u = collections.Counter(A)
sum = 0
for j, c in u.items():
    sum += int(c * (c - 1) / 2)

s = ""
for k in A:
    s += str(sum - u[k] + 1) + "\\n"
print(s)


Error: TLE

Fixed submission:

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

u = list(set(A))
c = []
sum = 0
for j in u:
    _ = A.count(j)
    c.append(_)
    sum += int(_ * (_ - 1) / 2)

s = ""
for k in A:
    v = c[u.index(k)]
    s += str(sum - v + 1) + "\\n"
print(s)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter
import time

N = int(input())
line = list(map(int, input().split()))
dic = Counter(line)
nums = 0
for num, cnt in dic.items():
    if cnt > 1:
        nums += (cnt * (cnt - 1)) // 2
for i in line:
    print(nums - (dic[i] - 1))


Error: TLE

Fixed submission:

N = int(input())
line = list(map(int, input().split()))
dic = set(line)
nums = 0
for i in dic:
    cnt = line.count(i) - 1
    nums += (cnt * (cnt + 1)) // 2

for i in line:
    cnt = line.count(i) - 1
    print(nums - cnt)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
    dictA[x] = 0
for x1 in A:
    dictA[x1] += 1

combisum = 0
for y in dictA.values():
    combisum += y * (y - 1) // 2

for z in range(N):
    print(combisum - dictA[A[z]] + 1)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
    dictA[x] = 0
for x1 in A:
    dictA[x1] += 1

for x2 in A:
    dictB = dictA.copy()
    combisum = 0
    dictB[x2] -= 1
    for x3 in dictB.values():
        combisum += x3 * (x3 - 1) // 2
    print(combisum)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections

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

c = collections.Counter(A)

sum_dict = {}
sum_dict_n = {}

sum = 0
sum_n = 0

for key in c.keys():
    coll = c[key] * (c[key] - 1) // 2
    sum_dict[key] = coll
    sum += coll
    value_k = c[key] - 1
    coll_n = value_k * (value_k - 1) // 2
    sum_dict_n[key] = coll_n

for a in A:
    ans = sum
    ans = ans - sum_dict[a] + sum_dict_n[a]
    print(ans)


Error: TLE

Fixed submission:

import collections

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

c = collections.Counter(A)

sum = 0

for a in A:
    for key in c.keys():
        if key == a:
            value_k = c[key] - 1
            sum += value_k * (value_k - 1) // 2
        else:
            value_k = c[key]
            sum += value_k * (value_k - 1) // 2
    print(sum)
    sum = 0
Problem p02732 (Python) — buggy submission, verdict: Runtime Error

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


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


counts = [0] * (N + 1)
for a in A:
    counts[a] += 1
total = sum(map(lambda n: comb2(n), filter(lambda n: n > 1, counts)))

for a in A:
    print(total - (counts[a] - 1))


Error: ModuleNotFoundError: No module named 'scipy'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02732/Python/s178651076.py", line 1, in <module>
    from scipy.misc import comb
ModuleNotFoundError: No module named 'scipy'


Fixed submission:

from scipy.misc import comb

N, M = map(int, input().split())

print(int(comb(N, 2) + comb(M, 2)))
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

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

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1

# print(counts)

ans_memory = {}
ans_memory_val = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue
    if counts[A[k]] in ans_memory_val:
        print(ans_memory_val[counts[A[k]]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    ans_memory_val[counts[A[k]]] = ans
    print(ans)


Error: TLE

Fixed submission:

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

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
        continue
    counts[a] = 1

# print(counts)

ans_memory = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    print(ans)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    num_list = [0] * n  # 各番号が書かれたボールが何個あるか
    method_list = [0] * n  # 同じ番号が書かれた異なる2つのボールを選ぶ方法

    for a in a_list:
        num_list[a - 1] += 1

    for i in range(n):
        b = num_list[i]
        if b >= 2:
            method_list[i] = b * (b - 1) // 2

    total_method = sum(method_list)

    for k in range(n):
        c = a_list[k]  # k番目のボールに書かれている数字
        ans = total_method - method_list[c - 1]
        d = num_list[c - 1]
        if d >= 3:
            e = (d - 1) * (d - 2) // 2
        else:
            e = 0
        ans += e
        print(ans)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_dict = {}
    for a in a_list:
        if a not in a_dict:
            a_dict[a] = 1
        else:
            a_dict[a] += 1

    for k in range(n):
        cnt = 0
        a_dict[a_list[k]] -= 1
        for v in a_dict.values():
            if v >= 2:
                cnt += v * (v - 1) // 2
        a_dict[a_list[k]] += 1
        print(cnt)


if __name__ == "__main__":
    main()
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

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

count = {}
for x in A:
    if count.get(x):
        count[x] += 1
    else:
        count[x] = 1

sub = {}
s = 0
for i, x in count.items():
    count[i] = x * (x - 1) // 2
    s += count[i]
    sub[i] = (x - 1) * (x - 2) // 2

for i in range(N):
    print(s - count[A[i]] + sub[A[i]])


Error: TLE

Fixed submission:

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

count = {}
for x in A:
    if count.get(x):
        count[x] += 1
    else:
        count[x] = 1

for i in range(N):
    count[A[i]] -= 1
    s = 0
    for x in count.values():
        s += x * (x - 1) // 2
    print(s)
    count[A[i]] += 1
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

import math


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


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

b = 0
for n in d.values():
    b += comb(n, 2)

for k in range(N):
    a = A[k]
    print(b - d[a] + 1)


Error: TLE

Fixed submission:

import math


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


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

d2 = {}
for k in range(N):
    a = A[k]

    if a not in d2:
        d2[a] = 0
        for i, n in d.items():
            if a == i:
                d2[a] += comb(n - 1, 2)
            else:
                d2[a] += comb(n, 2)
    print(d2[a])
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
dA = {}
A = []
for a in input().split():
    A.append(a)
    if a in dA:
        dA[a] += 1
    else:
        dA[a] = 1

cA = {}
for a in dA:
    cA[a] = dA[a] * (dA[a] - 1) // 2

s = sum(cA.values())
for a in A:
    print(s - dA[a] + 1)


Error: TLE

Fixed submission:

n = int(input())
dA = {}
A = []
for a in input().split():
    A.append(a)
    if a in dA:
        dA[a] += 1
    else:
        dA[a] = 1

cA = {}
for a in dA:
    cA[a] = dA[a] * (dA[a] - 1) // 2

for a in A:
    print(sum(cA.values()) - dA[a] + 1)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

# from collections import deque
from collections import Counter
from scipy.misc import comb

# from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
for key in C:
    S += comb(C[key], 2, exact=True)

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)


Error: TLE

Fixed submission:

# from collections import deque
from collections import Counter
from scipy.misc import comb
from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
cnt_n = 0
a_n = deepcopy(a)
c = Counter(a_n)
for key in c:
    cnt_n += comb(c[key], 2, exact=True)

for k in range(len(a)):
    a_n = deepcopy(a)
    a_k = deepcopy(a[k])
    a_n.pop(k)
    cnt_k = a_n.count(a_k)
    print(cnt_n - cnt_k)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

from sys import stdin

N = int(stdin.readline())
a_dict = {}
A = list(map(int, stdin.readline().split()))
for a in A:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1

sum_comb = 0
B = set(A)
for b in B:
    n = a_dict[b]
    sum_comb += n * (n - 1) // 2

for a in A:
    ans = sum_comb
    n = a_dict[a]
    ans -= n * (n - 1) // 2
    ans += (n - 1) * (n - 2) // 2
    print(ans)


Error: TLE

Fixed submission:

from scipy.misc import comb
from sys import stdin

N = int(stdin.readline())
count1 = [0] * (N + 1)
count2 = [0] * (N + 1)
A = list(map(int, stdin.readline().split()))

B = list(set(A))

for b in B:
    num_of_b = A.count(b)
    if num_of_b > 2:
        count1[b] = comb(num_of_b, 2, exact=True)
        count2[b] = comb(num_of_b - 1, 2, exact=True)
    elif num_of_b == 2:
        count1[b] = 1


for a in A:
    ans = 0
    ans += sum(count1) - count1[a]
    ans += count2[a]
    print(ans)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
numlist = list(map(int, input().split(" ")))

import collections

numcount = collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)


Error: TLE

Fixed submission:

n = int(input())
numlist = list(map(int, input().split(" ")))
ans = []

sum = 0
for i in range(1, n + 1):
    tmp = numlist.count(i)
    sum += int(tmp * (tmp - 1) / 2)

for i in numlist:
    print(sum - numlist.count(i) + 1)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

import math
import collections


def kumiawase(n):
    if n == 0 or n == 1:
        return 0
    return (n**2 - n) // 2


n = int(input())
aL = list(map(int, input().split(" ")))

d = collections.Counter(aL)

s = 0
for i in d.values():
    s += kumiawase(i)

for a in aL:
    print(s - d[a] + 1)


Error: TLE

Fixed submission:

import math


def kumiawase(n):
    if n == 0 or n == 1:
        return 0
    return math.floor(math.factorial(n) / math.factorial(n - 2) / 2)


n = int(input())
aL = list(map(int, input().split(" ")))

d = {}

for a in aL:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

d2 = {}
d3 = {}

for dk, di in d.items():
    d2[dk] = kumiawase(di)
    d3[dk] = kumiawase(di - 1)

for a in aL:
    sm = sum(d2.values())
    print(sm - d2[a] + d3[a])
Problem p02732 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

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


Error: KeyError: 0
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02732/Python/s071344434.py", line 15, in <module>
    print(total - (cnt[i] - 1))
KeyError: 0


Fixed submission:

N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

for i in range(N):
    print(total - (cnt[i] - 1))
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections

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

C = collections.Counter(A)

s_all = 0
for c in C:
    s_all += C[c] * (C[c] - 1) // 2

for a in A:
    s = 0
    s += s_all - (C[a] - 1)
    print(s)


Error: TLE

Fixed submission:

import collections

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

C = collections.Counter(A)

for a in A:
    s = 0
    for c in C:
        if c == a:
            s += (C[c] - 1) * (C[c] - 2) // 2
        else:
            s += C[c] * (C[c] - 1) // 2
    print(s)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
book = {}
array = [int(i) for i in input().split()]

for i in array:
    book[i] = book.get(i, 0) + 1

sum_val = 0
delta = {}
for k, v in book.items():
    t = (v * (v - 1)) // 2 if v > 0 else 0
    sum_val += t
    u = v - 1
    delta[k] = t - (u * (u - 1)) // 2 if u > 0 else 0

for i in range(n):
    print(sum_val - delta[array[i]])


Error: TLE

Fixed submission:

n = int(input())
book = {}
array = [int(i) for i in input().split()]

for i in array:
    book[i] = book.get(i, 0) + 1

for i in range(n):
    s = 0
    for k, v in book.items():
        if k == array[i]:
            v -= 1
        s += (v * (v - 1)) // 2 if v > 0 else 0
    print(s)
Problem p02732 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

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


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


d = Counter(A)
# print(d)
k = d.keys()

# print(k)
total = 0

for kk in k:
    total += comb(d[kk])

# print(total)

for a in A:
    res = total
    res -= comb(d[a])
    res += comb(d[a] - 1)
    print(res)


Error: TLE

Fixed submission:

from collections import Counter

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

# nC2 = [0] * (N + 1)
# nC2[0] = 0
# nC2[1] = 0
# for i in range(2, N + 1):
#     nC2[i] = i * (i - 1) // 2

# print(nC2)


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


d = Counter(A)
# print(d)
k = d.keys()

# print(k)

for a in A:
    res = 0
    for kk in k:
        if a == kk:
            res += comb(d[kk] - 1)
            # res += nC2[d[kk] - 1]
        else:
            res += comb(d[kk])
            # res += nC2[d[kk]]
    # print(a, d[a], res)
    print(res)