Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03196 (python)

Fixed submission:
from collections import Counter
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
prime = []
f = 2
while f**2 <=P:
    if P%f==0:
        prime.append(f)
        P//=f
    else:
        f += 1
if P != 1:
    prime.append(f)

ans = 1
for k,v in Counter(prime).items():
    if v//N:
        ans *= k**(v//N)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
for i in range(ceil(pow(P,1/N)),0,-1):
    if P%pow(i,N)==0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
for i in range(int(pow(P,1/N)//1)+1,0,-1):
    if P%pow(i,N)==0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
for i in range(int(pow(P,1/N)//1)+1,0,-1):
    if P%pow(i,N)==0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    raise ValueError
    exit()

for i in range(int(pow(P,1/N)//1),0,-1):
    if P%pow(i,N)==0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
for i in range((pow(P,1/N))//1,0,-1):
    if P%pow(i,N)==0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N,P =map(int,input().split(' '))
if N==1:
    print(P)
    exit()
for i in range((pow(P,1/N))//1,,0,-1):
    if P%pow(i,N)==0:
        print(i)
        break
Problem p03197 (python)

Fixed submission:
N = int(input())
for i in range(N):
    if int(input())%2 != 0:
        print("first")
        exit()
print('second')

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(N)
    if int(input())%2 != 0:
        print("first")
        exit()
print('second')
Problem p03229 (python)

Fixed submission:
from collections import deque
import copy
N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = copy.copy(A)
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))

Buggy submission (verdict: Runtime Error):
from collections import deque

N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = A.copy()
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))

Buggy submission (verdict: Runtime Error):
from collections import deque

N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = A.copy()
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))
Problem p03240 (python)

Fixed submission:
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
raise TypeError
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split(' '))
A = [list(map(int, input().split(' '))) for i in range(H)]
cnt = 0
ans = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 0:
            continue
        tmp = ''
        flg = True
        for x, y in [[1, 0], [0, 1]]:
            if 0 <= i+x < H and 0 <= j+y < W:
                if A[i+x][j+y] % 2 != 0:
                    A[i][j] -= 1
                    cnt += 1
                    A[i+x][j+y] += 1
                    ans.append([i, j, i+x, j+y])
                    flg = False
                    break
                else:
                    tmp = [x, y]
        if flg and tmp:
            cnt += 1
            A[i+tmp[0]][j+tmp[1]] += 1
            A[i][j] -= 1
            ans.append([i, j, i+tmp[0], j+tmp[1]])
print(cnt)
for i, j, k, l in ans:
    print(i+1, j+1, k+1, l+1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split(' '))
A = [list(map(int, input().split(' '))) for i in range(H)]
cnt = 0
ans = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 0:
            continue
        tmp = []
        flg = True
        for x, y in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
            if 0 <= i+x < H and 0 <= j+y < W:
                if A[i+x][j+y] % 2 != 0:
                    A[i][j] -= 1
                    cnt += 1
                    A[i+x][j+y] += 1
                    ans.append([i, j, i+x, j+y])
                    flg = False
                    break
                elif A[i][j] == 1:
                    tmp = [x, y]
                else:
                    flg = False
        if flg:
            cnt += 1
            A[tmp[0]][tmp[1]] += 1
            A[i][j] -= 1
            ans.append([i, j, i+tmp[0], j+tmp[1]])

print(cnt)
for i, j, k, l in ans:
    print(i+1, j+1, k+1, l+1)
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K <= tmp:
    print(1)
else:
    print(S[tmp])

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K >= tmp:
    print(1)
else:
    print(S[tmp])
Problem p03309 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split(' ')))
ans = float('inf')
l = []
for n,i in enumerate(A):
    l.append(i-n-1)
l = sorted(l)
for i in l[N//2-1:N//2+2]:
    tmp = 0
    for j in l:
        tmp += abs(j-i)
    ans = min(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().split(' ')))
ans = math.inf
l = []
for n,i in enumerate(A):
    l.append(i-n-1)
