Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
def gcd2(a, b, c):
	aa = math.gcd(a,b)
	return math.gcd(aa,c)

n=int(input())
N=list(range(1,n+1))
print(sum([gcd2(a,b,c) for a,b,c in [[a, b, c] for a in N for b in N for c in N]]))

Fixed submission:
import math

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

Buggy python submission (verdict: Runtime Error):
N = int(input())
 
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        tmp = math.gcd(a, b)
        for c in range(1, N + 1):
            ans += math.gcd(tmp, c)
 
print(ans)

Fixed submission:
import math

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

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a%b)

def gcd2(a, b, c):
	aa = gcd(a,b)
	return gcd(aa,c)

n=int(input())
N=list(range(1,n+1))
print(sum([gcd2(a,b,c) for a,b,c in [[a, b, c] for a in N for b in N for c in N]]))

Fixed submission:
import math

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

Buggy python submission (verdict: Runtime Error):
n=int(input())
N=list(range(1,n+1))
print(sum([gcd2(a,b,c) for a,b,c in [[a, b, c] for a in N for b in N for c in N]]))

Fixed submission:
import math

N = int(input())
 
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        tmp = math.gcd(a, b)
        for c in range(1, N + 1):
            ans += math.gcd(tmp, c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N= int(input())
S= input()
correct = ["RGB","RBG","GBR","GRB","BRG","BGR"]

cnt = 0
for i in range(N):
	for j in range(i+1,N):
		for k in range(j+1,N):
			if (j-i)!=(k-j):
				if "%s%s%s"%(S[i],S[j],S[k]) in correct:
					cnt+=1

print(cnt)
			

Fixed submission:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S={"R":[],"G":[],"B":[]}
for i,s in enumerate(input()):
	S[s].append(i)

lis = [[a,b,c] for a in S["R"] for b in S["G"] for c in S["B"]]
ans = 0
for i,j,k in lis:
	if i > k:
		tmp = k
		k = i
		i = tmp
	if j > k:
		tmp = k
		k = j
		j = tmp
	if i > j:
		tmp = j
		j = i
		i = tmp	
	if j-i!=k-j:
		ans+=1
print(ans)


Fixed submission:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S={"R":[],"G":[],"B":[]}
for i,s in enumerate(input()):
	S[s].append(i)

lis = [sorted([a, b, c]) for a in S["R"] for b in S["G"] for c in S["B"]]
ans = 0
for i,j,k in lis:
  if j-i!=k-j:
    ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S={"R":[],"G":[],"B":[]}
for i,s in enumerate(input()):
	S[s].append(i)

lis = [sorted([a, b, c]) for a in S["R"] for b in S["G"] for c in S["B"]]
print(len([1 for i,j,k in lis if j-i!=k-j]))

Fixed submission:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N= int(input())
S= [s for s in input()]
correct = ["RGB","RBG","GBR","GRB","BRG","BGR"]

cnt = 0
for i in range(N):
	for j in range(i+1,N):
		for k in range(j+1,N):
			if (j-i)!=(k-j):
				if "%s%s%s"%(S[i],S[j],S[k]) in correct:
					cnt+=1

print(cnt)
					



Fixed submission:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=list(map(int, input().split()))
ans = N
if N%K==0:
  print(0)
  exit()
while True:
    N = abs(N-K)
    if N < ans:
        ans=N
    elif N == ans or ans== 0:
        break
print(ans)

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

ans = N
if N%K==0 :
  print(0)
else:
  N = N%K
  while True:
      N = abs(N-K)
      if N < ans:
          ans=N
      elif N == ans or ans== 0:
          break
  print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
if 'AC' in N:
    print 'Yes'
else:
    print 'No'

Fixed submission:
S = raw_input()
print 'Yes' if 'AC' in S else 'No'
Buggy python submission (verdict: Runtime Error):
N=input()
brac = raw_input()
ans = brac

while '()' in brac:
	brac=brac.replace('()','')

left=brac.count('(')
right=brac.count(')')

print '('*right +ans +')'*left

Fixed submission:
if int(('').join(raw_input().split(' ')))%4==0:
	print('YES')
else:
	print('NO')
Buggy python submission (verdict: Runtime Error):
N=input()
a=raw_input().split(' ')
print(max(a)-min(a))

Fixed submission:
N=input()
a=[int(n) for n in raw_input().split(' ')]
print(max(a)-min(a))

Buggy python submission (verdict: Runtime Error):
a=raw_input().split(' ')
print(max(a)-min(a))

Fixed submission:
N=input()
a=[int(n) for n in raw_input().split(' ')]
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
N=input()
nlist= [int(l) for l in raw_input().split(' ')]

rate= [0,0,0,0,0,0,0]
max = 0
for n in nlist:
	if n/400>=8:
		max += 1
	else:
		rate[n/400]=1

print(sum(rate)),
if sum(rate)+max > 8:
	print(8)
else:
	print(sum(rate)+max)

Fixed submission:
N=input()
nlist= [int(l) for l in raw_input().split(' ')]

rate= [0,0,0,0,0,0,0,0]
up = 0
for n in nlist:
	if n/400>=8:
		up += 1
	else:
		rate[n/400]=1

print max(1,sum(rate)),sum(rate)+up

Buggy python submission (verdict: Runtime Error):
N=input()
nlist= [int(l) for l in raw_input().split(' ')]

rate= [0,0,0,0,0,0,0]
max = 0
for n in nlist:
	if n/400>=8:
		max += 1
	rate[n/400]=1

print(sum(rate)),
if sum(rate)+max > 8:
	print(8)
else:
	print(sum(rate)+max)

Fixed submission:
N=input()
nlist= [int(l) for l in raw_input().split(' ')]

rate= [0,0,0,0,0,0,0,0]
up = 0
for n in nlist:
	if n/400>=8:
		up += 1
	else:
		rate[n/400]=1

print max(1,sum(rate)),sum(rate)+up
Buggy python submission (verdict: Runtime Error):
N,A,B=map(lambda x:int(x) , raw_input().split(' '))
if A>B or N<2:
	print 0
elif A==B:
	print 1
else:
	li= range(0,B-A+2)[::-1]
        print li
	print sum(li[:N-2])

Fixed submission:
N,A,B=map(lambda x:int(x) , raw_input().split(' '))

if N==0:
	print 0
elif N==1:
	if A==B:
		print 1
	else:
		print 0
elif A>B:
	print 0
else:
	print (B-A)*(N-2)+1
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int, input().split()))
x = sum(A)/(4*m)
count = 0
for a in A:
    if a >= x:
        count += 1
