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

Fixed submission:
# pdf
from heapq import *

n, m = map(int, input().split())
hp = []
for _ in range(n):
    a, b = map(int, input().split())
    heappush(hp, [a, b])
ans = 0
mx = b
ch = []
a, b = heappop(hp)
flag = 1
for i in range(1, m + 1):
    while a <= i:
        if flag:
            heappush(ch, -b)
            flag = 0
        if not hp:break
        a, b = heappop(hp)
        flag = 1
    if ch:
        ans -= heappop(ch)
print(ans)

Buggy submission (verdict: Runtime Error):
def update(i, x):
    i += 1
    while i < m + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 1)
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], -x[0]))
cnt = 0
ans = 0
for a, b in ab:
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans += b
    print(a,b,bit,get_sum(a))
    if cnt == m: break
print(ans)

Buggy submission (verdict: Runtime Error):
def update(i, x):
    i += 1
    while i < n + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 2)
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:(-x[1],-x[0]))
cnt = 0
ans = 0
for a,b in ab:
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans += b
    if cnt==m:break
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import *

def update(i, x):
    i += 1
    while i < n + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 2)
hp = []
for _ in range(n):
    a, b = map(int, input().split())
    heappush(hp, [-b, a])
cnt = 0
ans = 0
while cnt < m and hp:
    b, a = heappop(hp)
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans -= b
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import *

n, m = map(int, input().split())
hp = []
used = [0] * (m + 1)
for _ in range(n):
    a, b = map(int, input().split())
    heappush(hp, [-b, a])
while hp:
    b, a = heappop(hp)
    while a <= m:
        if used[a] == 0: break
        a += 1
    if a == m + 1:
        continue
    else:
        used[a] = -b
print(sum(used))
Problem p02955 (python)

Fixed submission:
def yakusu(n):
    m = 1
    re = []
    while m ** 2 < n:
        a, md = divmod(n, m)
        if md == 0:
            re.append(m)
            re.append(a)
        m += 1
    if m ** 2 == n:
        re.append(m)
    return re

n, k = map(int, input().split())
aa = list(map(int, input().split()))
yk = yakusu(sum(aa))
yk.sort(reverse=True)
for y in yk:
    rs = [a % y for a in aa if a % y]
    if not rs:
        print(y)
        exit()
    if len(rs)==1:continue
    rs.sort()
    l = 0
    sl = rs[0]
    r = len(rs) - 1
    sr = y - rs[r]
    while 1:
        if l + 1 == r:
            if sl == sr and sl <= k:
                print(y)
                exit()
            else:
                break
        if sl > sr:
            r -= 1
            sr += y - rs[r]
            if sr > k: break
        else:
            l += 1
            sl += rs[l]
            if sl > k: break
print(1)

Buggy submission (verdict: Runtime Error):
def yakusu(n):
    m=1
    re=[]
    while m**2<n:
        a,md=divmod(n,m)
        if md==0:
            re.append(m)
            re.append(a)
        m+=1
    if m**2==n:
        re.append(m)
    return re

n, k = map(int, input().split())
aa = list(map(int, input().split()))
yk = yakusu(sum(aa))
yk.sort(reverse=True)
for y in yk:
    rs=[a%y for a in aa if a%y]
    rs.sort()
    l=0
    sl=rs[0]
    r=len(rs)-1
    sr=y-rs[r]
    while 1:
        if l+1==r:
            if sl==sr and sl<=k:
                print(y)
                exit()
            else:
                break
        if sl>sr:
            r-=1
            sr+=y-rs[r]
            if sr>k:break
        else:
            l+=1
            sl+=rs[l]
            if sl>k:break
print(1)
Problem p02984 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a0=sum(a)//2-sum(a[1::2])
ans=[a0*2]
for i in range(n-2):
    ans.append(a[i]*2-ans[-1])
ans.append((a[-1]-a0)*2)
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a=[[x] for x in a]
a=np.array(a)
k=np.zeros((n,n),dtype="i8")
for i in range(n-1):
    k[i][i]=1
    k[i][i+1]=1
k[n-1][0]=1
k[n-1][-1]=1
k=np.linalg.inv(k)
ka=np.dot(k,a)
ans=[]
for x in ka:
    ans.append(int(x[0])*2)
print(*ans)
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())
md=10**9+7
n1=n-k+1
n2=k-1
com1=[]
com2=[]
c1=1
c2=1
for i in range(k+1):
    com1+=[c1]
    com2+=[c2]
    c1=c1*(n1-i)//(i+1)
    c2 = c2 * (n2 - i) // (i + 1)
