Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n753 = set()
for i in range(357, 77777753+1):
    s = str(i)
    if "1" in s:
        continue
    if "2" in s:
        continue
    if "4" in s:
        continue
    if "6" in s:
        continue
    if "8" in s:
        continue
    if "9" in s:
        continue
    if "3" not in s:
        continue
    if "5" not in s:
        continue
    if "7" not in s:
        continue
    n753.add(i)


N = int(input())

print(len([1 for n in n753 if n <= N]))


Fixed submission:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

Plist = defaultdict(list)

for p, y in PY:
    Plist[p].append(y)

for p, l in Plist.items():
    l.sort()

for p, y in PY:
    idx = Plist[p].index(y)
    print("{:06}{:06}".format(p, idx+1))


Fixed submission:
from collections import defaultdict

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

years = []
for i in range(M):
    P, Y = map(int, input().split())
    years.append((P, Y))

d = defaultdict(int)
b = dict()
for p, y in sorted(years, key=lambda x: x[1]):
    d[p] += 1
    b[y] = '{:06d}{:06d}'.format(p, d[p])

for p, y in years:
    print(b[y])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

books = [[] for _ in range(N + 1)]
years = []

for i in range(M):
    P, Y = map(int, input().split())
    years.append((P, Y))

for p, y in years:
    books[p].append(y)

for i in range(N + 1):
    books[i].sort()

for p, y in years:
    ind = books[p].index(y) + 1
    s = ''
    s += '{:06d}'.format(p)
    s += '{:06d}'.format(ind)
    print(s)


Fixed submission:
from collections import defaultdict

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

years = []
for i in range(M):
    P, Y = map(int, input().split())
    years.append((P, Y))

d = defaultdict(int)
b = dict()
for p, y in sorted(years, key=lambda x: x[1]):
    d[p] += 1
    b[y] = '{:06d}{:06d}'.format(p, d[p])

for p, y in years:
    print(b[y])
Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


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

if N == 1:
    print(M)
    exit()

if is_prime(M):
    print(1)
    exit()

ans = 0
for i in range(1, M+1):
    d, m = divmod(M, i)
    if m == 0 and d >= N:
        ans = i
    if d < N:
        break

print(ans)



Fixed submission:
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass


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

K = divisor(M)

ans = 0
for k in K:
    if N * k <= M:
        ans = max(ans, k)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

if N == 1:
    print(M)
    exit()

ans = 0
for i in range(1, M+1):
    d, m = divmod(M, i)
    if m == 0 and d >= N:
        ans = i
    if d < N:
        break

print(ans)


Fixed submission:
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass


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

K = divisor(M)

ans = 0
for k in K:
    if N * k <= M:
        ans = max(ans, k)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

ans = 0
for i in range(1, M+1):
    d, m = divmod(M, i)
    if m == 0 and d >= N:
        ans = i
    if d < N:
        break

print(ans)


Fixed submission:
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass


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

K = divisor(M)

ans = 0
for k in K:
    if N * k <= M:
        ans = max(ans, k)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

ans = 0
for i in range(1, M+1):
    d, m = divmod(M, i)
    if m == 0 and d >= N:
        ans = i
    if d < N:
        break

print(ans)


Fixed submission:
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass


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

K = divisor(M)

ans = 0
for k in K:
    if N * k <= M:
        ans = max(ans, k)


print(ans)
Buggy python submission (verdict: Runtime Error):
import re

S = input().rstrip()
K = int(input())

i = re.search(r'[2-9]', S).start()

if K < i + 1:
    print(1)
else:
    if S[0] == '1':
        print(S[i])
    else:
        print(S[0])


Fixed submission:
import re

S = input().rstrip()
K = int(input())

reg = re.search(r'[2-9]', S)
if reg:
    i = reg.start()
else:
    i = len(S) + 1


if K < i + 1:
    print(1)
else:
    if S[0] == '1':
        print(S[i])
    else:
        print(S[0])
Buggy python submission (verdict: Time Limit Exceeded):


import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = list(input().strip())
K = int(input())
N = len(s)

if N == 1:
    print(s[0])
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(''.join(s[i:j+1]))

print(sorted(sub)[K])


Fixed submission:

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

print(sorted(substr)[K-1])

Buggy python submission (verdict: Runtime Error):

import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = list(input().strip())
K = int(input())
N = len(s)

if N == 1:
    print(s[0])
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j+1])

print(sorted(sub)[K])


Fixed submission:

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

print(sorted(substr)[K-1])

Buggy python submission (verdict: Time Limit Exceeded):

import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = input().strip()
K = int(input())
N = len(s)

if N == 1:
    print(s)
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j+1])

print(sorted(sub)[K])


Fixed submission:

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

print(sorted(substr)[K-1])

Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = input().strip()
K = int(input())
N = len(s)

sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j + 1])

print(sorted(sub)[K])


Fixed submission:

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