if count >= m:
    print("Yes")
else:
    print("No")


Fixed submission:
A = list(map(int, input().split()))
print(A[2], A[0], A[1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
print(min(N%K, K(N%K)))


Fixed submission:
N, K = map(int, input().split())
print(min(N%K, K-(N%K)))
Buggy python submission (verdict: Runtime Error):
distances = [int(input()) in _ for range(5)]
K = int(input())

if distances[-1] - distances[0] > K:
  print(":(")
else:
  print("Yay!")
  

Fixed submission:
distances = [int(input()) for _ in range(5)]
K = int(input())
 
if distances[-1] - distances[0] > K:
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

for x in food:
    if (10 - (x % 10) > compare) and ((x % 10) != 0):
        largest = x
        compare = 10 - (x % 10)

food.remove(largest)

for i in range(len(food)):
    if food[i] % 10 != 0:
        total += round(food[i] + 5.1, -1)
    else:
        total += food[i]

print(int(total+largest))


Fixed submission:
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

if sum(food)%10 == 0:
    print(sum(food))

else:
    for x in food:
        if (10 - (x % 10) > compare) and ((x % 10) != 0):
            largest = x
            compare = 10 - (x % 10)

    food.remove(largest)

    for i in range(len(food)):
        if food[i] % 10 != 0:
            total += round(food[i] + 5.1, -1)
        else:
            total += food[i]

    print(int(total+largest))

Buggy python submission (verdict: Runtime Error):
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

for x in food:
    if (10 - (x % 10) > compare) and ((x % 10) != 0):
        largest = x
        compare = 10 - (x % 10)

food.remove(largest)
print(largest)

for i in range(len(food)):
    if food[i] % 10 != 0:
        total += round(food[i] + 5.1, -1)
    else:
        total += food[i]

print(int(total+largest))


Fixed submission:
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

if sum(food)%10 == 0:
    print(sum(food))

else:
    for x in food:
        if (10 - (x % 10) > compare) and ((x % 10) != 0):
            largest = x
            compare = 10 - (x % 10)

    food.remove(largest)

    for i in range(len(food)):
        if food[i] % 10 != 0:
            total += round(food[i] + 5.1, -1)
        else:
            total += food[i]

    print(int(total+largest))

Buggy python submission (verdict: Runtime Error):
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

for x in food:
    if (10 - (x % 10) and (x % 10) != 0) > compare:
        largest = x
food.remove(largest)

for i in range(len(food)):
    if food[i] % 10 != 0:
        total += round(food[i] + 5.1, -1)
    else:
        total += food[i]
print(int(total+largest))


Fixed submission:
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

if sum(food)%10 == 0:
    print(sum(food))

else:
    for x in food:
        if (10 - (x % 10) > compare) and ((x % 10) != 0):
            largest = x
            compare = 10 - (x % 10)

    food.remove(largest)

    for i in range(len(food)):
        if food[i] % 10 != 0:
            total += round(food[i] + 5.1, -1)
        else:
            total += food[i]

    print(int(total+largest))
Buggy python submission (verdict: Runtime Error):
X,Y = map(int, input().split())
print(int(X+(Y/2))

Fixed submission:
X,Y = map(int, input().split())
print(int(X+(Y/2)))
Buggy python submission (verdict: Runtime Error):
N = input()
if (N = N[::-1]):
    print('Yes')
else:
    print('No')


Fixed submission:
N = input()
if (N == N[::-1]):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s=input()

for e in s:
  if e="7":
    print("Yes")
    break
else:
  print("No")

Fixed submission:
s=input()

for e in s:
  if e=="7":
    print("Yes")
    break
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A == B:
    print('Yes')
else:
    print('No')

Fixed submission:
A, B = map(int, input().split())
if A == B:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

from math import gcd # Python versions 3.5 and above
from functools import reduce # Python version 3.x


def lcm(a, b):
    return (a * b) // gcd(a, b)

# def lcm(denominators):
#     return reduce(lambda a,b: a*b // gcd(a,b), denominators)

res = reduce(lcm, A, 1)
# res = lcm(A)
print(sum(res // A[i] for i in range(N)) % (10 ** 9 + 7))

Fixed submission:

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

# from math import gcd # Python versions 3.5 and above
from functools import reduce # Python version 3.x


def computeGCD(x, y):
    while (y):
        x, y = y, x % y
    
    return x

def lcm(a, b):
    return (a * b) // computeGCD(a, b)

# def lcm(denominators):
#     return reduce(lambda a,b: a*b // gcd(a,b), denominators)

res = reduce(lcm, A, 1)
# res = lcm(A)
print(sum(res // A[i] for i in range(N)) % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):

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

from math import gcd # Python versions 3.5 and above
from functools import reduce # Python version 3.x

def lcm(denominators):
    return reduce(lambda a,b: a*b // gcd(a,b), denominators)

res = lcm(A)
print(sum(res // A[i] for i in range(N)) % (10 ** 9 + 7))

Fixed submission:

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

# from math import gcd # Python versions 3.5 and above
from functools import reduce # Python version 3.x


def computeGCD(x, y):
    while (y):
        x, y = y, x % y
    
    return x

def lcm(a, b):
    return (a * b) // computeGCD(a, b)

# def lcm(denominators):
#     return reduce(lambda a,b: a*b // gcd(a,b), denominators)

res = reduce(lcm, A, 1)
# res = lcm(A)
print(sum(res // A[i] for i in range(N)) % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
import collections
A, B = [int(x) for x in raw_input().split(' ')]
def reduceNum(n):
    res = collections.Counter()
    res[1] = 1
    while n != 1:
        for index in range(2, int(n + 1)):
            while n % index == 0:
                n /= index
                res[index] += 1
    return res
sa = reduceNum(A)
sb = reduceNum(B)
be = sa & sb
print(len(be))

Fixed submission:
from fractions import gcd
d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    r += d % i == 0
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))
Buggy python submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))

Buggy python submission (verdict: Runtime Error):
import heapq
N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for _ in xrange(M):
    cur = -(-heapq.heappop(A) // 2)
    heapq.heappush(A, cur)
print(-sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))

Buggy python submission (verdict: Runtime Error):
import heapq
N, M = map(int, input().split())
A = map(int, input().split())
A = [-x for x in A]
heapq.heapify(A)
for _ in xrange(M):
    cur = -(-heapq.heappop(A) // 2)
    heapq.heappush(A, cur)
print(-sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
t = raw_input()
p, e, n = 0, 1, len(s)
ss = set(s)
for tt in t:
    q = p % n
    if not tt in ss:
        e = 0
        break
    if tt in s[q:]: p += s[q:].index(tt) + 1 
    else:   p += s.index(tt) + len(s[q:]) + 1
print((p+1)*e-1)

Fixed submission:
import sys
import collections
import bisect
s = raw_input()
t = raw_input()
p, e, n = 0, 1, len(s)
ss = set(s)
idx = collections.defaultdict(list)
for i in xrange(n):
    idx[s[i]].append(i)
# print(idx)
for tt in t:
    q = p % n
    if not tt in idx:
        e = 0
        break
    indexs = idx[tt]
    # print(bisect.bisect(indexs, q), indexs)
    res = bisect.bisect_left(indexs, q)
    p += indexs[res] - q + 1 if res < len(indexs) else -q + n + indexs[0] + 1
print((p+1)*e-1)
Buggy python submission (verdict: Runtime Error):
s = raw_input()
N = len(s)
if N == 1:
    print(1)
    exit()
dp = [[0] * 3 for _ in xrange(N)]
dp[0][1] = 1
dp[1][2] = 0
dp[1][1] = 0 if s[1] == s[0] else 2
for i in xrange(2, N):
    if dp[i-1][2]:
        dp[i][1] = max(dp[i][1], dp[i - 1][2] + 1)
    if dp[i-1][1] and s[i] != s[i-1]:
        dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1)
    if dp[i-2][1]:
        dp[i][2] = dp[i-2][1]+1
    if i >= 3 and (s[i-2-1]!=s[i-1] or s[i-2]!=s[i]) and dp[i-2][2]:
        dp[i][2] = max(dp[i][2], dp[i-2][2]+1)
print(max(dp[N-1][1], dp[N-1][2]))

Fixed submission:
s = raw_input()
N = len(s)
s = '0' + s
dp = [0] * (1+N)
# dp[0] = 1
for i in xrange(1, N+1):
    if s[i] == s[i-1]:  dp[i] = dp[i-3]+2 if i >= 3 else 1
    else:   dp[i] = dp[i-1] + 1
print(dp[N])
Buggy python submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split(' ')]
edges = []
for _ in range(M):
    edges.append([int(x) - 1 for x in input().split(' ')])
res = [str(N * (N-1) // 2)]
init = N * (N-1) // 2
f = list(range(N))
cnt = [1] * N
def find(x):
    if x != f[x]:
        f[x] = find(f[x])
    return f[x]
for i in range(M-1, 0, -1):
    a, b = edges[i]
    fx, fy = find(a), find(b)
    if fx == fy:
        res.append(str(init))
    else:
        f[fy] = fx
        pre = cnt[fx] * (cnt[fx] - 1) // 2 + cnt[fy] * (cnt[fy] - 1) // 2
        cnt[fx] += cnt[fy]
        # print(a, b, f, cnt)
        init = init - cnt[fx] * (cnt[fx]-1) // 2 + pre
        res.append(str(init))
print('\n'.join(res[::-1]))

Fixed submission:
N, M = [int(x) for x in input().split(' ')]
edges = []
for _ in range(M):
    edges.append([int(x)-1 for x in input().split(' ')])
res = [str(N * (N-1) // 2)]
init = N * (N-1) // 2
f = list(range(N))
cnt = [1] * N
def find(x):
    if x != f[x]:
        f[x] = find(f[x])
    return f[x]
for i in range(M-1, 0, -1):
    a, b = edges[i]
    fx, fy = find(a), find(b)
    if fx == fy:
        res.append(str(init))
    else:
        
        pre = cnt[fx] * (cnt[fx] - 1) // 2 + cnt[fy] * (cnt[fy] - 1) // 2
        if cnt[fx] < cnt[fy]:
            f[fx] = fy
            cnt[fy] += cnt[fx]
            init = init - cnt[fy] * (cnt[fy]-1) // 2 + pre
        else:
            f[fy] = fx
            cnt[fx] += cnt[fy]
            init = init - cnt[fx] * (cnt[fx] - 1) // 2 + pre
        res.append(str(init))
print('\n'.join(res[::-1]))

Buggy python submission (verdict: Runtime Error):
N, M = [int(x) for x in raw_input().split(' ')]
edges = []
for _ in range(M):
    edges.append([int(x) - 1 for x in raw_input().split(' ')])
res = [str(N * (N-1) / 2)]
init = N * (N-1) / 2
f = range(N)
cnt = [1] * N
def find(x):
    if x != f[x]:
        f[x] = find(f[x])
    return f[x]
for i in range(M-1, 0, -1):
    a, b = edges[i]
    fx, fy = find(a), find(b)
    if fx == fy:
        res.append(str(init))
    else:
        f[fy] = fx
        pre = cnt[fx] * (cnt[fx] - 1) / 2 + cnt[fy] * (cnt[fy] - 1) / 2
        cnt[fx] += cnt[fy]
        # print(a, b, f, cnt)
        init = init - cnt[fx] * (cnt[fx]-1) / 2 + pre
        res.append(str(init))
print('\n'.join(res[::-1]))


Fixed submission:
N, M = [int(x) for x in input().split(' ')]
edges = []
for _ in range(M):
    edges.append([int(x)-1 for x in input().split(' ')])
res = [str(N * (N-1) // 2)]
init = N * (N-1) // 2
f = list(range(N))
cnt = [1] * N
def find(x):
    if x != f[x]:
        f[x] = find(f[x])
    return f[x]
for i in range(M-1, 0, -1):
    a, b = edges[i]
    fx, fy = find(a), find(b)
    if fx == fy:
        res.append(str(init))
    else:
        
        pre = cnt[fx] * (cnt[fx] - 1) // 2 + cnt[fy] * (cnt[fy] - 1) // 2
        if cnt[fx] < cnt[fy]:
            f[fx] = fy
            cnt[fy] += cnt[fx]
            init = init - cnt[fy] * (cnt[fy]-1) // 2 + pre
        else:
            f[fy] = fx
            cnt[fx] += cnt[fy]
            init = init - cnt[fx] * (cnt[fx] - 1) // 2 + pre
        res.append(str(init))
print('\n'.join(res[::-1]))
Buggy python submission (verdict: Runtime Error):
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
f = list(range(N))
costs = [0] * N
def find(x):
    if f[x] != x:
        f[x] = find(f[x])
    return f[x]
res = 0
for i, j, k in data:
    fi, fj = find(i), find(j)
    if fi == fj:
        continue
    else:
        f[fi] = fj
        res += k
print(res)

Fixed submission:
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
f = list(range(N))
costs = [1] * N
def find(x):
    if f[x] != x:
        f[x] = find(f[x])
    return f[x]
res = 0
for i, j, k in data:
    fi, fj = find(i), find(j)
    if fi == fj:
        continue
    else:
        if costs[fi] <= costs[fj]:
            f[fi] = fj
            costs[fj] += costs[fi]
            res += k
        else:
            f[fj] = fi
            costs[fi] += costs[fj]
            res += k
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n + 1):
    if i == 0: continue
    ans.append(a.count(i))

for i in range(n):
    print(ans[i])


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = []
sp = 0
c = 0
for i in range(n + 1):
    if i == 0: continue
    for j in range(sp, n - 1):
        if a[j] != i:
            break
        sp += 1
        c += 1
    ans.append(c)
    c = 0

for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
import sys
from operator import itemgetter
import collections

def r(n, p):
  m = n + 1
  count = 0
  for i in range(n):
    m = min(p[i], m)
    if m == p[i]:
      count += 1
  return count

def main():
    input = sys.stdin.readline
    n = int(input())
    p = map(int, input().split())
    print(r(n,p))

    
if __name__ == '__main__':
    main()


Fixed submission:
import sys
from operator import itemgetter
import collections

def r(n, p):
  m = n + 1
  count = 0
  for i in range(n):
    m = min([p[i], m])
    if m == p[i]:
      count += 1
  return count

def main():
    input = sys.stdin.readline
    n = int(input())
    p = list(map(int, input().split()))
    print(r(n,p))

    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections


def r(n, ab):

    s = [(x[0] + x[1])/2 for x in ab]
    
    scr = 0
    sente = True
    for _ in range(n):
        i = s.index(max(s))
        if sente:
            scr += ab[i][0]
        else:
            scr -= ab[i][1]
        del ab[i]
        del s[i]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from operator import itemgetter


def r(n, ab):

    ss = [x + [x[0] + x[1]] for x in ab]
    ss.sort(key=itemgetter(2), reverse=True)
    
    scr = 0
    sente = True
    for s in ss:
        if sente:
            scr += s[0]
        else:
            scr -= s[1]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()