Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

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

print(seed)

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

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

print(seed)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

seed = h[0]
for i in range(0,n-k+1):
    high = h[i:i+k][0] - h[i:i+k][k-1]
    if seed > high:
        seed = high

print(seed)

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

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

print(seed)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

seed = max(h)
for i in range(0,n-k+1):
    high = max(h[i:i+k]) - min(h[i:i+k])
    if seed > high:
        seed = high

print(seed)

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

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

print(seed)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
ans = max(h) - min(h)
h.sort(reverse=True)

h_n = []
for i in range(0,n):
    l = h[i:i+k]
    if len(l) == k:
        h_n.append(l)

seed = max(h)
for i in range(0,len(h_n)):
    high = max(h_n[i]) - min(h_n[i])
    if seed > high:
        seed = high

print(seed)

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

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

print(seed)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input())
if (a*b) % 2 != 0:
    print('Yes')
else:
    print('No')

Fixed submission:
a, b = map(int,input().split())
if (a*b) % 2 != 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

d = 0
c = []
for b in range(0,max(a)+1):
    for i in range(0,len(a)):
        d += abs(a[i]-(b+i+1))
    c.append(d)
    d = 0
print(min(c))

Fixed submission:
n = int(input())
if n % 2 != 0:
    print(n*2)
else:
    print(n)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

d = 0
c = []
for b in range(-max(a),min(a)+1):
    for i in range(0,len(a)):
        d += abs(a[i]-(b+i+1))
    c.append(d)
    d = 0
print(min(c))

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

b_l = []
for i in range(0,len(a)):
    b_l.append(a[i] - (i+1))
b_l.sort()
b = b_l[n//2]
ans = 0
for i in range(0,len(a)):
    ans += abs(a[i] - (i+1+b))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

d = 0
c = []
for b in range(-max(a),max(a)+1):
    for i in range(0,len(a)):
        d += abs(a[i]-(b+i+1))
    c.append(d)
    d = 0
print(min(c))

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

b_l = []
for i in range(0,len(a)):
    b_l.append(a[i] - (i+1))
b_l.sort()
b = b_l[n//2]
ans = 0
for i in range(0,len(a)):
    ans += abs(a[i] - (i+1+b))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]

x = 0
y = 0
for i in range(n):
    t = l[i][0]
    x = l[i][1]
    y = l[i][2]
    d = x + y
    if d <= t and (d - t) % 2 == 0:
        continue
    else:
        print('No')
        quit()
print('Yes')


Fixed submission:
a, b = map(int,input().split())
if a*b % 2 != 0:
  print('Odd')
else:
  print('Even')
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
L = a + b
R = c + d
if L > R:
    print('Left')
elif L == R:
    print('balanced')
else L < R:
    print('Right')

Fixed submission:
a, b, c, d = map(int, input().split())
l = a + b
r = c + d
if l > r:
	print ("Left")
elif l == r:
	print ("Balanced")
else:
	print ("Right")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a = list(map(int,input().split()))

aset = set(a)
count = []
n = len(aset)
for i in aset:
    count.append([i,a.count(i)])
if n <= k:
    print(0)
else:
    c = n - k
    count.sort(key=lambda x: x[1])
    ans = 0
    for i in range(c):
        ans += count[i][1]
    print(ans)

Fixed submission:
n, k = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
count = []
c = 1
for i in range(n-1):
    if a[i] != a[i+1]:
        count.append(c)
        c = 1
    else:
        c += 1
    if i == n - 2:
        count.append(c)

l = len(count)
#print(a)
#print(count)
c = 0
if l <= k:
    print(0)
else:
    count.sort()
    for i in range(l):
        l -= 1
        c += count[i]
        if l <= k:
            print(c)
            quit()
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,b+1):
        ans *= (i%mod)
        ans %= mod
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print((2*ans)%mod)

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

if a >= b:
    print('delicious')
elif b - a < x+1:
    print('safe')
else:
    print('dangerous')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)

    for i in range(1,b+1):
        ans *= (i%mod)
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= (i%mod)
    for i in range(1,n+1):
        ans *= (i%mod)
    print((2*ans)%mod)