l = sorted(l)
for i in l[N//2-1:N//2+2]:
    tmp = 0
    for j in l:
        tmp += abs(j-i)
    ans = min(ans,tmp)
print(ans)
Problem p03323 (python)

Fixed submission:
A,B=map(int,input().split(' '))
if A<=8 and B <= 8:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().splti(' '))
if A<=8 and B <= 8:
    print('Yay!')
else:
    print(':(')
Problem p03341 (python)

Fixed submission:
N=int(input())
s=input()
tmp = 0
for i in s[1:]:
    if i == "E":
        tmp += 1
ans = tmp
for i in range(1,N):
    if s[i] =="W" and s[i-1]=="W":
        tmp += 1
    elif s[i]=="E" and s[i-1]=="E":
        tmp -=1
    ans = min(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
s=input()
ans = np.array([0]*N)
for n,i in enumerate(s):
    if i=="W":
        ans += np.array([0]*(n+1)+[1]*(N-n-1))
    else:
        ans += np.array([1]*(n+1)+[0]*(N-n-1))
print(min(ans))
Problem p03380 (python)

Fixed submission:
import sys

input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = 0
for i in A[:-1]:
    if abs(A[-1] // 2 - i) < tmp:
        tmp = abs(A[-1] // 2 - i)
        ans = i
    elif A[-1] % 2 != 0 and abs(A[-1] // 2 - i + 1) < tmp:
        tmp = abs(A[-1] // 2 - i + 1)
        ans = i
print(A[-1], ans)

Buggy submission (verdict: Runtime Error):
import sys
from scipy.special import comb
import bisect
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
l = bisect.bisect_left(A,A[-1]//2)-1
r = l+1
if comb(A[-1],A[l]) > comb(A[-1],A[r]):
    print(A[-1],A[l])
else:
    print(A[-1],A[r])
Problem p03393 (python)

Fixed submission:
S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            tmp =sorted(tmp)
            print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])
            exit()
    print(-1)

Buggy submission (verdict: Runtime Error):
S=input()
if len(S)<26:
    raise TypeError
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

Buggy submission (verdict: Runtime Error):
S=input()
if len(S)<26:
    raise TypeError:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)
Problem p03424 (python)

Fixed submission:
N=input()
s=len(set(list(input().split(' '))))
if s==4:
    print('Four')
else:
    print('Three')

Buggy submission (verdict: Runtime Error):
N=input()
s=list(map(int,input().split(' ')))
if len(set(s))==4:
    print('Four')
else:
    print('Three')
Problem p03436 (python)

Fixed submission:
from collections import deque
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
S[0][0]=1
next  = deque([[0,0]])
ans = H*W
while next:
    x,y =next.popleft()
    s = S[x][y]
    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+i<H and 0<=y+j<W and S[x+i][y+j]=='.':
            S[x+i][y+j]=s+1
            next.append([x+i,y+j])
for i in S:
    ans -=i.count('#')
if type(S[H-1][W-1])==str:
    print(-1)
else:
    print(ans-S[H-1][W-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
S[0][0]=1
next  = deque([[0,0]])
ans = H*W
while next:
    x,y =next.popleft()
    s = S[x][y]
    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+i<H and 0<=y+j<W and S[x+i][y+j]=='.':
            S[x+i][y+j]=s+1
            next.append([x+i,y+j])
for i in S:
    ans -=i.count('#')
print(ans-S[H-1][W-1])
Problem p03494 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split(' ')))
ans = []
for i in A:
    tmp = 0
    while i%2==0:
        tmp += 1
        i/=2
    ans.append(tmp)
print(min(ans))

Buggy submission (verdict: Runtime Error):
from sympy import factorint
n=int(input())
A=list(map(int,input().split(' ')))
ans = []
for i in A:
    tmp = factorint(i)
    ans.append(tmp[2])
print(min(ans))
Problem p03565 (python)

Fixed submission:
s_d=input()
t=input()
if len(s_d) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t):]
        break
if not flag:
    for i in range(len(s_d) - len(t), -1, -1):
        flag = True
        for j, k in zip(s_d[i:i + len(t)], t):
            if j != "?" and j != k:
                flag = False
                break
        if flag:
            s_d = s_d[:i] + t + s_d[i + len(t):]
            break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")

Buggy submission (verdict: Runtime Error):
s_d=input()
t=input()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != "?" and j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t)+1:]
        break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")
