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

Fixed submission:
mod=10**9+7

N=int(input())
A=list(map(int,input().split()))
B=[0]
for x in A:
  B.append(B[-1]+x)

ans=0
for i in range(N):
  s=(B[N]-B[i+1])%mod
  ans+=A[i]*s
  ans%=mod

print(ans)

Buggy submission (verdict: Runtime Error):
MAX=101010
is_prime=[True]*MAX
is_prime[0]=False
is_prime[1]=False
for i in range(2,MAX):
  if is_prime[i]==False:
    continue
  for j in range(i*2,MAX,i):
    is_prime[j]=False

a=[0]*MAX
for i in range(MAX):
  if i%2==0:
    continue
  if is_prime[i] and is_prime[(i+1)//2]:
    a[i]=1

s=[0]
for x in a:
  s.append(s[-1]+x)

Q=int(input())
for _ in range(Q):
  l,r=map(int,input().split())
  print(s[r+1]-s[l])
Problem p02831 (python)

Fixed submission:
import fractions

def lcm(x,y):
  return (x*y)//fractions.gcd(x,y)

A,B=map(int,input().split())
print(lcm(A,B))

Buggy submission (verdict: Runtime Error):
import math

def lcm(x,y):
  return (x*y)//math.gcd(x,y)

A,B=map(int,input().split())
print(lcm(A,B))
Problem p03329 (python)

Fixed submission:
N=int(input())
ans=N
for i in range(N+1):
  cnt=0
  t=i
  while t>0:
    cnt+=t%6
    t//=6
  j=N-i
  while j>0:
    cnt+=j%9
    j//=9
  ans=min(ans,cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
dp=[0]*100000
a=1
b=6
c=9
for i in range(1,N+1):
  if i>=b*6:
    b*=6
  if i>=c*9:
    c*=9
  if i<6:
    dp[i]=i
  elif i<9:
    dp[i]=min(dp[i-a]+1,dp[i-b]+1)
  else:
    dp[i]=min([dp[i-a]+1,dp[i-b]+1,dp[i-c]+1])
print(dp[N])
Problem p03017 (python)

Fixed submission:
N, A, B, C, D =  map(int, input().split())
S = input()
S = [False] + [s == '.' for s in S] + [False]
def check(s, t):
    i = s
    for _ in range(s, t+1):
        if i + 1 == t or i + 2 == t:
            return True
        if S[i+2]:
            i += 2
            continue
        if S[i+1]:
            i += 1
            continue
        return False

def checki(s, t):
    for i in range(s, t+1):
        if S[i-1] and S[i] and S[i+1]:
            return True
    return False



if A < B < D < C:
    if not check(B, D) or not check(A, C):
        print('No')
    elif checki(B, D):
        print('Yes')
    else:
        print('No')
else:
    if check(A, C) and check(B, D):
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import sys
N, X = map(int, input().split())
BLU = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
B, L, U = map(list, zip(*BLU))
C = [(u-l)*b for b, l, u in BLU]
D = [(X*u - c, u, c, l) for u, c, l in zip(U, C, L)]
D.sort(reverse = True)
SL = sum(l*b for l, b in zip(L, B))
SS = 0
for i, (d, _, _, _) in enumerate(D):
    SS += d
    if SS >= SL:
        break
SSb = SS - d
lans = i*X
m = 10**10
for _, u, c, l in D[i:]:
    m = min(m, -(-(c + SL - SSb)//u), -((SSb - SL)//l))
lans += m

ans = (i+1) * X
m = 0
for _, u, _, _ in D[:i+1]:
    m = max(m, -(-(SS - SL))//u)
print(min(lans, ans - m))
Problem p03033 (python)

Fixed submission:
from heapq import heappop as hpp, heappush as hp
import sys
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx = [(s-x, t-x, x) for s, t, x in stx]
stx.sort(reverse = True)

D = [int(sys.stdin.readline()) for _ in range(Q)] 
H = []
ans = [None]*Q

for i, d in enumerate(D):
    while stx and stx[-1][0] <= d:
        hp(H, stx.pop()[1:][::-1])    
    while H and H[0][1] <= d:
        hpp(H)
    if not H:
        ans[i] = -1
    else:
        ans[i] = H[0][0]

for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl
import sys
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split()))[::-1] for _ in range(N)]

stx.sort()

D = [int(sys.stdin.readline()) for _ in range(Q)] 
A = [0]*Q
X = [0]*N
for i, (x, t, s) in enumerate(stx):
    il = bl(D, s-x)
    ir = bl(D, t-x)
    A[il] += 2**i
    A[ir] += 2**i
    X[i] = x
for i in range(1, Q):
    A[i] = A[i]^A[i-1]
for a in A:
    if not a:
        print(-1)
    else:
        print(X[(a & -a).bit_length() - 1])
Problem p03034 (python)

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

ans = 0
for c in range(1, N):
    a = 0
    if (N-1) % c:
        for i in range(1, (N-1)//c):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
    else:
        se = set(list(range(N)))
        for i in range(1, (N-1)//c):
            if i*c not in se or N-1-i*c not in se or i*c == N-1-i*c:
                break
            se.remove(i*c)
            se.remove(N-1-i*c)
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int, input().split()))

ans = 0
for c in range(N):
    a = 0
    if (N-1) % c:
        for i in range(1, (N-1)//c):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
    else:
        for i in range(1, (N-1)//(2*c)):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
print(ans)
Problem p03053 (python)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
G = [input() for _ in range(H)]
dist = [0]*(H*W)
bn = 0
B = deque()
geta = W
for i, g in enumerate(G):
    for j, f in enumerate(g):
        if f == '#':
            bn += 1
            B.append(i*geta + j)
visited = set(B)
while bn < H*W:
    if not B:
        break
    dh, dw = divmod(B.pop(), geta)
    dhw = dh * geta + dw
    for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        ni, nj = dh + di, dw + dj
        if not (0 <= ni <= H - 1) or not (0 <= nj <= W - 1):
            continue
        nij = ni * geta + nj
        if nij in visited or G[ni][nj] == '#':
            continue
        visited.add(nij)
        dist[nij] = 1 + dist[dhw]
        B.appendleft(nij)
print(max(dist))

Buggy submission (verdict: Runtime Error):
from queue import Queue

def inside(x, l, r):
    return l <= x < r

if __name__ == '__main__':
    h, w = map(int, input().split())

    a = [input() for _ in range(h)]

    qu = Queue()

    nokori = h*w
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                nokori -= 1
                qu.put(i*w + j)

    ans = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    while nokori:
        ans += 1
        qu2 = Queue()
        while not qu.empty():
            i0, j0 = divmod(qu.get(), w)
            for k in range(4):
                ni = i0 + dx[k]
                nj = j0 + dy[k]
                if not (inside(ni, 0, h) and inside(nj, 0, w)):
                    continue
                if a[ni][nj] == '.':
                    a[ni][nj] = '#'
                    nokori -= 1
                    qu2.put(ni*w+nj)
        qu = qu2
    print(ans)

Buggy submission (verdict: Runtime Error):
from sys import exit
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()
ul = 1
dl = H
rl = W
ll = 1
for s, t in zip(S[1::][::-1], T[::-1]):
    if t == 'U':
        dl = min(H, dl+1)
    elif t == 'D':
        ul = max(1, ul-1)
    elif t == 'L':
        rl = min(W, rl+1)
    else:
        ll = max(1, ll-1)
    if s == 'U':
        ul += 1
    elif s == 'D':
        dl -= 1
    elif s == 'L':
        ll += 1
    else:
        rl -= 1
    if ul > dl or ll > rl or ul == H + 1 or dl == 0 or ll == W + 1 or rl == 0:
        print('NO')
        exit()
s = S[0]
if s == 'U':
    ul -= 1
elif s == 'D':
    dl += 1
elif s == 'L':
    ll -= 1
else:
    rl += 1

if ul <= sr <= dl and ll <= sc <= rl:
    print('YES')
else:
    print('NO')
Problem p03201 (python)

Fixed submission:
import bisect
from collections import defaultdict
def inpl(): return [int(i) for i in input().split()]
H = defaultdict(lambda: [])
Ad = defaultdict(lambda: 0)
N = int(input())
A = inpl()
for i in A:
    Ad[i] += 1
A = list(set(A))
A.sort()
ans = 0
for j in range(30,0,-1):
    k = 2**j
    H = defaultdict(lambda: [])
    ml = bisect.bisect_left(A, k) 
    for i in A[:ml]:
        if 2*i == k:
            ans += Ad[i]//2
            del Ad[i]
            continue
        if H[k-i]:
            m = min(Ad[k-i], Ad[i])
            Ad[k-i] -= m
            del Ad[i]
            ans += m
        else:
            H[i] = j
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return [int(i) for i in input().split()]
def list_dif(l1, l2):
    result = l1.copy()
    for v in l2:
        if v in result:
            result.remove(v)
    return result
H = defaultdict(lambda: [])
N = int(input())
A = sorted(inpl())
ans = 0
for j in range(29,0,-1):
    k = 2**j
    t = []
    H = defaultdict(lambda: [])
    for i in A:
        if k <= i:
            break
        if H[k-i]:
            t.append(H[k-i].pop())
            t.append(i)
            ans += 1
        else:
            H[i].append(i)
    A = list_dif(A, t)
print(ans)
Problem p03253 (python)

Fixed submission:
def prf(m):
    pf = {}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf
def inpl(): return [int(i) for i in input().split()]
def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

mod = 10**9+7
N, M = inpl()

ans = 1
for i in prf(M).values():
    ans = ans*comb(N+i-1, i)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb 
def prf(m):
    pf = {}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf
def inpl(): return [int(i) for i in input().split()]

mod = 10**9+7
N, M = inpl()

ans = 1
for i in prf(M).values():
    ans = ans*comb(N+i-1, i, exact = True)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def prf(m):
    pf = {}
    for i in range(2,int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i,0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf
def inpl(): return [int(i) for i in input().split()]
mod = 10**9+7
N, M = inpl()
fac = [1 for _ in range(2*N+1)]
for i in range(2*N):
    fac[i+1] = (i+1)*fac[i]%mod

inv = [1 for _ in range(2*N+1)]
for i in range(2,2*N+1):
    inv[i] = (-(mod//i) * inv[mod%i]) %mod    

facinv = [1 for _ in range(2*N+1)]
for i in range(2*N):
    facinv[i+1] = inv[i+1]*facinv[i]%mod

ans = 1
for i in prf(M).values():
    ans = ans*fac[N+i-1]*facinv[i]*facinv[N-1]%mod
print(ans)
Problem p03327 (python)

Fixed submission:
num = input()
num = int(num)
if num <= 999 and num >= 0 :
    print('ABC')
elif num >= 1000 and num <= 1998 :
    print('ABD')

Buggy submission (verdict: Runtime Error):
n,c = [int(i) for i in input().split()]
d = [] 
for i in range(c):
    d.append(list(map(int, input().split())))
color = []
for i in range(n):
    color.append(list(map(int, input().split())))
for i in range(n):
    for j in range(n):
        color[i][j] -= 1
dofc = [[0 for i in range(3)] for j in range(c)]
for t in range(3):
    for a in range(c):
        for l in range(n):
            for row in range(n):
                dofc[a][(l+row)%3] += d[a][color[row][l]]
D = dofc[0][0]+dofc[1][1]+dofc[2][2]
for c0 in range (c):
    for c1 in range (c):
        if c1 == c0:
            continue
        for c2 in range (c):
            if c2 == c1 or c2 == c0:
                continue
            D = min(D,dofc[c0][0]+dofc[c1][1]+dofc[c2][2])
print(D)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input().split())
s = b-a
s = int(s*(s+1)/2-b)
print(s)
Problem p03426 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

H, W, D = inpl()
S = dict([])
for i in range(H):
    a = inpl()
    for j in range(W):
        S[a[j]] = [i,j]

dist = [[0] for i in range(D+1) ]
for i in range(1,D+1):
    for j in range(1,1+(H*W-i)//D):
        dist[i].append(dist[i][-1] +\
        (abs(S[i+j*D][0]-S[i+(j-1)*D][0])+abs(S[i+j*D][1]-S[i+(j-1)*D][1])))
Q = int(input())
ans = []
for i in range(Q):
    l, r = inpl()
    mod = l % D
    if mod == 0 : mod = D
    l, r = (l-mod)//D, (r-mod)//D
    ans.append(dist[mod][r]-dist[mod][l])
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

H, W, D = inpl()
S = dict([])
for i in range(H):
    a = inpl()
    for j in range(W):
        S[a[j]] = [i,j]

dist = [[0] for i in range(D+1) ]
for i in range(1,D+1):
    for j in range(1,-(-(H*W-i)//D)):
        dist[i].append(dist[i][-1] +\
        (abs(S[i+j*D][0]-S[i+(j-1)*D][0])+abs(S[i+j*D][1]-S[i+(j-1)*D][1])))
Q = int(input())
ans = []
for i in range(Q):
    l, r = inpl()
    mod = l % D
    if mod == 0 : mod = D
    l, r = (l-mod)//D, (r-mod)//D
    ans.append(dist[mod][r]-dist[mod][l])
for i in ans:
    print(i)
Problem p03617 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

Q, H, S, D = inpl()
N = int(input())
mini2 = min(8*Q, 4*H, 2*S, D)
mini1 = min(4*Q, 2*H, S)
print(N//2*mini2 + N%2*mini1)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
from math import atan
def lis(L):
    if not L:
        return 0
    seq = [L[0]]
    for i in L[1:]:
        if seq[-1] < i:
            seq.append(i)
        else:
            seq[bisect.bisect_left(seq, i)] = i
    return len(seq)

def mhd(x, y):
    return abs(x) + abs(y)

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
        
N = int(sys.stdin.readline())

if x1 == x2 or y1 == y2:
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if X != x1:
                continue
            else:
                if y1 <= Y <= y2:
                    print(100*mhd(0, y1-y2) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(0, y1-y2))
                    sys.exit()
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if Y != y1:
                continue
            else:
                if x1 <= X <= x2:
                    print(100*mhd(x1-x2, 0) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(x1-x2, 0))
                    sys.exit()
if x1 > x2:
    x1, x2 = x2, x1
    y1, y2 = y2, y1

geta = 10**9+7
B = []
if y1 < y2:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y1 <= Y <= y2:
            B.append(X*geta + Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))
    
else:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y2 <= Y <= y1:
            B.append(X*geta - Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))
Problem p03634 (python)

Fixed submission:
from collections import defaultdict
def inpl(): return [int(i) for i in input().split()]

path = defaultdict(lambda: [])
N = int(input())
for _ in range(N-1):
    a, b, c = inpl()
    path[a].append((b,c))
    path[b].append((a,c))

ctr = 1
Q, K = inpl()
now = [K]
dist = [0 for _ in range(N+1)]
while True:
    for na in now.copy():
        na = now.pop()
        for nb, nc in path[na]:
            dist[nb] = dist[na] + nc
            path[nb].remove((na,nc))
            now.append(nb)
            ctr += 1
    if ctr >=  N:
        break
for i in range(Q):
    x, y = inpl()
    print(dist[x]+dist[y])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return [int(i) for i in input().split()]

path = defaultdict(lambda: [])
N = int(input())
for _ in range(N-1):
    a, b, c = inpl()
    path[a].append((b,c))
    path[b].append((a,c))

ctr = 1
Q, K = inpl()
now = [K]
dist = [0 for _ in range(N+1)]
while True:
    for na in now.copy():
        na = now.pop()
        for nb, nc in path[na]:
            dist[nb] = dist[na] + nc
            path[nb].remove((na,nc))
            now.add(nb)
            ctr += 1
    if ctr >=  N:
        break
for i in range(Q):
    x, y = inpl()
    print(dist[x]+dist[y])
Problem p03726 (python)

Fixed submission:
from sys import exit
def Fi():
    print('First')
    exit()

N = int(input())
dim = [-1]*N
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    dim[a-1] += 1
    dim[b-1] += 1
    Edge[a-1].append(b-1)
    Edge[b-1].append(a-1)
par = [None] + [0]*(N-1)
stack = [0]
visited = set([0])
while stack:
    vn = stack.pop()
    for vf in Edge[vn]:
        if vf in visited:
            continue
        visited.add(vf)
        par[vf] = vn
        stack.append(vf)

L = [i for i in range(1,N) if dim[i] == 0]
used = set(L)
stack = L[:]
mat = [0]*N
dim[0] += 2
while stack:
    vn = stack.pop()
    pv = par[vn]
    if pv is None:
        break
    if mat[vn] == 0:
        mat[vn] += 1
        mat[pv] += 1
    dim[pv] -= 1
    if dim[pv] == 0:
        stack.append(pv)
print('Second' if all(m == 1 for m in mat) else 'First')

Buggy submission (verdict: Runtime Error):
from collections import deque
from sys import exit
def Fi():
    print('First')
    exit()

N = int(input())
dim = [0]*N
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    dim[a-1] += 1
    dim[b-1] += 1
    Edge[a-1].append(b-1)
    Edge[b-1].append(a-1)
par = [None] + [0]*(N-1)
stack = [0]
visited = set([0])
while stack:
    vn = stack.pop()
    for vf in Edge[vn]:
        if vf in visited:
            continue
        visited.add(vf)
        par[vf] = vn
        stack.append(vf)

L = [i for i in range(1,N) if dim[i] == 1]
used = set()
stack = deque(L)
while stack:
    vn = stack.pop()
    vp = par[vn]
    if vp is None:
        Fi()
    dim[vp] -= 1
    if vp in used:
        Fi()
    used.add(vp)
    pvp = par[vp]
    if dim[pvp] == 1 and pvp is not None:
        stack.appendleft(pvp)
print('Second')

Buggy submission (verdict: Runtime Error):
from collections import deque
from sys import exit
def Fi():
    print('First')
    exit()

N = int(input())
dim = [0]*N
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    dim[a-1] += 1
    dim[b-1] += 1
    Edge[a-1].append(b-1)
    Edge[b-1].append(a-1)
par = [None] + [0]*(N-1)
stack = [0]
visited = set([0])
while stack:
    vn = stack.pop()
    for vf in Edge[vn]:
        if vf in visited:
            continue
        visited.add(vf)
        par[vf] = vn
        stack.append(vf)

L = [i for i in range(1,N) if dim[i] == 1]
used = set()
stack = deque(L)
while stack:
    vn = stack.pop()
    vp = par[vn]
    dim[vp] -= 1
    if vp in used:
        Fi()
    used.add(vp)
    pvp = par[vp]
    if dim[pvp] == 1 and pvp is not None:
        stack.appendleft(pvp)
print('Second')
Problem p03745 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N = int(input())
A = inpl()
ans = 1
first = True
for i in range(N-1):
    if first:
        if A[i+1] == A[i]:
            continue
        else:
            c = (A[i+1]-A[i])//abs((A[i+1]-A[i]))
            first = False
            continue
    if c*A[i] > c*A[i+1]:
        ans += 1
        first = True
print(ans)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v]:
        if visited[i]:
            continue
        visited[i] = True
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
visited = [False for _ in range(N+1)]
visited[1] = True
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
path = list(reversed(path))
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
print(len(path))
print(*path)
Problem p03776 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
def comb(a,b):
    return math.factorial(a)//math.factorial(a-b)//math.factorial(b)

N, A, B = inpl()
V = inpl()
V = list(reversed(sorted(V)))
x1 = N-1
x2 = 0
for i in range(N):
    if V[i] == V[A]:
        x1 = min(x1,i)
        x2 = max(x2,i)

print(sum(V[0:A])/A)
import math
ans = 0
if x1 == 0:
    for l in range(A-1,min(B,x2+1)):
        ans += comb(x2-x1+1,l-x1+1)
    print(ans)
else:
    print(comb(x2-x1+1,A-x1))

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

N, A, B = inpl()
V = inpl()
V = list(reversed(sorted(V)))
x1 = N-1
x2 = 0
for i in range(N):
    if V[i] == V[A]:
        x1 = min(x1,i)
        x2 = max(x2,i)

print(sum(V[0:A])/A)
from scipy.special import comb
ans = 0
if x1 == 0:
    for l in range(min(B-1,x2)-A+2):
        ans += comb(x2-x1+1,l-x1+1, exact=True)
    print(ans)
else:
    print(comb(x2-x1+1,A-x1+1, exact=True))
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2*10**5)
N = int(input())
A = [int(input()) for _ in range(N-1)]
if len(set(A)) == N - 1:
    print(N - 1)
    sys.exit()
H = [[] for _ in range(N+1)]
for i, a in enumerate(A, 2):
    H[a].append(i)

def depth(x):
    if not H[x]:
        return 0
    k = len(H[x])
    return max([k - i + j for i, j in zip(range(k), sorted([depth(x) for x in H[x]]))])

print(depth(1))

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
N = int(input())
A = [int(sys.stdin.readline()) for _ in range(N-1)]
H = defaultdict(lambda: [])
for i, a in enumerate(A, 2):
    H[a].append(i)

def depth(x):
    if not H[x]:
        return 0
    k = len(H[x])
    return max([k - i + j for i, j in zip(range(k), sorted([depth(x) for x in H[x]]))])

print(depth(1))
Problem p03834 (python)

Fixed submission:
print(input().replace(',',' '))

Buggy submission (verdict: Runtime Error):
import heapq

n, m = [int(i) for i in input().split()]
inf = 10**10
path = [[0] * n for _ in range(n)]
Q = [[inf] * n for _ in range(n)]
ans = 0
pathnum = []
ctr = 0

for i in range(m):
    a, b, c = map(lambda x: int(x)-1 ,input().split())    
    path[a][b] = path[b][a] = c+1
    pathnum.append((a,b))

for i in range(n):
    decided = [False for _ in range(n)]
    H = []
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    while ctr != n:
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                ctr += 1
                break
        for j in range(n):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

for i in pathnum:
    if Q[i[0]][i[1]] == inf:
        continue
    elif Q[i[0]][i[1]] != path[i[0]][i[1]]:
        ans += 1
print(ans)
Problem p03986 (python)

Fixed submission:
X = input()
ctr = 0
ans = 0
for i in X:
    if i == 'T':
        if ctr > 0:
            ctr -= 1
        else: 
            ans += 1
    else:
        ctr += 1
print(2*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    if d == 1:
        return x[0]
    result = 0
    if mini != 0:
        result += minisum(x[0:mini])
    if mini != d-1:
        result += minisum(x[mini+1:d])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))
Problem p02659 (python)

Fixed submission:
from decimal import *
A,B = list(map(Decimal, input().split()))
print(int(A*B))

Buggy submission (verdict: Runtime Error):
A,B = list(map(int, input().split()))
print(int(A*B))