Fixed submission:
n, m = map(int,input().split())

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,b+1):
        ans *= (i%mod)
        ans %= mod
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    print((2*ans)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, c = map(int,input().split())

for i in range(10**7):
    n = a * i
    if n % b == c:
        print('YES')
        quit()
print('NO')

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

for i in range(b):
    n = a * i
    if n % b == c:
        print('YES')
        quit()
print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Fixed submission:
a, b = map(int,input().split())
print((a+b)%24)
Buggy python submission (verdict: Runtime Error):
 n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Fixed submission:
n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ele = []
i = 1
while i * i < n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = min(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Fixed submission:
n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ele = []
ans = []
i = 1
while i * i < n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
        ans.append([i,n//i])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Fixed submission:
n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)
Buggy python submission (verdict: Runtime Error):
import statistics
n = int(input())
a = list(map(int,input().split()))

mean = round(statistics.mean(a))

ans = 0
for i in range(n):
    ans += (a[i]-mean)**2

print(ans)

Fixed submission:
import statistics
n = int(input())
a = list(map(int,input().split()))

mean = round(statistics.mean(a))

ans = 0
for i in range(n):
    ans += (a[i]-mean)**2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
P = [int(x)-1 for x in input().split()]
C = [int(x) for x in input().split()]

def loop(s):
    value = 0
    done = set()
    while s not in done:
        done.add(s)
        s = P[s]
        value += C[s]
    return len(done), value

def f(s,K):
    ans = -10**18
    total = 0
    done = set()
    while s not in done:
        done.add(s)
        s = P[s]
        total += C[s]
        ans = max(ans,total)
        K -= 1

        if K==0:
            return ans

    lamb, value = loop(s)

    if K > 2*lamb:
        K -= lamb
        if value > 0:
            total += (K//lamb)*value
            ans = max(ans,total)
            K -= (K//lamb)*lamb
        K += lamb

    while K > 0:
        s = P[s]
        total += C[s]
        ans = max(ans,total)
        K -= 1
    return ans

print(max([f(s,K) for s in range(N)]))

Fixed submission:
N, K = map(int,input().split())
P = [int(x)-1 for x in input().split()]
C = [int(x) for x in input().split()]

def loop(s):
    value = 0
    done = set()
    while s not in done:
        done.add(s)
        s = P[s]
        value += C[s]
    return len(done), value

def f(s,K):
    ans = -10**18
    total = 0
    done = set()
    while s not in done:
        done.add(s)
        s = P[s]
        total += C[s]
        ans = max(ans,total)
        K -= 1

        if K==0:
            return ans

    lamb, value = loop(s)

    if K > 2*lamb:
        if value > 0:
            K -= lamb
            total += (K//lamb)*value
            ans = max(ans,total)
            K -= (K//lamb)*lamb
            K += lamb
    if value <= 0:
        K = min(K,lamb+5)
        


    while K > 0:
        s = P[s]
        total += C[s]
        ans = max(ans,total)
        K -= 1
    return ans

print(max([f(s,K) for s in range(N)]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
freq = [0 for i in range(10**5)]
for x in A:
    freq[x] += 1
ans = sum(A)
for q in range(int(input())):
    B, C = map(int,input().split())
    ans -= B*freq[B]
    ans += C*freq[B]
    freq[C] += freq[B]
    freq[B] = 0
    print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
freq = [0 for i in range(10**5+1)]
for x in A:
    freq[x] += 1
ans = sum(A)
for q in range(int(input())):
    B, C = map(int,input().split())
    ans -= B*freq[B]
    ans += C*freq[B]
    freq[C] += freq[B]
    freq[B] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
	ans *= x
print(-1 if ans > 10**18 else ans)

Fixed submission:
N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
	ans *= x
	if ans > 10**18:
		ans = 10**18+1
print(-1 if ans > 10**18 else ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(3*10**5)

N, M = map(int,input().split())
adj = [[] for i in range(N+1)]
for i in range(M):
	u, v, w = map(int,input().split())
	adj[u].append(v)
	adj[v].append(u)

vis = [False for i in range(N+1)]
def dfs(u):
	if vis[u]:
		return
	vis[u] = True
	for v in adj[u]:
		dfs(v)

ans = 0
for u in range(1,N+1):
	if not vis[u]:
		ans += 1
		dfs(u)

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(3*10**5)

N, M = map(int,input().split())
adj = [[] for i in range(N+1)]
for i in range(M):
	u, v, w = map(int,input().split())
	adj[u].append(v)
	adj[v].append(u)

vis = [False for i in range(N+1)]
def bfs(s):
	frontier = [s]
	ptr = 0
	while ptr < len(frontier):
		u = frontier[ptr]
		if not vis[u]:
			vis[u] = True
			for v in adj[u]:
				if not vis[v]:
					frontier.append(v)
		ptr += 1
ans = 0
for u in range(1,N+1):
	if not vis[u]:
		ans += 1
		bfs(u)

print(ans)
Buggy python submission (verdict: Runtime Error):
def conv(c): return '+' if c==1 else '-'
def main():
	num = [int(c) for c in input()]
	choices = [-1,1]
    for a in choices:
		for b in choices:
			for c in choices:
				if num[0]+num[1]*a+num[2]*b+num[3]*c==7:
					print("{}{}{}{}{}{}{}=7".format(num[0],conv(a),num[1],conv(b),num[2],conv(c),num[3]))
                    return
main()


Fixed submission:
def conv(c): return '+' if c==1 else '-'
def main():
	num = [int(c) for c in input()]
	choices = [-1,1]
	for a in choices:
		for b in choices:
			for c in choices:
				if num[0]+num[1]*a+num[2]*b+num[3]*c==7:
					print("{}{}{}{}{}{}{}=7".format(num[0],conv(a),num[1],conv(b),num[2],conv(c),num[3]))
					return
main()
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

num = 10**10

for i in range(len(S)-len(T)+1):
    U = S[i:(i+len(T))]
    for j in range(len(T)):
        if(T[j] != S[j]):
            tmp += 1
    num = min(num, tmp)
    
print(num)

Fixed submission:
S = input()
T = input()

num = 10**10

for i in range(len(S)-len(T)+1):
    U = S[i:(i+len(T))]
    tmp = 0
    for j in range(len(T)):
        if(T[j] != U[j]):
            tmp += 1
    num = min(num, tmp)
    
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

tmp = 1
for i in range(K):
    tmp *= A[i]
tmp1 = tmp
idx = 0
for i in range(K, N):
    tmp1 *= A[i]
    tmp1 = tmp1//A[idx]
    if(tmp1 > tmp):
        print("Yes")
        tmp = tmp1
        idx += 1
    else:
        print("No")
        tmp = tmp1
        idx += 1

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

idx = 0
for i in range(K, N):
    if(A[idx] < A[i]):
        print("Yes")
    else:
        print("No")
    idx += 1
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
cnt = 0
lb = len(b)-1
for i in range(len(a)):
    cnt = a[i]
    if(cnt > K):
        break
    for j in reversed(range(lb)):
        tmp = cnt + b[j]
        if(tmp > K):
            lb = j
        else:
            ans = max(i+j, ans)
            break

print(ans)

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

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
lb = len(b)
j = len(b)-1
for i in range(len(a)):
    if(a[i] > K):
        break
    while(a[i]+b[j] > K):
        j -= 1
    ans = max(ans, i+j)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def func(n):
    div = 0 
    for i in range(1, int(n**0.5)+1):
        if(n%i == 0):
            div += 1
            if(i != n //i):
                div += 1
    return div

def main():
    N = int(input())

    ans = 0
    for i in range(1, N+1):
        ans += i*func(i)
    print(ans)
main()

Fixed submission:
N = int(input())

ans = 0

for i in range(1, N+1):
    y = N//i
    ans += ((y*(y+1))//2)*i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def func(n):
    divisors = [] 
    for i in range(1, int(n**0.5)+1):
        if(n%i == 0):
            divisors.append(i)
            if(i != n //i):
                divisors.append(n//i)
    return len(divisors)

N = int(input())

ans = 0
for i in range(1, N+1):
    ans += i*func(i)
print(ans)

Fixed submission:
N = int(input())

ans = 0

for i in range(1, N+1):
    y = N//i
    ans += ((y*(y+1))//2)*i
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
d = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", \
     9:"i", 10:"j", 11:"k", 12:"l", 13:"m", 14:"n", 15:"o", 16:"p", 17:"q", \
      18:"r", 19:"s", 20:"t", 21:"u", 22:"v", 23:"w", 24:"x", 25:"y", 26:"z"}

def Base_10_to_n(X, n):
    if(int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)+","
    return str(X%n)+","

a = Base_10_to_n(N, 26)
a = list(a.split(","))
ans = ""

for i in a:
    if(i == ""):
        continue
    ans += d[int(i)]        
print(ans)

Fixed submission:
from collections import defaultdict

d = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", \
     9:"i", 10:"j", 11:"k", 12:"l", 13:"m", 14:"n", 15:"o", 16:"p", 17:"q", \
      18:"r", 19:"s", 20:"t", 21:"u", 22:"v", 23:"w", 24:"x", 25:"y", 0:"z"}

N = int(input())
n = N
ans = ""

while n > 0:
    x = n%26
    ans += d[x]
    if(x == 0):
        n = n//26-1
    else:
        n //= 26

print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
nA = np.array(A)

cnt = 0
for i in range(N):
    tmp = len(nA[A[i]%nA == 0]) 
    if(tmp == 1):
        cnt += 1    
print(cnt)

Fixed submission:
from collections import Counter

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

prime = [0 for i in range(ma)]

for a in A:
    for j in range(a, ma+1, a):
        prime[j-1] += 1

cnt = 0
for i in A:
    if(prime[i-1] == 1):
        cnt += 1
       
print(cnt)
Buggy python submission (verdict: Runtime Error):
import decimal
N = int(input())
A = list(input().split())

ans = 1
for i in range(len(A)):
    ans *= decimal.Decimal(A[i])
    
if(len(str(ans)) >= 18):
    print(-1)
else:
    print(ans)

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

aa = set(A)
ans = 1
for i in range(len(A)):
    if(ans > 10**18):
        if(0 not in aa):
            ans = -1
            break
        else:
            ans = 0
    ans *= A[i]

if(ans > 10**18):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
T = input()

ans = ""
for i in range(len(T)):
    if(T[i] == "P" or T[i] == "D"):
        ans += T[i]
    elif(i != 0 and ans[i-1] == "P"):
        ans += "D"
    elif(i != len(T)-1 and T[i+1] == "?"):
        ans += "P"
    elif(i != len(T)-1 and T[i+1] == "D"):
        ans += "P"

print(ans)

Fixed submission:
T = input()

ans = ""
for i in range(len(T)):
    if(T[i] == "?"):
        ans +="D"
    else:
        ans += T[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections 

N = int(input())
A = list(map(int, input().split()))
lst = []
c = collections.Counter(A)
for key in c:
    lst.append(key)
lst.sort()
cnt = 0
for i in range(1, N+1):
    if(i in lst):
        print(c[i])
    else:
        print(0)

Fixed submission:
import collections 

N = int(input())
A = list(map(int, input().split()))
lst = set()
c = collections.Counter(A)
cnt = 0
for i in range(1, N+1):
    if(c[i] != 0):
        print(c[i])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main(): 
    N = int(input())
    A = list(map(int, input().split()))

    for i in range(N):
        ans = 0
        a = A[:i]+A[i+1:]
        C = collections.Counter(a)
        for v in C.values():
            ans += (v*(v-1))//2
        print(ans)
        
main()

Fixed submission:
import collections

def main(): 
    N = int(input())
    A = list(map(int, input().split()))
    cnt = [0]*(N+1)
    C = collections.Counter(A)
    
    for k, v in C.items():
        cnt[k] = v*(v-1)//2
    S = sum(cnt)
    
    for i in A:
        print(S - cnt[i] + (C[i]-1)*(C[i]-2)//2)
        
main()

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main(): 
    N = int(input())
    A = list(map(int, input().split()))

    for i in range(N):
        ans = 0
        a = A[:i]+A[i+1:]
        C = collections.Counter(a)
        for v in C.values():
            ans += (v*(v-1))//2
        print(ans)
        
main()

Fixed submission:
import collections

def main(): 
    N = int(input())
    A = list(map(int, input().split()))
    cnt = [0]*(N+1)
    C = collections.Counter(A)
    
    for k, v in C.items():
        cnt[k] = v*(v-1)//2
    S = sum(cnt)
    
    for i in A:
        print(S - cnt[i] + (C[i]-1)*(C[i]-2)//2)
        
main()

Buggy python submission (verdict: Time Limit Exceeded):
import collections 
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    ans = 0
    a = A[:i]+A[i+1:]
    C = collections.Counter(a)
    for v in C.values():
        ans += (v*(v-1))//2
    print(ans)

Fixed submission:
import collections

def main(): 
    N = int(input())
    A = list(map(int, input().split()))
    cnt = [0]*(N+1)
    C = collections.Counter(A)
    
    for k, v in C.items():
        cnt[k] = v*(v-1)//2
    S = sum(cnt)
    
    for i in A:
        print(S - cnt[i] + (C[i]-1)*(C[i]-2)//2)
        
main()
Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 10**6
for i in range(M):
    X, Y, C = map(int, input().split())
    if(ans > a[X-1]+b[Y-1]-C):
        ans = a[X-1]+b[Y-1]-C

for j in range(len(a)):
    for k in range(len(b)):
        if(a[j]+b[k] < ans):
            ans = a[j]+b[k]
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a)+min(b)
for i in range(M):
    X, Y, C = map(int, input().split())
    if(ans > a[X-1]+b[Y-1]-C):
        ans = a[X-1]+b[Y-1]-C

print(ans)