Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = input()
nums = input().split()
res = int(nums.pop(0))

if 0 in nums:
  print('0')
  return

for i in nums:
  res *= int(i)

print(res)

Fixed submission:
import sys
 
N = input()
nums = list(map(int, input().split()))
res = 1

if 0 in nums:
  res = 0
else:
  for i in nums:
    res *= i
    if res > 10 ** 18:
      res = -1
      break
print(res)
Buggy python submission (verdict: Runtime Error):
x, y = input().split()
 
x = int(x)
y = float(y)
 
print(int(x * y, '10'))

Fixed submission:
import math
x, y = list(map(float, input().split()))

x = int(x)
y = int(y * 100 + 0.5)
 
print(x * y // 100)

Buggy python submission (verdict: Runtime Error):
x, y = input().split()

x = int(x)
y = float(y)

print(int(x * y, 10))

Fixed submission:
import math
x, y = list(map(float, input().split()))

x = int(x)
y = int(y * 100 + 0.5)
 
print(x * y // 100)
Buggy python submission (verdict: Time Limit Exceeded):
s= input()
q= int(input())
inv = False
for i in range(q):
    p = input()
    if p[0]=='1':
        if inv:inv=False
        else:inv=True
    elif p[0]=='2':
        _,f,c= p.split()
        if f=='1':
            if inv:s = s+c
            else: s = c+s
        elif f=='2':
            if inv:s=c+s
            else:s = s + c
if inv:print(s[::-1])
else:print(s)

Fixed submission:
from collections import deque
s= input()
q= int(input())
inv = False
head = deque()
tail = deque()
for i in range(q):
    p = input()
    if p[0]=='1':
        if inv:inv=False
        else:inv=True
    elif p[0]=='2':
        _,f,c= p.split()
        if f=='1':
            if inv:tail.append(c)
            else:head.appendleft(c)
        elif f=='2':
            if inv:head.appendleft(c)
            else:tail.append(c)
news = ''.join(head) + s + ''.join(tail)
if inv:print(news[::-1])
else:print(news)

Buggy python submission (verdict: Time Limit Exceeded):
s= input()
q= int(input())
for i in range(q):
    p = input()
    if p[0]=='1':s = s[::-1]
    elif p[0]=='2':
        _,f,c= p.split()
        if f=='1':s = c + s
        elif f=='2':s = s + c
print(s)


Fixed submission:
from collections import deque
s= input()
q= int(input())
inv = False
head = deque()
tail = deque()
for i in range(q):
    p = input()
    if p[0]=='1':
        if inv:inv=False
        else:inv=True
    elif p[0]=='2':
        _,f,c= p.split()
        if f=='1':
            if inv:tail.append(c)
            else:head.appendleft(c)
        elif f=='2':
            if inv:head.appendleft(c)
            else:tail.append(c)
news = ''.join(head) + s + ''.join(tail)
if inv:print(news[::-1])
else:print(news)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
aa=''.join([int(a) for _ in range(int(b))])
bb=''.join([int(b) for _ in range(int(a))])
print(max(int(aa),int(bb)))
           

Fixed submission:
a,b = input().split()
aa=''.join([a for _ in range(int(b))])
bb=''.join([b for _ in range(int(a))])
print(max(int(aa),int(bb)))
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
print(t+s)

Fixed submission:
s=input().split()
print(s[1]+s[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
all_set = set([c for c in range(1,n+1)])
node_col = [set() for _ in range(n)]
maxc = 0
anslist = []
for i in range(n-1):
    a,b = map(int,input().split())
    abset = node_col[a-1] | node_col[b-1]
    all_m_ab = all_set - abset
    minc = min(all_m_ab)
    node_col[a-1].add(minc)
    node_col[b-1].add(minc)
    anslist.append(minc)
    maxc = max(maxc,minc)
print(maxc)
for p in anslist:print(p)

Fixed submission:
import queue
n = int(input())
tree_node = [set() for _ in range(n)]
hen = []
hen_col = {}
for i in range(n-1):
    a,b = map(int,input().split())
    tree_node[a-1].add(b)
    hen.append([a,b])
    hen_col[str(a)+'-'+str(b)] = 0
q = queue.Queue()
q.put(1)
parent_node = [0] * n
parent_color = [0] * n
maxcol = 0
while not q.empty():
    col = 0
    nod = q.get()
    for i,c in enumerate(tree_node[nod-1]):
        if i+1 == parent_color[nod-1]:col+=1
        tempcol = i+1+col
        parent_color[c-1]=tempcol
        maxcol = max(maxcol,tempcol)
        q.put(c)
        l = min(nod,c)
        r = max(nod,c)
        hen_col[str(l)+'-'+str(r)] = tempcol
        parent_node[c-1] = nod

print(maxcol)
for t in hen:
    tempstr = str(t[0])+'-'+str(t[1])
    print(hen_col[tempstr])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = list(map(int,input().split()))
co = []
ol = sorted(l)
nl = sorted(l,reverse=True)
for i in range(1,n):
    for j in range(1,n):
        if i<j:
            co.append(nl[i]+nl[j])
nco = list(reversed(co))
sk = 0
g = 0
for i in range(2,n):
    a = ol[i]
    x = nco[:(i)*(i-1)//2]
    ind = bisect.bisect(x,a)
    g += len(x)-ind
print(g)

Fixed submission:
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
    for bi in range(ai+1,n-1):
        g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
co = []
nl = sorted(l,reverse=True)
for i in range(1,n):
    for j in range(1,n):
        if i<j:
            co.append(nl[i]+nl[j])
sk = 0
g = 0
for i in range(n-1):
    a = nl[i]
    for j in co[sk:]:
        if a<j:
            g +=1
    sk += n-2-i
print(g)

Fixed submission:
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
    for bi in range(ai+1,n-1):
        g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
nl = sorted(l,reverse=True)
c = 0
for i in range(n-2):
    a = nl[i]
    for j in range(n-1,i,-1):
        for k in range(i+1,j):
            if a<(nl[j]+nl[k]):
                c+=1
            else:
                break
print(c)

Fixed submission:
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
    for bi in range(ai+1,n-1):
        g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int,input().split()))
a = [0] * n
if n==2:
    print(b[0]*2)
else:
    #c = d = 0
    a[0] = b[0]
    for i in range(n-1,-1,-1):
        if i == n-1:
            a[i] = b[i-1]
        elif i == 0:
            #a[0] = min(b[0],b[1])
        else:
            a[i] = min(b[i-1],b[i])
    print(sum(a))

Fixed submission:
n = int(input())
b = list(map(int,input().split()))
a = [0] * n
if n==2:
    print(b[0]*2)
else:
    #c = d = 0
    a[0] = b[0]
    for i in range(n-1,-1,-1):
        if i == n-1:
            a[i] = b[i-1]
        elif i == 0:
            pass
            #a[0] = min(b[0],b[1])
        else:
            a[i] = min(b[i-1],b[i])
    print(sum(a))
Buggy python submission (verdict: Runtime Error):
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)

Fixed submission:
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    if a<=m:feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
dic = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a > M:
        pass
    else:
        if a in dic.keys():
            dic[a].append(b)
        else:
            dic[a] = [b]
#print(dic)
lis = [[]] * M
for p in dic.keys():
    lis[p-1] = dic[p]
#print('lis:',lis)
g = 0
for i in range(M):
    if lis[i] == []:
        pass
    else:
        #print('sublis:',lis[i])
        mx = max(lis[i])
        g += mx
        lis[i].remove(mx)
        if i+1 < M:
            if len(lis[i])>0:
                lis[i+1].extend()
    #print(lis)
print(g)

Fixed submission:
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    if a<=m:feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
dic = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a > M:
        pass
    else:
        if a in dic.keys():
            dic[a].append(b)
        else:
            dic[a] = [b]
lis = [[]] * M
for p in dic.keys():
    lis[M-p] = dic[p]
g = 0
for j in range(M):
    id = 0
    m =  0
    for w,k in enumerate(lis[j:]):
        if k != []:
            if m < max(k):
                m = max(k)
                id = w
    if m != 0:
        g += m
        lis[id+j].remove(m)
print(g)

Fixed submission:
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    if a<=m:feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)
Buggy python submission (verdict: Runtime Error):
if L > 0:
    k = N*(L-1) + (N * (N+1))//2 - L
    print(k)
elif L == 0:
    print( (N-1) * N //2)
else: 
    if L+N-1 >=0:
        k = N*(L-1) + (N * (N+1))//2
        print(k)
    else:
        k = N*(L-1) + (N * (N+1))//2 - (L+N-1)
        print(k)

Fixed submission:
N,L = map(int,input().split())
if L > 0:
    k = N*(L-1) + (N * (N+1))//2 - L
    print(k)
elif L == 0:
    print( (N-1) * N //2)
else: 
    if L+N-1 >=0:
        k = N*(L-1) + (N * (N+1))//2
        print(k)
    else:
        k = N*(L-1) + (N * (N+1))//2 - (L+N-1)
        print(k)
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
l = list(map(int,input().split()))
d = preD = 0
i = 0
while d <= X:
    d = preD + l[i]
    i += 1
    preD = d
print(i)

Fixed submission:
N,X = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
d = preD = 0
i = 0
for i in range(N):
    d = preD + l[i]
    preD = d
    #print(i+1,d)
    if d == X:
        print(i+2)
        break
    elif d > X:
        print(i+1)
        break
else:
    print(N+1)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
pre_a = -1
k = []
ef = True
for i in range(M):
    a = int(input())
    if (a-pre_a == 1):break
    k.append(a-pre_a-2)
    pre_a = a
else:
    ef = False
    k.append(N-a-1)
nk = sorted(k)
def org_fib(t):
    t1 = 1
    t2 = 2
    fib = 0
    if t == 1:
        return t1
    elif t == 2:
        return t2
    else:
        for _ in range(t-2):
            fib = t1+t2
            t1 = t2
            t2 = fib
    return fib

if ef:print(0)
else:
    g = 1
    for nnkk in nk:
        if nnkk == 0:
            pass
        else:
            g = (g * org_fib(nnkk)) % 1000000007
    print(g)

Fixed submission:
def org_fib(t):
    t1 = 1
    t2 = 2
    fib = 0
    if t == 1:
        return t1
    elif t == 2:
        return t2
    else:
        for _ in range(t-2):
            fib = t1+t2
            t1 = t2
            t2 = fib
    return fib % 1000000007

N,M = map(int,input().split())
if N == 1:
    print(1)
elif M == 0:
    print(org_fib(N))
else:
    pre_a = -1
    k = []
    ef = True
    for i in range(M):
        a = int(input())
        if (a-pre_a == 1):break
        k.append(a-pre_a-2)
        pre_a = a
    else:
        ef = False
        k.append(N-a-1)

    if ef:print(0)
    else:
        g = 1
        for kk in k:
            if kk == 0:pass
            else:g = (g * org_fib(kk)) % 1000000007
        print(g)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
pre_a = -1
k = []
ef = False
for i in range(M):
    a = int(input())
    if a == 1:pre_a = 1
    else:
        if a-pre_a == 1:
            ef = True
            break
        #print(a,pre_a)
        k.append(a-pre_a-2)
        #print(k)
        pre_a = a
else:
    if a < N:k.append(N-a-1)
#print(k)
nk = sorted(k)
#print('nk:',nk)
def fib(sorted_lis):
    t1 = 1
    t2 = 2
    retl = []
    fi = 0
    i = 0
    for k in range(max(sorted_lis)+1):
        if k == 0:fi = 1
        elif k == 1:fi = t1
        elif k == 2:fi = t2
        else:
            fi = t1 + t2
            t1 = t2
            t2 = fi
        while (i < len(sorted_lis)) and (sorted_lis[i] == k):
            retl.append(fi % 1000000007)
            i += 1
    return retl
if ef:print(0)
else:
    cl = fib(nk)
    #print(cl)
    g = 1
    for kk in cl:g = (g * kk) % 1000000007
    print(g)

Fixed submission:
def org_fib(t):
    t1 = 1
    t2 = 2
    fib = 0
    if t == 1:
        return t1
    elif t == 2:
        return t2
    else:
        for _ in range(t-2):
            fib = t1+t2
            t1 = t2
            t2 = fib
    return fib % 1000000007

N,M = map(int,input().split())
if N == 1:
    print(1)
elif M == 0:
    print(org_fib(N))
else:
    pre_a = -1
    k = []
    ef = True
    for i in range(M):
        a = int(input())
        if (a-pre_a == 1):break
        k.append(a-pre_a-2)
        pre_a = a
    else:
        ef = False
        k.append(N-a-1)

    if ef:print(0)
    else:
        g = 1
        for kk in k:
            if kk == 0:pass
            else:g = (g * org_fib(kk)) % 1000000007
        print(g)
Buggy python submission (verdict: Runtime Error):
n= int(input())
bdic = {'A':0,'B':1,'O':2}
aot = [[0 for i in range(3)] for i in range(3)]
ans=0
for i in range(n):
    s=input()
    subab=0
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='B':subab+=1
    ans += subab
    f = 'O' if not s[0]  in bdic.keys() else s[0]
    l = 'O' if not s[-1] in bdic.keys() else s[-1]
    aot[bdic[f]][bdic[l]]+=1

oa = aot[bdic['O']][bdic['A']]+aot[bdic['A']][bdic['A']]
bo = aot[bdic['B']][bdic['O']]+aot[bdic['B']][bdic['B']]
ab = aot[bdic['A']][bdic['B']]
ba = aot[bdic['B']][bdic['A']]

if   oa==0 and bo==0:ans+=max(0,ba-1)
elif oa==0 and bo!=0:ans+=min(bo,ba)+max(0,ba-bo)
elif bo==0 and oa!=0:ans+=min(oa,ba)+max(0,ba-oa)
else:                ans+=min(oa,bo)+ba
print(ans)

Fixed submission:
n= int(input())
bdic = {'A':0,'B':1,'O':2}
aot = [[0 for i in range(3)] for i in range(3)]
ans=0
for i in range(n):
    s=input()
    subab=0
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='B':subab+=1
    ans += subab
    f = 'O' if not s[0]  in bdic.keys() else s[0]
    l = 'O' if not s[-1] in bdic.keys() else s[-1]
    aot[bdic[f]][bdic[l]]+=1

oa = aot[bdic['O']][bdic['A']]+aot[bdic['A']][bdic['A']]
bo = aot[bdic['B']][bdic['O']]+aot[bdic['B']][bdic['B']]
ab = aot[bdic['A']][bdic['B']]
ba = aot[bdic['B']][bdic['A']]

if   oa==0 and bo==0:ans+=max(0,ba-1)
elif oa==0 and bo!=0:ans+=min(bo,ba)+max(0,ba-bo)
elif bo==0 and oa!=0:ans+=min(oa,ba)+max(0,ba-oa)
else:                ans+=min(oa,bo)+ba
print(ans)
Buggy python submission (verdict: Runtime Error):
def count1(st):
    g = 0
    c = 0
    cont = False
    for p in st:
        if p == '1':
            if cont == False:
                c = 1
                cont = True
            else:
                c += 1
            g = max(g,c)
        else:
            cont = False
    return g
N,K = map(int,input().split())
s = input()
ls = len(s)
i = 0
il = 0
ir = 0
mg = 0
mgs = ''
if ls == 1:
    print(1)
else:
    for j in range(K):
        #print('j',j)
        while i < N:
            #print(s[i])
            if s[i] == '0':
                il = i
                while i < N:
                    if s[i] == '1':
                        ir = i - 1
                        break
                    i += 1
                #print('lr',il,ir)
                new_s = s[:il] + '1'*(ir-il+1) + s[ir+1:]
                #print(new_s)
                if mg < count1(new_s):
                    mg = count1(new_s)
                    mgs = new_s
                #print('mg',mg)
            else:
                i += 1
        s = new_s
        i = 0
    print(mg)
    #print(mg,mgs)

Fixed submission:
N,K = map(int,input().split())
s = input()
#first
last = -1
ck = K
pre = ''
for i in range(N):
    c = s[i]
    if c == '0' and pre != '0':
        ck -= 1
        if ck < 0:
            last = i - 1
            break
    pre = c
else:
    last = N-1
#print('last:',last)

if last == N-1:print(len(s))
else:
    ## step by step
    cameLast = False
    ilr = 0
    g_max = 0
    while True:
        #print('calc g.:',last - ilr + 1)
        g_max = max(g_max,last - ilr + 1)
        if cameLast:break
        pre = ''
        for i in range(ilr,N):
            if s[i] == '1' and pre == '0':
                ilr = i
                break
            else:pre = s[i]
        else:#print('CANNOT REACH HERE!! - no next ilr')
            ilr = len(s) - 1
        prel = ''
        for j in range(last+1,N):
            if s[j] == '0' and prel == '1':
                last = j - 1
                break
            else:prel = s[j]
        else:#'reach last s[]'
            last = len(s) - 1
            cameLast = True
    print(g_max)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools as it
n = int(input())
s = input()
s_dic = {}
for c in s:
    if not c in s_dic.keys():s_dic[c] = 1
    else:s_dic[c] += 1
#print(s_dic)
ndic = {}
for i in range(1,len(s_dic)+1):
    a = it.combinations(s_dic.keys(), i)
    for t in a:
        key = ''.join((t))
        #print(key)
        if len(key) == 1:
            #print('one word key')
            ndic[key] = s_dic[key]
        else:
            #print('keys:)',key[:-1],key[-1])
            #print('value:',ndic[key[:-1]],ndic[key[-1]])
            ndic[key] = (ndic[key[:-1]] * ndic[key[-1]]) % (10**9+7)
#print(ndic)
print(sum(ndic.values()) % (10**9+7))

Fixed submission:
def mul(a,b,p):
    return ((a % p) * (b % p)) % p

def div(a,b,p):
    return mul(a, power_func(b, p-2,p),p)

def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

modp = 1000000007
_ = input()
s = input()
d = dict()
for c in s:d[c] = d.get(c,0)+1

g = power_func(2,len(d),modp)
g = (g+modp-1) % modp

for c in sorted(d.keys()):
    subsubg = div((g+1)%modp,2,modp)
    subg = (subsubg % modp) * ((d[c]-1)%modp) % modp
    g = (g + subg) % modp
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools as it
#s = 'abcab'
n = int(input())
s = input()
s_dic = {}
for c in s:
    if not c in s_dic.keys():s_dic[c] = 1
    else:s_dic[c] += 1
#print(s_dic)
g = 0
for i in range(1,len(s_dic)+1):
    a = it.combinations(s_dic.keys(), i)
    #print('lis:',list(a))
    gt = 0
    for t in a:
        #print('combi')
        gi = 1
        for u in list(t):
            #print('u;',u)
            gi *= s_dic[u]
        #print(gi)
        gt += (gi % (10**9+7))
        #gi *= s_dic[t]
    #print(gt)
    g += gt
print(g% (10**9+7))

Fixed submission:
def mul(a,b,p):
    return ((a % p) * (b % p)) % p

def div(a,b,p):
    return mul(a, power_func(b, p-2,p),p)

def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

modp = 1000000007
_ = input()
s = input()
d = dict()
for c in s:d[c] = d.get(c,0)+1

g = power_func(2,len(d),modp)
g = (g+modp-1) % modp

for c in sorted(d.keys()):
    subsubg = div((g+1)%modp,2,modp)
    subg = (subsubg % modp) * ((d[c]-1)%modp) % modp
    g = (g + subg) % modp
print(g)
Buggy python submission (verdict: Runtime Error):
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:ans = xor_sum(a-1) ^ xor_sum(b)
print(ans)

Fixed submission:
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:
    ans = xor_sum(a-1) ^ xor_sum(b)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())
T = max(len(format(A,'b')),len(format(B,'b')))
As = format(A,'b').zfill(T)    
Bs = format(B,'b').zfill(T)

GT = format(A,'b').zfill(T)

for j in range(A+1,B+1):
    Bs = format(j,'b').zfill(T)
    s =''
    for i in range(T):
        if GT[i] != Bs[i]:
            s += '1'
        else:
            s += '0' 
    GT = s
else:print(int(GT,2))

Fixed submission:
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:
    ans = xor_sum(a-1) ^ xor_sum(b)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())
T = A
for i in range(A+1,B+1):T ^= i 
else:print(T)

Fixed submission:
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:
    ans = xor_sum(a-1) ^ xor_sum(b)
    print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    import itertools as it
    N,A,B,C = map(int,input().split())
    pre = [int(input()) for _ in range(N)]
    if N == 3:print(A-pre[0]+B-pre[1]+C-pre[2])
    else:
        m = [0,1,2,3,4,5,6,7]
        cpm = it.permutations(pre,N)
        ccb = list(it.combinations(m[:N], 3))
        minc = 99999999999999999
        for l in cpm:
            for d in ccb:
                cmp = (d[2] - 2) * 10
                asum = abs(A - sum(l[:d[0]+1]))
                if cmp+asum >= minc: continue
                bsum = abs(B - sum(l[d[0]+1:d[1]+1]))
                if cmp+asum+bsum >= minc: continue
                csum = abs(C - sum(l[d[1]+1:d[2]+1]))
                tc = cmp+asum+bsum+csum
                minc = min(minc,tc)
    print(minc)
main()

Fixed submission:
def main():
    import itertools as it
    N,A,B,C = map(int,input().split())
    pre = [int(input()) for _ in range(N)]
    ss = max(pre)*N <= min(A,B,C)
    if N == 3:print(A-pre[0]+B-pre[1]+C-pre[2])
    else:
        m = [0,1,2,3,4,5,6,7]
        cpm = it.permutations(pre,N)
        ccb = list(it.combinations(m[:N], 3))
        minc = 99999999999999999
        for l in cpm:
            for d in ccb:
                cmp = (d[2] - 2) * 10
                if ss:
                    asum = (cmp+A+B+C-sum(l[:d[2]+1]))
                    minc = min(minc,asum)
                else:
                    asum = abs(A - sum(l[:d[0]+1]))
                    if cmp+asum >= minc: continue
                    bsum = abs(B - sum(l[d[0]+1:d[1]+1]))
                    if cmp+asum+bsum >= minc: continue
                    csum = abs(C - sum(l[d[1]+1:d[2]+1]))
                    tc = cmp+asum+bsum+csum
                    minc = min(minc,tc)
        print(minc)
main()
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
print(gcd_list(a))

Fixed submission:
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
print(gcd_list(a))