Problem p03575 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
def main():
    n,m=map(int,input().split(' '))
    graph=[[0 for i in range(n)] for j in range(n)]
    graph_del=[]
    ans = 0

    for i in range(m):
        e_1,e_2=map(int,input().split(' '))
        graph[e_1-1][e_2-1]=1
        graph[e_2-1][e_1-1]=1
        graph_del.append((e_1,e_2))

    for i,j in graph_del:
        graph[i-1][j-1]=0
        graph[j-1][i-1]=0
        if connected_components(np.array(graph),return_labels=False)!=1:
            ans += 1
        graph[i-1][j-1]=1
        graph[j-1][i-1]=1
    print(ans)




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M=map(int,input().split(' '))
q = [list(map(int,input().split(' '))) for i in range(M)]
ans = 0
for i in range(M):
    tmp = q[:i]+q[i+1:]
    uf = UnionFind(N)
    for j,k in tmp:
        uf.unite(j-1,k-1)
    for l in range(M):
        if uf.size(l) != N:
            ans += 1
            break
print(ans)
Problem p03593 (python)

Fixed submission:
from collections import Counter, defaultdict
H, W = map(int, input().split(' '))
d = defaultdict(int)
for i in range(H):
    for k, v in Counter(input()).items():
        d[k] += v
if H % 2 == 0 and W % 2 == 0:
    for i in d.values():
        if i % 4 != 0:
            print('No')
            exit()
    print('Yes')
elif H % 2 == 0 or W % 2 == 0:
    cnt = H//2 if not H % 2 else W//2
    for i in d.values():
        if i % 4 == 0:
            continue
        elif i % 2 == 0:
            cnt -= 1
            if cnt >= 0:
                continue
        print('No')
        exit()
    print('Yes')
else:
    odd = 1
    cnt = (H+W-2)//2
    for i in d.values():
        if i % 2 != 0 and odd:
            odd -= 1
            continue
        elif i % 4 == 0:
            continue
        elif i % 2 == 0 and cnt:
            cnt -= 1
            continue
        else:
            print('No')
            exit()
    print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
H, W = map(int, input().split(' '))
d = defaultdict(int)
for i in range(H):
    for k, v in Counter(input()).items():
        d[k] += v
if H % 2 == 0 and W % 2 == 0:
    for i in d.values():
        if i % 4 != 0:
            print('No')
            exit()
    print('Yes')
elif H % 2 == 0 or W % 2 == 0:
    cnt = H//2 if not H % 2 else W//2
    for i in d.values():
        if i % 4 == 0:
            continue
        elif i % 2 == 0:
            cnt -= 1
            if cnt >= 0:
                continue
        print('No')
        exit()
    print('Yes')
else:
    raise TypeError
    odd = 1
    cnt = H+W-1
    for i in d.values():
        if i % 2 != 0 and odd:
            odd -=1
            continue
        elif i % 4 == 0:
            continue
        elif i % 2 == 0 and cnt:
            cnt -= 1
            continue
        else:
            print('No')
            exit()
    print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
H, W = map(int, input().split(' '))
d = defaultdict(int)
for i in range(H):
    for k, v in Counter(input()).items():
        d[k] += v
if H % 2 == 0 and W % 2 == 0:
    for i in d.values():
        if i % 4 != 0:
            print('No')
            exit()
    print('Yes')
elif H % 2 == 0 or W % 2 == 0:
    raise TypeError
    cnt = H//2 if not H % 2 else W//2
    for i in d.values():
        if i % 4 == 0:
            continue
        elif i % 2 == 0:
            cnt -= 1
            if cnt >= 0:
                continue
        print('No')
        exit()
    print('Yes')