for i in range(1,k+1):
    ans=com1[i]*com2[i-1]%md
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

def com(m,r):
    if r>m/2:
        r=m-r
    if r==0:
        return 1
    t=(m,r)
    if t in memo:
        return memo[t]
    memo[t]=re=com(m,r-1)*(m-r+1)//r
    return re

n,k=map(int,input().split())
memo={}
md=10**9+7
for i in range(1,k+1):
    ans=com(n-k+1,i)*com(k-1,i-1)%md
    print(ans)

Buggy submission (verdict: Runtime Error):
def com(m,r):
    if r>m/2:
        r=m-r
    if r==0:
        return 1
    t=(m,r)
    if t in memo:
        return memo[t]
    memo[t]=re=com(m,r-1)*(m-r+1)//r
    return re

n,k=map(int,input().split())
memo={}
md=10**9+7
for i in range(1,k+1):
    ans=com(n-k+1,i)*com(k-1,i-1)%md
    print(ans)
Problem p02998 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(x, al):
    global cntx, cnty
    if (al, x) in used:
        return
    used.add((al, x))
    if al == 0:
        cntx += 1
    else:
        cnty += 1
    for xy in to[al][x]:
        dfs(xy, 1 - al)
    return

n = int(input())
to = [{}, {}]
for _ in range(n):
    x, y = map(int, input().split())
    to[0].setdefault(x, [])
    to[1].setdefault(y, [])
    to[0][x] += [y]
    to[1][y] += [x]
used = set()
ans = 0
for x in to[0].keys():
    if (0, x) in used: continue
    cntx = 0
    cnty = 0
    dfs(x, 0)
    ans += cntx * cnty
print(ans - n)

Buggy submission (verdict: Runtime Error):
def dfs(x, al):
    global cntx, cnty
    if (al, x) in used:
        return
    used.add((al, x))
    if al == 0:
        cntx += 1
    else:
        cnty += 1
    for xy in to[al][x]:
        dfs(xy, 1 - al)
    return

n = int(input())
to = [{}, {}]
for _ in range(n):
    x, y = map(int, input().split())
    to[0].setdefault(x, [])
    to[1].setdefault(y, [])
    to[0][x] += [y]
    to[1][y] += [x]
used = set()
ans = 0
for x in to[0].keys():
    if (0, x) in used: continue
    cntx = 0
    cnty = 0
    dfs(x, 0)
    ans += cntx * cnty
print(ans - n)
Problem p03033 (python)

Fixed submission:
import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    for i in range(q):
        d = int(input())
        ds.append(d)

    ans = [-1] * q
    jump = [-1] * q

    for x, s, t in xst:
        i = bisect_left(ds, s)
        fi = bisect_left(ds, t)
        while i < fi:
            if jump[i] != -1:
                i = jump[i]
            else:
                ans[i] = x
                jump[i] = fi
                i += 1

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    for i in range(q):
        d = int(input())
        ds.append(d)

    ans = [-1] * q
    jump = [-1] * q

    for x, s, t in xst:
        i = bisect_left(ds, s)
        fi = bisect_left(ds, t)
        while i < fi:
            if jump[i] != -1:
                i = jump[i]
            ans[i] = x
            jump[i] = fi
            i += 1

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    ans = [-1] * q
    for i in range(q):
        d = int(input())
        ds.append(d)

    for x, s, t in xst:
        st = bisect_left(ds, s)
        for i in range(st, q):
            if d[i] >= t:
                break
            if ans[i] == -1:
                ans[i] = x

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)

Buggy submission (verdict: Runtime Error):
def f(n, q):
    dp=[-1]*(10**9+1)
    for _ in range(n):
        s, t, x = map(int, input().split())
        for i in range(s-x,t-x):
            if dp[i]>x or dp[i]==-1:
                dp[i]=x
    for _ in range(q):
        d = int(input())
        print(dp[d])

n, q = map(int, input().split())
f(n, q)
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

n,*h=map(int,open(0).read().split())

gh=gcd(h[0],h[1])
for i in range(2,n):
    gh=gcd(h[i],gh)

print(gh)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

def gcd_list(lst):
    if len(lst)==2:
        return gcd(lst[0],lst[1])
    else:
        return gcd_list([gcd(lst[0],lst[1])]+lst[2:])

n,*h=map(int,open(0).read().split())

print(gcd_list(h))

Buggy submission (verdict: Runtime Error):
while len(h)>1:
    kh=[]
    for i in range(len(h)):
        mn = min(h)
        md=h[i]%mn
        if md!=0:
            kh.append(md)
        kh.append(mn)
    h=list(set(kh))