print(sorted(substr)[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    C = sorted([x for index, x in enumerate(X) if index != i])
    print(C[len(C)//2])


Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
CL = Y[N//2-1]
CR = Y[N//2]

for x in X:
    if x < CR:
        print(CR)
    else:
        print(CL)
Buggy python submission (verdict: Runtime Error):
def abc():
    a, b, c = map(int, input().split())
    n = list(range(a, b + 1))
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()


Fixed submission:
def abc():
    a, b, c = map(int, input().split())
    n = range(a, b + 1)
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()

Buggy python submission (verdict: Runtime Error):
def abc():
    a, b, c = map(int, input().rstrip().split())
    n = list(range(a, b + 1))
    s = sorted(set(n[:c]) | set(n[-c:]))
    for _s in s:
        print(_s)


abc()


Fixed submission:
def abc():
    a, b, c = map(int, input().split())
    n = range(a, b + 1)
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()

Buggy python submission (verdict: Runtime Error):
def abc():
    a, b, c = map(int, input().split())
    n = list(range(a, b + 1))
    s = sorted(set(n[:c]) | set(n[-c:]))
    for _s in s:
        print(_s)


abc()


Fixed submission:
def abc():
    a, b, c = map(int, input().split())
    n = range(a, b + 1)
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()

Buggy python submission (verdict: Runtime Error):
def abc():
    a, b, c = map(int, input().split())
    n = list(range(a, b + 1))
    s = sorted(set(n[:c]) | set(n[-c:]))
    for _s in s:
        print(_s)


abc()

Fixed submission:
def abc():
    a, b, c = map(int, input().split())
    n = range(a, b + 1)
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()
Buggy python submission (verdict: Time Limit Exceeded):
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for a1 in range(max(c[0][0], c[0][1], c[0][2]) + 1):
    for a2 in range(max(c[1][0], c[1][1], c[1][2]) + 1):
        for a3 in range(max(c[2][0], c[2][1], c[2][2]) + 1):
            for b1 in range(max(c[0][0], c[1][0], c[2][0]) + 1):
                for b2 in range(max(c[0][1], c[1][1], c[2][1]) + 1):
                    for b3 in range(max(c[0][2], c[1][2], c[2][2]) + 1):
                        if a1 + b1 == c[0][0] and \
                           a1 + b2 == c[0][1] and \
                           a1 + b3 == c[0][2] and \
                           a2 + b1 == c[1][0] and \
                           a2 + b2 == c[1][1] and \
                           a2 + b3 == c[1][2] and \
                           a3 + b1 == c[2][0] and \
                           a3 + b2 == c[2][1] and \
                           a3 + b3 == c[2][2]:
                            print('Yes')
                            exit()
print('No')


Fixed submission:
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

x = [0] * 3
y = [0] * 3

for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]

for i in range(3):
    for j in range(3):
        if x[i] + y[j] != c[i][j]:
            print('No')
            exit()

print('Yes')
Buggy python submission (verdict: Runtime Error):
print(sum[map(int, input())])

Fixed submission:
print(sum(map(int, input())))
Buggy python submission (verdict: Runtime Error):
ceil = lambda a, b: -(-a // b)

K, A, B = map(int, input().split())
if A >= K:
    print(1)
    exit()
p = A - B
if p < 0:
    print(-1)
    exit()

ans = 1
ans += ceil(K - A, A - B) * 2
print(ans)


Fixed submission:
ceil = lambda a, b: -(-a // b)

K, A, B = map(int, input().split())
if A >= K:
    print(1)
    exit()
p = A - B
if p <= 0:
    print(-1)
    exit()

ans = 1
ans += ceil(K - A, A - B) * 2
print(ans)

Buggy python submission (verdict: Runtime Error):
ceil = lambda a, b: -(-a // b)

K, A, B = map(int, input().split())
if A >= K:
    print(1)
    exit()
p = A - B
if p < 0:
    print(-1)
    exit()

ans = 1
ans += ceil(K - A, A - B) * 2
print(ans)


Fixed submission:
ceil = lambda a, b: -(-a // b)

K, A, B = map(int, input().split())
if A >= K:
    print(1)
    exit()
p = A - B
if p <= 0:
    print(-1)
    exit()

ans = 1
ans += ceil(K - A, A - B) * 2
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input().strip()

K = S.find('K')
I = S.find('I')
H = S.find('H')
B = S.find('B')
R = S.find('R')

if S.find('AA'):
    print('NO')
    exit()

if K in [0, 1] and I >= 0 and H >= 0 and B >= 0 and R >= 0 and \
   I-K in [0, 1] and H-I in [0, 1] and B-H in [0, 1] and R-B in [0, 1] and:
    print('YES')
else:
    print('NO')

Fixed submission:
S = input().strip()

if S.find('AA') != -1:
    print('NO')
    exit()

if S.find('KAI') != -1:
    print('NO')
    exit()

if S.find('IAH') != -1:
    print('NO')
    exit()

if S.replace('A', '') == 'KIHBR':
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0
for b in B:
    na = len(A[:bisect.bisect_left(A, b)])
    nc = len(C[bisect.bisect_right(C, b):])
    ans += na * nc

print(ans)

Fixed submission:
import bisect

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
LC = len(C)
ans = 0
for b in B:
    na = bisect.bisect_left(A, b)
    nc = LC - bisect.bisect_right(C, b)
    ans += na * nc

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

B = copy.deepcopy(A)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        for k in range(N):
            if j == k:
                continue
            if k == i:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            if A[i][j] == A[i][k] + A[k][j]:
                B[i][j] = 0

ans = 0
for i in range(N):
    for j in range(i, N):
        ans += B[i][j]

print(ans)



Fixed submission:
import copy

N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

B = copy.deepcopy(A)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        for k in range(N):
            if j == k:
                continue
            if k == i:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            if A[i][j] == A[i][k] + A[k][j]:
                B[i][j] = 0

ans = 0
for i in range(N):
    for j in range(i, N):
        ans += B[i][j]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])


Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])


Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

bridge1 = []
bridge2 = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        bridge1.append((a, b))
    if b == N:
        bridge2.append((a, b))

if len(bridge1) == 0 or len(bridge2) == 0:
    print('IMPOSSIBLE')
    exit()

for b1 in bridge1:
    for b2 in bridge2:
        if b1[1] == b2[0]:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')

Fixed submission:
N, M = map(int, input().split())

bridge1 = []
bridge1_right = set()
bridge2 = []
bridge2_left = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        bridge1.append((a, b))
        bridge1_right.add(b)
    if b == N:
        bridge2.append((a, b))
        bridge2_left.add(a)

if len(bridge1) == 0 or len(bridge2) == 0:
    print('IMPOSSIBLE')
    exit()

if len(bridge1_right & bridge2_left) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

bridge1 = []
bridge2 = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        bridge1.append((a, b))
    if b == N:
        bridge2.append((a, b))

for b1 in bridge1:
    for b2 in bridge2:
        if b1[1] == b2[0]:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')

Fixed submission:
N, M = map(int, input().split())

bridge1 = []
bridge1_right = set()
bridge2 = []
bridge2_left = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        bridge1.append((a, b))
        bridge1_right.add(b)
    if b == N:
        bridge2.append((a, b))
        bridge2_left.add(a)

if len(bridge1) == 0 or len(bridge2) == 0:
    print('IMPOSSIBLE')
    exit()

if len(bridge1_right & bridge2_left) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
def abc():
    n = int(input())
    p = 1
    for i in range(1, n+1):
        p *= i
    print(p % (10 ** 9 + 7))


abc()


Fixed submission:
def abc():
    import math
    n = int(input())
    print(math.factorial(n) % (10 ** 9 + 7))


abc()
Buggy python submission (verdict: Time Limit Exceeded):
S, C = map(int, input().split())

if S * 2 >= C:
    print(C//2)
    exit()

i = 0
while (C - 2*i)/(S + i) >= 2:
    i += 1

print(S + i - 1)


Fixed submission:
S, C = map(int, input().split())

if S * 2 >= C:
    print(C//2)
    exit()

i = (C - 2 * S) // 4

print(S + i)
Buggy python submission (verdict: Time Limit Exceeded):
def abc():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        for y in range(k + 1):
            for z in range(k + 1):
                if x + y + z == s:
                    ans += 1
    print(ans)


abc()


Fixed submission:
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - (x + y) <= k:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

L = []
for i in range(N):
    L.append(tuple(map(int, input().split())))

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    tmpT = L[i][0]
    tmpA = L[i][1]
    mul = 2
    while not(tmpT >= nowT and tmpA >= nowA):
        tmpT = L[i][0] * mul
        tmpA = L[i][1] * mul
        mul += 1
    nowT = tmpT
    nowA = tmpA

print(nowT + nowA)


Fixed submission:
N = int(input())

nowT = 1
nowA = 1
for i in range(N):
    nextT, nextA = map(int, input().split())

    # mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
    mul = max(-(-nowT // nextT), -(-nowA // nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print(nowT + nowA)
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h, 2)

    for a in A:
        h = hist[a-1]
        if h > 2:
            diff = combinations_count(h, 2) - combinations_count(h-1, 2)
            print(all - diff)
        elif h == 2:
            print(all - 1)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()

Fixed submission:
import math

def combinations_count(n):
    return math.floor(n*(n-1)/2)

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h)

    for a in A:
        h = hist[a-1]
        if h >= 2:
            diff = h-1
            print(all - diff)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

import math

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

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h, 2)

    for a in A:
        h = hist[a-1]
        if h > 2:
            diff = combinations_count(h, 2) - combinations_count(h-1, 2)
            print(all - diff)
        elif h == 2:
            print(all - 1)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()

Fixed submission:
import math

def combinations_count(n):
    return math.floor(n*(n-1)/2)

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h)

    for a in A:
        h = hist[a-1]
        if h >= 2:
            diff = h-1
            print(all - diff)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()