Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input() for i in range(n))]
inf = 10**4

def bamboo_connect(i, a, b, c):
    if i == N:
        if all(a, b, c):
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    no_connect = bamboo_connect(i+1, a, b, c)
    choice_a = bamboo_connect(i+1, a+l[i], b, c) + 10
    choice_b = bamboo_connect(i+1, a, b+l[i], c) + 10
    choice_c = bamboo_connect(i+1, a, b, c+l[i]) + 10
    return min(no_connect, choice_a, choice_b, choice_c)

print(bamboo_connect(0, 0, 0, 0))

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 10**4

def bamboo_connect(i, a, b, c):
    if i == N:
        if all((a, b, c)):
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    no_connect = bamboo_connect(i+1, a, b, c)
    choice_a = bamboo_connect(i+1, a+l[i], b, c) + 10
    choice_b = bamboo_connect(i+1, a, b+l[i], c) + 10
    choice_c = bamboo_connect(i+1, a, b, c+l[i]) + 10
    return min(no_connect, choice_a, choice_b, choice_c)

print(bamboo_connect(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
5 3
5
7
5
7
7

Fixed submission:
n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])

res = h[k-1] - h[0]
for i in range(k, n):
    tmp = h[i] - h[i-k+1]
    res = min(res, tmp)

print(res)
Buggy python submission (verdict: Runtime Error):
n=[int(input()) for i in range(int(input()))]
print(sum(n) - max(n)//2)

Fixed submission:
print('YES' if input() in ['3', '5', '7'] else 'NO')
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

n, x = map(int, input().split())
town = map(int, input().split())

distance = (abs(x-y) for y in town)
print(distance)
for d in distance:
    res = gcd(next(d), next(d))

print(res)


Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while a > 0:
        a, b = b, a%b
    return b

n, x = map(int, input().split())
town = list(map(int, input().split()))

res = abs(town[0] - x)
for t in town[1:]:
    d = abs(t - x)
    res = gcd(res, d)

print(res)

Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while a > 0:
        a = a % b
        a, b = b, a
    return b

n, x = map(int, input().split())
town = list(map(int, input().split()))

res = abs(town[0] - x)
for t in town[1:]:
    d = abs(t - x)
    res = gcd(res, d)

print(res)

Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Buggy python submission (verdict: Runtime Error):
from math import gcd

n, x = map(int, input().split())
town = list(map(int, input().split()))

res = abs(town[0] - x)
for t in town[1:]:
    d = abs(t - x)
    res = gcd(res, d)

print(res)

Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from fractions import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

Fixed submission:
from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()
if s[0] == 'A':
    s = s[1:]
    if s[1:-2].cont('C') == 1:
        s.remove('C')
        if s == s.lower():
            print('AC')
            exit()
print('WA')

Fixed submission:
s = input()
if s[0] == 'A':
    s = s[1:]
    if s[1:-1].count('C') == 1:
        for char in s:
            if char != 'C' and char == char.upper():
                break
        else:
            print('AC')
            exit()
print('WA')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
list_ = []

for i in range(1, n-1):
    x = set(s[:i])
    y = set(s[i:])
    cnt = 0
    for j in x:
        if j in y:
            cnt += 1
    list_.append(cnt)

print(max(list_))

Fixed submission:
n = int(input())
s = input()
list_ = []

for i in range(n):
    x = set(s[:i])
    y = set(s[i:])
    cnt = 0
    for j in x:
        if j in y:
            cnt += 1
    list_.append(cnt)

print(max(list_))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

set_ = set()

for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        set_.add(s[i:j])

res = sorted(list(set_))[k-1]
print(res)

Fixed submission:
s = input()
k = int(input())

s_head = sorted(list(set(s)), reverse=True)
res = [s_head.pop()]
while len(res) < k:
    tmp = res[-1]
    tmp_list = []
    for i in range(len(s)-len(tmp)):
        if s[i:i+len(tmp)] == tmp:
            tmp_list.append(s[i:i+len(tmp)+1])
    if len(tmp_list) == 0:
        res.append(s_head.pop())
    elif min(tmp_list) == tmp:
        res.append(s_head.pop())
    else:
        res.append(min(tmp_list))

print(res[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = [int(i) for i in input().split()]
x_sorted = sorted(x)

x_1 = x_sorted[n // 2 - 1]
x_2 = x_sorted[n // 2]

for i in x:
    if x_sorted.index(i) < n // 2:
        print(x_2)
    else:
        print(x_1)

Fixed submission:
n = int(input())
x = [int(i) for i in input().split()]
x_sorted = sorted(x)

x_1 = x_sorted[n // 2 - 1]
x_2 = x_sorted[n // 2]

for x_ in x:
    if x_ <= x_1:
        print(x_2)
    else:
        print(x_1)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
arr = list(range(a, b+1))
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
arr = range(a, b+1)
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
arr = list(range(a, b+1))
for i in sorted(set((arr[:k]+arr[-k:]))):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
arr = range(a, b+1)
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
arr = list(range(a, b+1))
for i in sorted(set(arr[:k]|arr[-k:])):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
arr = range(a, b+1)
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
arr = list(range(a, b+1))
for i in sorted(set(arr[:k]+arr[-k:])):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
arr = range(a, b+1)
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
arr = list(range(a, b+1))
for i in set(arr[:k]+arr[-k:]):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
arr = range(a, b+1)
for i in sorted(set(arr[:k]) | set(arr[-k:])):
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]

agg = [list() for _ in range(n)]
for i in range(n):
    c, d = blue[i]
    for j in range(n):
        a, b = red[j]
        if c > a and d > b:
            agg[i].append(j)

prod = itertools.product(*[x for x in agg if len(x) > 0])
res = 0
for p in prod:
    res = max(res, len(set(p)))

print(res)

Fixed submission:
n = int(input())
red = sorted([tuple(map(int, input().split())) for _ in range(n)])
blue = sorted([tuple(map(int, input().split())) for _ in range(n)])

res = 0
for bx, by in blue:
    tmp_max = -1
    tmp_cnt = None
    for i, (rx, ry) in enumerate(red):
        if bx <= rx:
            break
        if tmp_max <= ry < by:
            tmp_max = ry
            tmp_cnt = i
    if tmp_cnt is not None:
        res += 1
        red.pop(tmp_cnt)

print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
station = (tuple(map(int, input().split())) for _ in range(n-1))

for i in range(n):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        res += max(s - res, (res+f-1)//f*f - res) + c
    print(res)


Fixed submission:
n = int(input())
station = [tuple(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        if res == 0:
            res += s + c
        else:
            res += max(s-res, ((res+(f-1))//f)*f - res) + c
    print(res)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input())
print('Left' if a+b>c+d else 'Balanced' if a+b==c+d else 'Right')

Fixed submission:
a, b, c, d = map(int, input().split())
print('Left' if a+b>c+d else 'Balanced' if a+b==c+d else 'Right')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

s = set()
for a_ in a:
    s ^= a

print(len(s))


Fixed submission:
n = int(input())

s = set()
for _ in range(n):
    s ^= {input()}

print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())

l = []
for _ in range(n):
    a = int(input())
    i = bisect.bisect_left(l, a)
    if i != len(l) and l[i] == a:
        l.pop(i)
    else:
        l.insert(i, a)

res = len(l)
print(res)

Fixed submission:
n = int(input())

s = set()
for _ in range(n):
    s ^= {input()}

print(len(s))
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' x >= b-a else 'dangerous')

Fixed submission:
x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' if x >= b-a else 'dangerous')

Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' x >= b-1 else 'dangerous')

Fixed submission:
x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' if x >= b-a else 'dangerous')
Buggy python submission (verdict: Runtime Error):
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = map(int, input().split())

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print(Yes)
else:
    print(No)  

Fixed submission:
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = map(int, input().split())

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a%2==0 and b%2==0 and c%2==0 and a==b==c:
    print(-1)
else:
    res = 0
    while True:
        if a%2==1 or b%2==1 or c%2==1:
            break
        else:
            a, b, c = b//2+c//2, a//2+c//2, a//2+b//2
            res += 1

print(res)


Fixed submission:
a, b, c = map(int, input().split())

if a%2==0 and b%2==0 and c%2==0 and a==b==c:
    print(-1)
else:
    res = 0
    while True:
        if a%2==1 or b%2==1 or c%2==1:
            break
        else:
            a, b, c = b//2+c//2, a//2+c//2, a//2+b//2
            res += 1
    print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]

res = 0
x = 0
for i in range(n-1):
    x += a[i]
    sign = (x // abs(x)) * (-1)
    tmp = sign - (x + a[i+1])
    if sign < 0:
        tmp = min(tmp, 0)
    else:
        tmp = max(tmp, 0)
    res += abs(tmp)
    a[i+1] += tmp

print(res)

Fixed submission:
n = int(input())
arr = [0] + [int(x) for x in input().split()]

def exec(sign):
    a = [x for x in arr]
    res = 0

    x = 0
    for i in range(n):
        x += a[i]
        tmp = sign - (x + a[i+1])
        if sign < 0:
            tmp = min(tmp, 0)
        else:
            tmp = max(tmp, 0)
        res += abs(tmp)
        a[i+1] += tmp
        sign *= (-1)
    return res

print(min(exec(1), exec(-1)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1
for i in range(n):
    ans *= i + 1
    asn %= (10**9 + 7)
print(ans)


Fixed submission:
ans=1
n=int(input())
for i in range(1,n+1):
    ans*=i
    ans=ans%(10**9+7)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(n):
    ans *= i + 1
print(ans % (10**9 + 7))

Fixed submission:
ans=1
n=int(input())
for i in range(1,n+1):
    ans*=i
    ans=ans%(10**9+7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

res = 0
for x in range(k+1):
    for y in range(min(k+1, s-x+1)):
        for z in range(min(k+1, s-x-y+1)):
            if x+y+z == s:
                res += 1

print(res)

Fixed submission:
k, s = map(int, input().split())

res = 0
for x in range(k+1):
    for y in range(k+1):
        if x + y <= s:
            if x + y + k >= s:
                res += 1
        else:
            break

print(res)

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

res = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                res += 1

print(res)

Fixed submission:
k, s = map(int, input().split())

res = 0
for x in range(k+1):
    for y in range(k+1):
        if x + y <= s:
            if x + y + k >= s:
                res += 1
        else:
            break

print(res)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
d = abs(abs(y) - abs(x))
if x // abs(x) == y // abs(y):
    if x > y:
        d += 2
else:
    d += 1

print(d)


Fixed submission:
x, y = map(int, input().split())

d = abs(abs(y) - abs(x))

if (x > 0 and y <= 0) or (x >= 0 and y < 0) or (x < 0 and y > 0):
    d += 1
elif x > y:
    d += 2

print(d)
Buggy python submission (verdict: Time Limit Exceeded):
T = input()
L = len(T)
if T[0] is "?" and L > 1 :
    if T[1] is "D":
        T = 'P' + T[1:]
    else:
        T = 'D' + T[1:]
if T[L-1] is "?":
    T = T[:L-1] + 'D'
for i in range(1,L):
    if T[i] is "?":
        if T[i-1] is "P":
            T = T[:i] + 'D' + T[i+1:]
        elif T[i-1] is "D":
            T = T[:i] + 'P' + T[i+1:]
print(T)

Fixed submission:
T = input()
L = len(T)
if T[0] is "?" and L > 1 :
    if T[1] is "D":
        T = 'P' + T[1:]
    else:
        T = 'D' + T[1:]
if T[L-1] is "?":
    T = T[:L-1] + 'D'
T = T.replace("P?", "PD")
T = T.replace("?P", "DP") 
T = T.replace("?","D")

print(T)

Buggy python submission (verdict: Time Limit Exceeded):
T = input()
L = len(T)
if T[0] is "?" and L > 1 :
    if T[1] is "D":
        T = 'P' + T[1:]
    else:
        T = 'D' + T[1:]
if T[L-1] is "?":
    T = T[:L-1] + 'D'
for i in range(1,L):
    if T[i] is "?":
        if T[i-1] is "P":
            T = T[:i] + 'D' + T[i+1:]
        elif T[i-1] is "D":
            T = T[:i] + 'P' + T[i+1:]
print(T)

Fixed submission:
T = input()
L = len(T)
if T[0] is "?" and L > 1 :
    if T[1] is "D":
        T = 'P' + T[1:]
    else:
        T = 'D' + T[1:]
if T[L-1] is "?":
    T = T[:L-1] + 'D'
T = T.replace("P?", "PD")
T = T.replace("?P", "DP") 
T = T.replace("?","D")

print(T)
Buggy python submission (verdict: Runtime Error):
A, B, N = map(int, input().split(" "))

ans = 0
count = 0
num = int(N / B)
array = list(range(N, B * num - 1,-1))
# array2 = list(i for i in range(B * num, -1, -B))
# array.extend(array2)
# print(array)
for x in array:
#     print(x)
    if count > 1000000:
        break
    xb = x / B
    if xb < 1 and ans != 0:
        count += 1
#         print("continue")
        continue
    floor = int(A*xb) - A * int(xb)
    if ans < floor:
#         print(x)
#         print(x,count)
        count = 0
        ans = floor
    count += 1
print(ans)

Fixed submission:
A, B, N = map(int, input().split(" "))
ans = 0
x = min(B-1,N)
floor = int(A*x/B) - A * int(x/B)
print(floor)

Buggy python submission (verdict: Runtime Error):
A, B, N = map(int, input().split(" "))

ans = 0
count = 0
num = int(N / B)
array = list(range(N, B * num,-1))
array.append(i for i in range(B * num, -1, -B))
# print(array
for x in range(N,0,-1):
    if count > 1000000:
        break
    xb = x / B
    if xb < 1 and ans != 0:
        count += 1
#         print("continue")
        continue
    floor = int(A*xb) - A * int(xb)
    if ans < floor:
#         print(x)
#         print(x,count)
        count = 0
        ans = floor
    count += 1
print(ans)

Fixed submission:
A, B, N = map(int, input().split(" "))
ans = 0
x = min(B-1,N)
floor = int(A*x/B) - A * int(x/B)
print(floor)

Buggy python submission (verdict: Runtime Error):
A, B, N = map(int, input().split(" "))

ans = 0
count = 0
num = int(N / B)
array = list(range(N, B * num,-1))
array.append(i for i in range(B * num, -1, -B))
# print(array
for x in range(N,0,-1):
    if count > 1000000:
        break
    xb = x / B
    if xb < 1 and ans != 0:
        count += 1
#         print("continue")
        continue
    floor = int(A*xb) - A * int(xb)
    if ans < floor:
#         print(x)
#         print(x,count)
        count = 0
        ans = floor
    count += 1
print(ans)

Fixed submission:
A, B, N = map(int, input().split(" "))
ans = 0
x = min(B-1,N)
floor = int(A*x/B) - A * int(x/B)
print(floor)
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input()) + 1
ans = 0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            ab = math.gcd(a,b)
            part = math.gcd(ab,c)            
            ans += part
    
print(ans)

Fixed submission:
import math

K = int(input()) + 1
ans = 0
for a in range(1,K):
    for b in range(a,K):
        for c in range(b,K):
            ab = math.gcd(a,b)
            part = math.gcd(ab,c)
            if a == b or b == c:
                if not (a == b and b == c):
                    part = part * 3
            else:
                    part = part * 6                   
            ans += part
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=0
#     print(A)
    X = A[len(A)-1] - A[0]
#     print(X)
#     for i in range(0,len(A)-1): #i番目の家からスタート
#         X += A[i+1] - A[i]
#         if X > X_min:
#             i=0
#             break
#     if i == len(A)-2:
#     print(X)
    if X_min > X:
        X_min = X
    A=around(K,A)
#     print(X_min)
    
print(X_min)

Fixed submission:
K,N = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )

Buggy python submission (verdict: Runtime Error):
def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=
    X = A[len(A)-1] - A[0]
    if X_min > X:
        X_min = X
    A=around(K,A)
    
print(X_min)

Fixed submission:
K,N = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )

Buggy python submission (verdict: Time Limit Exceeded):
def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A  

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=0
    for i in range(0,len(A)-1): #i番目の家からスタート
        X += A[i+1] - A[i]
        if X > X_min:
            i=0
            break
    if i == len(A)-2:
        X_min = X
    A=around(K,A)
#     print(X_min)
    
print(X_min)

Fixed submission:
K,N = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )
Buggy python submission (verdict: Time Limit Exceeded):
import collections

def check(A,num):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            if j == num:
                n -= 1
#             print("{} {}".format(j,n))

            count += n * (n - 1) / 2
    return int(count)

N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
for i in range(0,N):
    num = A[i]
    out = check(A2,num)
    print(out)

Fixed submission:
import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

def check(A,num):
    count = 0
    for j in A:
        n = A[j]
        if j == num:
            n -= 1
#         print(n)
        count += n * (n - 1) / 2
    return int(count)
    

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

A2 = collections.Counter(A)
# print(A2)
for i in range(0,N):
    num = A[i]
    out = check(A2,num)
    print(out)

Fixed submission:
import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
def check(A,i):
    count = 0
    for j in range(0, N):
        if j != i:
            for k in range(j+1,N):
                if k != i:
                    if A[j] == A[k]:
                        count += 1
#                         print("{} {}".format(A[j],A[k]))
    return count
    

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

for i in range(0,N):
    out = check(A,i)
    print(out)

Fixed submission:
import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)