else:
    raise TypeError
    odd = 1
    cnt = H+W-1
    for i in d.values():
        if i % 2 != 0 and odd:
            odd -=1
            continue
        elif i % 4 == 0:
            continue
        elif i % 2 == 0 and cnt:
            cnt -= 1
            continue
        else:
            print('No')
            exit()
    print('Yes')
Problem p03612 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i<n-1 and i+1 == a[i] and i+2 ==a[i+1]:
        a[i],a[i+1]  = a[i+1],a[i]
        ans += 1
    if i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i+1 == a[i] and i+1 != a[i+1] and i <n:
        a[i],a[i+1] = a[i+1],a[i]
        ans += 1
    if  i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i+1 == a[i] and i+1 != a[i+1]:
        a[i],a[i+1] = a[i+1],a[i]
        ans += 1
    if  i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)
Problem p03659 (python)

Fixed submission:
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =abs(a[0]-sum(a[1:]))
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =math.inf
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()
Problem p03665 (python)

Fixed submission:
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
for i in A:
    if i%2 != 0:
        print(2**(N-1))
        exit()
if P ==0:
    print(2**N)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += comb(odd,i)
ans = ans*(2**even)
print(int(ans))
Problem p03696 (python)

Fixed submission:
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s):
        if n != len(s)-1 and i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
            break
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)

Buggy submission (verdict: Runtime Error):
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s[:-2]):
        if i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)

Buggy submission (verdict: Runtime Error):
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s):
        if n!=N-1 and  i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)
Problem p03786 (python)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
ans =1
for i in A[1:]:
    acc.append(acc[-1]+i)
for i in range(N-1,0,-1):
    if A[i]>acc[i-1]*2:
        print(N-i)
        exit()
print(N)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
for i in A[1:]:
    acc.append(A[-1]+i)
for i in range(N):
    if acc[i]*2<acc[i+1]:
        print(N-i-1)
        break
    elif i==N-1:
        print(1)
        break
Problem p03828 (python)

Fixed submission:
def power(x,y):
    if x%y != 0:
        return 0
    else:
        return 1+power(x/y,y)


def main():
    n = int(input())
    prime=[]
    fact = {}
    num_list = [i for i in range(2,n+1)]
    i = 0
    ans = 1
    if n ==1:
        print(ans)
        exit()
    mod = 10**9+7
    while i <=n**0.5:
        i = num_list.pop(0)
        prime.append(i)
        for j in num_list:
            if j%i ==0:
                num_list.remove(j)
    prime = prime + num_list

    for i in range(1,n+1):
        for j in prime:
            if i <j:
                break
            elif j in fact.keys():
                fact[j] += power(i,j)
            else:
                fact[j] = power(i,j)
    for i in fact.values():
        ans *= (i+1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def power(x,y):
    if x%y != 0:
        return 0
    else:
        return 1+power(x/y,y)


def main():
    n = int(input())
    prime=[]
    fact = {}
    num_list = [i for i in range(2,n+1)]
    i = 0
    ans = 1
    mod = 10**9+7
    while i <=n**0.5:
        i = num_list.pop(0)
        prime.append(i)
        for j in num_list:
            if j%i ==0:
                num_list.remove(j)
    prime = prime + num_list

    for i in range(1,n+1):
        for j in prime:
            if i <j:
                break
            elif j in fact.keys():
                fact[j] += power(i,j)
            else:
                fact[j] = power(i,j)
    for i in fact.values():
        ans *= (i+1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()
Problem p03838 (python)

Fixed submission:
A,B=map(int,input().split(' '))
print(min([i if i>0 else 10**10 for i in [B-A,A+B+1,-B+A+2,-B-A+1]]))

Buggy submission (verdict: Runtime Error):
from math import inf
A,B=map(int,input().split(' '))
print(min([i if i>0 else inf for i in [B-A,A+B+1,-B+A+2]]))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split(' '))
if A<=B:
    print(min(B-A,abs(B)-abs(A)))
elif A<0 or 0<B:
    raise TypeError
    print(A-B+2)
else:
    raise TypeError
    print(A+B+1)