print(mn)
Problem p03209 (python)

Fixed submission:
sou = lambda n: 2 ** (n + 2) - 3
ptn = lambda n: 2 ** (n + 1) - 1


def pate(lv, x):
    if x == 0:
        return 0
    if x < 0:
        return -1
    else:
        for i in range(lv + 1):
            if x < lv - i + sou(i):
                i -= 1
                re = ptn(i) + 1 + pate(i, x - (lv - i + sou(i) + 1))
                return re
        else:
            return ptn(lv)


lv, x = map(int, input().split())
print(pate(lv, x))

Buggy submission (verdict: Runtime Error):
sou = lambda n: 2 ** (n + 2) - 3
ptn = lambda n: 2 ** (n + 1) - 1


def pate(lv, x):
    if x == 0:
        return 0
    if x < 0:
        return -1
    else:
        for i in range(lv + 1):
            if x < lv - i + sou(i): break
        i -= 1
        re = ptn(i) + 1 + pate(i, x - (lv - i + sou(i) + 1))
        return re


lv, x = map(int, input().split())
print(pate(lv, x))
Problem p03291 (python)

Fixed submission:
md=10**9+7
s=input()
dp=[[0]*4 for _ in range(3)]
for c in s:
    if c=="A":dp[0][0]=(dp[0][0]+1)%md
    if c=="B":
        for j in range(2):dp[1][j]=(dp[1][j]+dp[0][j])%md
    if c=="C":
        for j in range(3):dp[2][j]=(dp[2][j]+dp[1][j])%md
    if c=="?":
        for j in range(3):dp[2][j+1]=(dp[2][j+1]+dp[1][j])%md
        for j in range(2):dp[1][j+1]=(dp[1][j+1]+dp[0][j])%md
        dp[0][1] = (dp[0][1] + 1) % md
ans=0
q=s.count("?")
for j in range(4):
    if q-j<0:break
    ans+=dp[2][j]*pow(3,q-j,md)
    ans%=md
print(ans)

Buggy submission (verdict: Runtime Error):
md=10**9+7
s=input()
dp=[[0]*4 for _ in range(3)]
for c in s:
    if c=="A":dp[0][0]=(dp[0][0]+1)%md
    if c=="B":
        for j in range(2):dp[1][j]=(dp[1][j]+dp[0][j])%md
    if c=="C":
        for j in range(3):dp[2][j]=(dp[2][j]+dp[1][j])%md
    if c=="?":
        for j in range(3):dp[2][j+1]=(dp[2][j+1]+dp[1][j])%md
        for j in range(2):dp[1][j+1]=(dp[1][j+1]+dp[0][j])%md
        dp[0][1] = (dp[0][1] + 1) % md
ans=0
q=s.count("?")
for j in range(4):
    ans+=dp[2][j]*pow(3,q-j,md)
    ans%=md
print(ans)
Problem p03806 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,ma,mb=MI()
    inf=10**9
    abc=[LI() for _ in range(n)]
    dp=[[[inf]*(n*10+1) for _ in range(10*n+1)] for _ in range(n+1)]
    dp[0][0][0]=0
    for i,(a,b,c) in enumerate(abc):
        for j in range(n*10+1):
            for k in range(n*10+1):
                pre=dp[i][j][k]
                if pre==inf:continue
                dp[i+1][j][k]=min(dp[i+1][j][k],pre)
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],pre+c)
    ans=inf
    for i in range(1,105):
        a=i*ma
        b=i*mb
        if a>n*10 or b>n*10:break
        ans=min(ans,dp[n][a][b])
    if ans==inf:print(-1)
    else:print(ans)

main()

Buggy submission (verdict: Runtime Error):
# 半分全列挙バージョン
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,ma,mb=MI()
    abc=[LI() for _ in range(n)]
    inf=10**9
    # 前半の要素をa1,b1、後半の要素をa2,b2とする
    # (a1+a2):(b1+b2)=ma:mbとなればよい。式変形すると
    # (mb*a1-ma*b1)+(mb*a2-ma*b2)=0となる
    # つまり各要素についてmb*a-ma*bという指標を計算し、前半と後半で和が0になる組合せを探せばよい
    # 前半全列挙
    pre=[(0,0,0)]
    for a,b,c in abc[:n//2]:
        pn=len(pre)
        for i in range(pn):
            pa,pb,pc=abc[i]
            pre.append((a+pa,b+pb,c+pc))
    pre=[(a*mb-b*ma,c) for a,b,c in pre]
    # 後半全列挙
    pos=[(0,0,0)]
    for a,b,c in abc[n//2:]:
        pn=len(pos)
        for i in range(pn):
            pa,pb,pc=abc[i]
            pos.append((a+pa,b+pb,c+pc))
    pos=[(a*mb-b*ma,c) for a,b,c in pos]
    # 指標が昇順になるよう並び替えて、前半は前から後半は後からしゃくとり法で
    # 指標の和が0になるところのコストを求める
    pre.sort()
    pos.sort()
    j=len(pos)-1
    ans=inf
    for val,c in pre:
        while val+pos[j][0]>0 and j>0:j-=1
        while val+pos[j][0]==0 and j>=0:
            now=c+pos[j][1]
            if now and now<ans:ans=now
            j-=1
        if j<0:break
    if ans==inf:print(-1)
    else:print(ans)

main()
Problem p02695 (python)

Fixed submission:
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = set()

def point(x):
    temp = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if x[b-1] - x[a-1] == c:
            temp += d
    return temp

def maker(x):
    dig = len(x)
    if  dig == N:
        ans.add(point(x))
    else:
        for i in range(x[-1], M+1):
            maker(x + [i])

for i in range(1, M+1):
    maker([i])
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = set()

def point(x):
    temp = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if x[b-1] - x[a-1] == c:
            temp += d
    return temp

def maker(x):
    dig = len(x)
    if  dig == N:
        ans.add(point(x))
    else:
        for i in range(x[-1], M+1):
            maker(x + [i])

for i in range(1, M):
    maker([i])
print(max(ans))
Problem p02833 (python)

Fixed submission:
import math
N = int(input())

if N % 2 != 0 or N <= 8:
    print(0)
else:
    n = N // 10
    ans = n
    for i in range(1,int(math.log(n, 5) + 1)):
        ans += n // (5 ** i)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())

if N % 2 != 0:
    print(0)
else:
    n = N // 10
    ans = n
    for i in range(1,int(math.log(n, 5) + 1)):
        ans += n // (5 ** i)
    print(ans)
Problem p02990 (python)

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

def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

for i in range(1,K+1):
    if N-K+1 < i:   print(0)
    else:   print( (C(N-K+1,i)*C(K-1,i-1)) % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())

def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

for i in range(1,K+1):
    print( (C(N-K+1,i)*C(K-1,i-1)) % 1000000007)
Problem p03013 (python)

Fixed submission:
N,M = map(int, input().split())
a = set()
for i in range(M):
    a.add(int(input()))

if N == 1:  print(1)
elif N == 2:
    if 1 == M:  print(1)
    else:   print(2)
else:
    temp, temp1, temp2 = 0,0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N-1):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

    print( int((temp1+temp2) % 1000000007) )

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = []
for i in range(M):
    a += [int(input())]

if N == 1:  print(1)
elif N == 2:
    if 1 in a:  print(1)
    else:   print(2)
else:
    temp1, temp2 = 0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

print( int(temp % 1000000007) )
Problem p03015 (python)

Fixed submission:
L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

ans, m = 0, 1
while True:
    if '0' not in L:
        ans = (ans + (m * num_ab[len(L)]) % MOD) % MOD
        print(ans)
        exit()
    elif '1' not in L[1:]:
        ans = (ans + ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD) % MOD
        print(ans)
        exit()
    else:
        ans = (ans + (m * num_ab[len(L) - 1]) % MOD) % MOD
        L = L[L[1:].index('1') + 1:]
        m = (2 * m) % MOD

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(100002)

L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

def calc(L, m):
    m %= MOD
    if len(L) == 1:
        return (m * num_ab[int(L)]) % MOD
    elif '0' not in L:
        return (m * num_ab[len(L)]) % MOD
    elif '1' not in L[1:]:
        return ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD
    else:
        return ((m * num_ab[len(L) - 1]) % MOD + calc(L[L[1:].index('1') + 1:], 2*m)) % MOD

print(calc(L,1))

Buggy submission (verdict: Runtime Error):
L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

def calc(L, m):
    m %= MOD
    if len(L) == 1:
        return (m * num_ab[int(L)]) % MOD
    elif '0' not in L:
        return (m * num_ab[len(L)]) % MOD
    elif '1' not in L[1:]:
        return ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD
    else:
        return ((m * num_ab[len(L) - 1]) % MOD + calc(L[L[1:].index('1') + 1:], 2*m)) % MOD

print(calc(L,1))
Problem p03104 (python)

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

if A == B:
    print(A)
elif B - A == 1:
    print(A^B)
else:
    ans = 0
    if A % 2 != 0:
        ans ^= A
        A += 1
    if B % 2 == 0:
        ans ^= B
        B -= 1
    ans ^= ((B-A+1)//2)%2

    print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B = (int(x) for x in input().split())

if A==B:
    print(A)
else:
    ans = 0
    if A*2 <= B+1 and B > 4:
        n = int(math.log2(A))
        m = int(math.log2(B))

        if n <= 1:
            for i in range(A,4):
                ans = ans ^ i
            A=4
            n=2
            
        if 2**n != A:
            n += 1
            for i in range(A,2**n):
                ans = ans ^ i

        for i in range(2**m,B+1):
            ans = ans ^ i

    else:
        for i in range(A,B+1):
            ans = ans ^ i

    print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B = (int(x) for x in input().split())

if A==B:
    print(A)
else:
    ans = 0
    if A*2 <= B+1 and B > 4:
        n = int(math.log2(A))
        m = int(math.log2(B))

        if n <= 1:
            for i in range(A,4):
                ans = ans ^ i
            A=4
            n=2
            
        if 2**n != A:
            n += 1
            ans = A
            for i in range(A+1,2**n):
                ans = ans ^ i

        for i in range(2**m,B+1):
            ans = ans ^ i

    else:
        for i in range(A+1,B+1):
            ans = ans ^ i

    print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B = (int(x) for x in input().split())

if A==B:
    print(A)
else:
    ans = 0
    if A*2 <= B-1 and B > 4:
        n = int(math.log2(A))
        m = int(math.log2(B))

        if n <= 1:
            for i in range(A,4):
                ans = ans ^ i
            A=4
            n=2
            
        if 2**n != A:
            n += 1
            ans = A
            for i in range(A+1,2**n):
                ans = ans ^ i

        for i in range(2**m,B+1):
            ans = ans ^ i

    else:
        for i in range(A+1,B+1):
            ans = ans ^ i

    print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B = (int(x) for x in input().split())

if A==B:
    print(A)
else:
    ans = 0
    if A*2 <= B and B > 4:
        n = int(math.log2(A))
        m = int(math.log2(B))

        if n <= 1:
            for i in range(A,4):
                ans = ans ^ i
            A=4
            n=2
            
        if 2**n != A:
            n += 1
            ans = A
            for i in range(A+1,2**n):
                ans = ans ^ i

        for i in range(2**m,B+1):
            ans = ans ^ i

    else:
        for i in range(A,B+1):
            ans = ans ^ i

    print(ans)

Buggy submission (verdict: Runtime Error):
A,B = (int(x) for x in input().split())

if A=B:
    print(A)
else:
    ans = A^(A+1)

    for i in range(A+2,B+1):
        ans = ans ^ i

    print(ans)
Problem p03618 (python)

Fixed submission:
import collections

A = list(input())
N, ans = len(A), 0

c = collections.Counter(A)
for x in list(c.keys()):
    ans += c[x] * (c[x] - 1) // 2

print(N*(N-1)//2 + 1 - ans)

Buggy submission (verdict: Runtime Error):
A = list(input())
N, ans = len(A), 0

for i in range(1, N-1):
    j = 1
    while i-j >= 0 and i+j-1 < N:
        if A[i-j] == A[i+j-1]:
            ans += 1
        j += 1

    j = 1
    while i-j >= 0 and i+j < N:
        if A[i-j] == A[i+j]:
            ans += 1
        j += 1

if A[-1] == A[-2]:
    ans += 1

print(N*(N-1)//2 + 1 - ans)
Problem p03634 (python)

Fixed submission:
from collections import deque

N = int(input())
T = [{} for i in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    T[a][b] = c
    T[b][a] = c

Q, K = map(int, input().split())
shortest_path = [0 for _ in range(N+1)]
queue = deque([[v, T[K][v], K] for v in T[K].keys()])
for _ in range(N-1):
    v = queue.popleft()
    shortest_path[v[0]] = v[1]
    queue.extend([[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]])

for _ in range(Q):
    x, y = map(int, input().split())
    print(shortest_path[x] + shortest_path[y])

Buggy submission (verdict: Runtime Error):
N = int(input())
T = [{} for i in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    T[a][b] = c
    T[b][a] = c

Q, K = map(int, input().split())
shortest_path = [0 for _ in range(N+1)]
queue = [[v, T[K][v], K] for v in T[K].keys()]

for _ in range(Q):
    x, y = map(int, input().split())
    while len(queue) > 0 or (shortest_path[x] != 0 and shortest_path[y] != 0):
        v = queue.pop(0)
        shortest_path[v[0]] = v[1]
        queue += [[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]]
    print(shortest_path[x] + shortest_path[y])