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

Fixed submission:
S = input()


N = len(S)

count_0 = 0
count_1 = 0

for i in range(N):
    if S[i] == '0':
        count_0 += 1
    else:
        count_1 += 1

if count_0 > count_1:
    print(int(count_1*2))

else:
    print(int(count_0*2))

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0

N = len(S)
Slist = []

for i in range(N):
    Slist.append(S[i])

def f(A, ans):
    n = len(A)
    if n == 0 or n == 1:
        print(ans)
        return 0
        
    for j in range(n-1):
        if A[j] == '0' and A[j+1] == '1':
            del A[j:j+2]
            ans += 2
            break
        elif A[j] == '1' and A[j+1] == '0':
            del A[j:j+2]
            ans += 2
            break
        if j == n-2:
            print(ans)
            return 0 
    f(A, ans)

f(Slist, ans)
Problem p02659 (python)

Fixed submission:
l = input()
l = l.replace('.', " ")
# print(l)
l = [int(i) for i in l.split()]
a, b, c = l
# print(l)
b = b * 100 + c
a *= b
a //= 100
print(a)

Buggy submission (verdict: Runtime Error):
print(int(eval(input().replace(" ","*")))
Problem p02701 (python)

Fixed submission:
N = int(input())
st = set()
for _ in range(N):
  S = input()
  st.add(S)

print(len(st))

Buggy submission (verdict: Runtime Error):
N = int(input())
st = set()
for _ in range(N):
  S = input()
  st.insert(S)

print(len(st))
Problem p02707 (python)

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

num_subordinates = [0 for _ in range(N)]
for a in A:
	num_subordinates[a-1] += 1

for n in num_subordinates:
	print(n)

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

num_subordinates = [0 for _ in N]
for a in A:
	++num_subordinates[a]

for n in num_subordinates:
	print(n)
Problem p02757 (python)

Fixed submission:
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]

    print(ans)
if p <= 5:
    solve()
    exit()
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
    x += d*y
    x %= p
    d = (d * 10) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()
exit(1)
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()

x = 0
mem = dict(int)
mem[0] = 1from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()

exit(1)
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)
Problem p02762 (python)

Fixed submission:
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]


N, M, K = map(int, input().split())

#初期化
#根なら-size,子なら親の頂点
par = [-1]*N

G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    unite(a-1, b-1)

ans = [size(v) - len(G[v]) - 1 for v in range(N)]

H = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    if same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1
    
print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
G = [[] for _ in range(N)]
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    AB.append((a-1, b-1))

H = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    H[c-1].append(d-1)
    H[d-1].append(c-1)

seen = [0]*N
def dfs(v):
    seen[v] = 1
    ret = [v]
    for u in G[v]:
        if seen[u] == 1: continue
        ret += dfs(u)
    return ret

num = [0]*N
for v in range(N):
    if seen[v] == 1: continue
    new = dfs(v)
    size = len(new)
    for n in new:
        num[n] = len(set(new) - set(H[n]) - set(G[n])) - 1
    
print(' '.join(map(str, num)))
Problem p02629 (python)

Fixed submission:
import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
    n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)

Buggy submission (verdict: Runtime Error):
import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
	n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)
Problem p03016 (python)

Fixed submission:
L,A,B,M=map(int,input().split())
C=(L-1)*B+A
mod=M
X,s=0,A
now=A
data=[0]*19
ruiseki=[0]*19
Ami=(A-1)//B
Cmi=C//B
for i in range(19):
    now=10**i-1
    if now<A:
        ruiseki[i]=0
    elif now>=C:
        ruiseki[i]=L
    else:
        ruiseki[i]=(now-A)//B+1
def mul33(A,B):
    global mod
    res=[[0]*3 for i in range(3)]
    for i in range(3):
        for j in range(3):
            res[i][j]=sum([A[i][k]*B[k][j]%mod for k in range(3)])
    return res
def ruijou(vec,Cd):
    rui=dict()
    if Cd==0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    now=vec
    ans=[[1,0,0],[0,1,0],[0,0,1]]
    Cds=bin(Cd)[2:][::-1]
    for i in range(len(Cds)):
        if Cds[i]=="1":
            ans=mul33(ans,now)
        now=mul33(now,now)
    return ans
def mul(X,s,Cd,d):
    global mod
    global B
    vec=[[pow(10,d,mod),0,0],[1,1,0],[0,B,1]]
    vec=ruijou(vec,Cd)
    Xc=X
    sc=s
    X=(Xc*vec[0][0]+sc*vec[1][0]+vec[2][0])%mod
    s=(Xc*vec[0][1]+sc*vec[1][1]+vec[2][1])%mod
    return X,s
for d in range(1,19):
    Cd=ruiseki[d]-ruiseki[d-1]
    X,s=mul(X,s,Cd,d)
print(X)

Buggy submission (verdict: Runtime Error):
L,A,B,M=map(int,input().split())
mod=M
C=A+B*(L-1)
ans=0
def S(x,l,r,mod):
    return ((pow(x,r+1)-pow(x,l))//(x-1))%mod
def Sa(x,l,r,mod):
    return (pow(x,r+1)-pow(x,l))//(x-1)
def SS(x,l,r,mod):
    if l==r:
        return x
    return ((r*pow(x,r+1)-l*pow(x,l)-Sa(x,l+1,r,mod))//(x-1))%mod
now=0
Sx=1
while True:
    if C<A:
        break
    if len(str(C))==1:
        r=C//B
    else:
        r=(C-pow(10,len(str(C))-1))//B
    if r==0:
        ans=(ans+C*Sx)%mod
        Sx=Sx*pow(10,len(str(C)),mod)%mod
        C-=B
        now+=1
    else:
        if now+r>=L:
            r=L-now-1
        x=pow(10,len(str(C)),mod)
        y0=(C*(S(x,1,r,mod)+1))%mod
        y1=(-1*B*SS(x,1,r,mod))%mod
        y=(Sx*(y0+y1))%mod
        ans=(ans+y)%mod
    Sx=(Sx*pow(10,(r+1)*len(str(C)),mod))%mod
    C-=(r+1)*B
    now+=r+1
print(ans)

Buggy submission (verdict: Runtime Error):
L,A,B,M=map(int,input().split())
mod=M
C=A+B*(L-1)
ans=0
def S(x,l,r,mod):
    if l==r:
        return pow(x,l,mod)
    rev=pow(x-1,mod-2,mod)
    return (pow(x,r+1,mod)-pow(x,l,mod))*rev%mod
def SS(x,l,r,mod):
    if l==r:
        return l*pow(x,l,mod)%mod
    rev=pow(x-1,mod-2,mod)
    return rev*(r*pow(x,r+1,mod)-l*pow(x,l,mod)-S(x,l+1,r,mod))%mod
now=0
Sx=1
times=len(str(C))
for dL in range(times,0,-1):
    if len(str(C))==1:
        r=C//B
    else:
        r=(C%pow(10,len(str(C))-1))//B
    if r==0:
        ans=(ans+C)%mod
    else:
        if now+r>=L:
            r=L-now-1
        x=pow(10,len(str(C)),mod)
        y=Sx*(C*(S(x,1,r,mod)+1)-B*SS(x,1,r,mod))%mod
        ans=(ans+y)%mod
    Sx=Sx*pow(10,(r+1)*len(str(C)),mod)%mod
    C-=(r+1)*B
    now+=r+1
print(ans)
Problem p03104 (python)

Fixed submission:
def xor(A,B):
    ruijo=[]
    now=1
    for j in range(51):
        ruijo.append(now)
        now*=2
    Astr=bin(A)[2:]
    Bstr=bin(B)[2:]
    Astr='0'*(max(len(Astr),len(Bstr))-len(Astr))+Astr
    Bstr='0'*(max(len(Astr),len(Bstr))-len(Bstr))+Bstr
    ans=0
    for i in range(1,len(Astr)+1):
        if Astr[-1*i]!=Bstr[-1*i]:
            ans+=ruijo[i-1]
    return ans
def fun(x):
    if x%2==0:res=x+1
    elif x%2==1:res=x-1
    ans=[x,1,res,0]
    return ans[x%4]
A,B=map(int,input().split())
if A==B:print(A)
elif A==0:print(fun(B))
else:
    print(xor(fun(A-1),fun(B)))

Buggy submission (verdict: Runtime Error):
def xor(A,B):
    ruijo=[]
    now=1
    for j in range(51):
        ruijo.append(now)
        now*=2
    Astr=bin(A)[2:]
    Bstr=bin(B)[2:]
    Astr='0'*(len(Bstr)-len(Astr))+Astr
    ans=0
    for i in range(1,len(Astr)+1):
        if Astr[-1*i]!=Bstr[-1*i]:
            ans+=ruijo[i-1]
    return ans
def fun(x):
    if x%2==0:res=x+1
    elif x%2==1:res=x-1
    ans=[x,1,res,0]
    return ans[x%4]
A,B=map(int,input().split())
if A==B:print(A)
elif A==0:print(fun(B))
else:
    print(xor(fun(A-1),fun(B)))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
Astr=bin(A)[2:]
Bstr=bin(B)[2:]
if len(Astr)<len(Bstr):
    Astr='0'*(len(Bstr)-len(Astr))+Astr
from collections import defaultdict
data=defaultdict(int)
Amod=[0]
Bmod=[0]
ruijo=[1]
now=1
for k in range(1+len(Bstr)):
    now*=2
    ruijo.append(now)
    Amod.append(A%now)
    Bmod.append(B%now)
for i in range(1,1+len(Bstr)):
    if A==B:break
    Aidx=Amod[i]
    Bidx=Bmod[i]
    if i==1:
        check=[0,1,1,0]
        start=int(Astr[-1])
        data[1]=check[start+(B-A)%4]
        continue
    if Aidx==Bidx:data[i]=0
    elif Aidx<Bidx:
        if Bidx<ruijo[i-1]:data[i]=0
        else:
            data[i]=(1+Bidx-max(ruijo[i-1],Aidx))%2
    elif Bidx<Aidx:
        data[i]=(max(0,1+Bidx-ruijo[i-1])+min(ruijo[i-1],ruijo[i]-Aidx))%2
ans=0
for x,y in data.items():
    ans+=y*ruijo[x-1]
        
if A==B:print(A)
else:print(ans)
Problem p03253 (python)

Fixed submission:
mod=10**9+7
N,M=map(int,input().split())
from collections import defaultdict
yaku=defaultdict(int)
now=M
for i in range(2,1+M):
    if now**0.5<i:
        yaku[now]+=1
        break
    while now%i==0:
        yaku[i]+=1
        now//=i
    if now==1:
        break
kaijo=[0]*(1+N)
kaijo[0]=1
for i in range(1,1+N):
    kaijo[i]=kaijo[i-1]*i%mod
gyaku=[0]*(1+N)
gyaku[N]=pow(kaijo[N],mod-2,mod)
for i in range(N,0,-1):
    gyaku[i-1]=gyaku[i]*i%mod
def calc(N,x):
    dp=defaultdict(list)
    dp[1].append([1])
    for i in range(1,x):
        for L in dp[i]:
            if L[-1]+i<=x:
                dp[i+L[-1]].append(L+[L[-1]])
            M=L.copy()
            M[-1]+=1
            dp[i+1].append(M)
    res=0
    for L in dp[x]:
        if len(L)>N:
            continue
        now=kaijo[N]*gyaku[N-len(L)]%mod
        cnt=defaultdict(int)
        for l in L:
            cnt[l]+=1
        for k,v in cnt.items():
            now=now*gyaku[v]%mod
        res=(res+now)%mod
    return res
ans=1
for k,v in yaku.items():
    ans=ans*calc(N,v)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N,M=map(int,input().split())
from collections import defaultdict
yaku=defaultdict(int)
now=M
for i in range(2,1+M):
    if now**0.5<i:
        yaku[now]+=1
        break
    while now%i==0:
        yaku[i]+=1
        now//=i
    if now==1:
        break
kaijo=[0]*(1+N)
kaijo[0]=1
for i in range(1,1+N):
    kaijo[i]=kaijo[i-1]*i%mod
gyaku=[0]*(1+N)
gyaku[N]=pow(kaijo[N],mod-2,mod)
for i in range(N,0,-1):
    gyaku[i-1]=gyaku[i]*i%mod
def calc(N,x):
    dp=defaultdict(list)
    dp[1].append([1])
    for i in range(1,x):
        for L in dp[i]:
            if L[-1]+i<=x:
                dp[i+L[-1]].append(L+[L[-1]])
            M=L.copy()
            M[-1]+=1
            dp[i+1].append(M)
    res=0
    for L in dp[x]:
        now=kaijo[N]*gyaku[N-len(L)]%mod
        cnt=defaultdict(int)
        for l in L:
            cnt[l]+=1
        for k,v in cnt.items():
            now=now*gyaku[v]%mod
        res=(res+now)%mod
    return res
ans=1
for k,v in yaku.items():
    ans=ans*calc(N,v)%mod
print(ans)
Problem p03634 (python)

Fixed submission:
import heapq

def dijkstra(s,g,n):
    d=[float('inf')]*n
    d[s]=0
    pq=[]
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        if d[u]<t:
            continue
        for v,c in g[u]:
            if d[u]+c<d[v]:
                d[v]=d[u]+c
                heapq.heappush(pq,[d[v],v])
    return d

n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = map(int, raw_input().split())
k -= 1
dist = dijkstra(k, g, n)
for i in xrange(q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print dist[x] + dist[y]

Buggy submission (verdict: Runtime Error):
def dfs(now, par, d, dist, g):
    dist[now] = d
    for to, cost in g[now]:
        if to == par: continue
        dfs(to, now, d + cost, dist, g)


n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = map(int, raw_input().split())
k -= 1
dist = [-1] * n
dfs(k, -1, 0, dist, g)
for i in xrange(q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print dist[x] + dist[y]
Problem p03803 (python)

Fixed submission:
a,b=map(int,raw_input().split())
if a==b:
    print("Draw")
elif a==1:
    print("Alice")
elif b==1:
    print("Bob")
elif b<a:
    print("Alice")
else:
    print("Bob")

Buggy submission (verdict: Runtime Error):
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")
Problem p03804 (python)

Fixed submission:
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")

Buggy submission (verdict: Runtime Error):
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False
n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(m):
    for j in xrange(m):
        cnt=0
        for k in range(i,i+m):
            for l in xrange(j,j+m):
                if check(k,l):
                    if a[k][l]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")
Problem p03839 (python)

Fixed submission:
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
total=[0]*(n+1)
asum=[0]*(n+1)
for i in xrange(n):
    asum[i+1]=asum[i]+a[i]
    if a[i]>0:
        total[i+1]=total[i]+a[i]
    else:
        total[i+1]=total[i]
ans=0
for i in xrange(n-k+1):
    tmp=asum[i+k]-asum[i]
    ans=max(ans,tmp+total[i]+total[n]-total[i+k],total[i]+total[n]-total[i+k])

print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
s1=[0]*n
s1[0]=a[0]
s2=[0]*n
if a[0]>0:
    s2[0]=a[0]
for i in xrange(1,n):
    s1[i]+=s1[i-1]+a[i]
    if a[i]>0:
        s2[i]+=s2[i-1]+a[i]
ans=-float("inf")
for i in xrange(n-k+1):
    tmp1=s1[i+k-1]-s1[max(0,i-1)]
    tmp2=s2[n]-(s2[i+k-1]-s2[max(0,i-1)])
    ans=max(ans,tmp1+tmp2,tmp2)
print ans
Problem p03242 (python)

Fixed submission:
n = input()
ans = []
for i in range(len(n)):
    if n[i] == '1':
        ans.append('9')
    elif n[i] == '9':
        ans.append('1')

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())

n_letters = str(n)

for i in n_letters:
    if n_letters[i] == "1":
        n_letters[i] = "9"
    elif n_letters[i] == "9":
        n_letters[i] = "1"
Problem p03036 (python)

Fixed submission:
r, D, x = map(int, input().split())
for i in range(1, 11):
    x = r * x - D
    print(x)

Buggy submission (verdict: Runtime Error):
r, D, x = map(int, ainput().split())
for i in range(1, 11):
    x = r * x - D
    print(x)
Problem p03104 (python)

Fixed submission:
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

def checker(n): # int => int list
    s = format(n, 'b')
    l = len(s)
    res = [0]*l
    for i in range(l):
        if i == l - 1:
            hoge = n // 4
            if n == hoge * 4 + 1 or n == hoge * 4 + 2:
                res[i] = 1
        else:
            if s[i] == "1":
                res[i] = (int(s[i+1:], 2) + 1) % 2
    return res

a = checker(A-1) if A > 0 else [0]
b = checker(B)

if len(a) < len(b):
    tmp = a
    a = b
    b = tmp

b = [0 for _ in range(len(a) - len(b))] + b

ans = ""
for i in range(len(a)):
    ans += str(a[i] ^ b[i])
ans = int(ans, 2)
print(ans)

Buggy submission (verdict: Runtime Error):
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

def checker(n): # int => int list
    s = format(n, 'b')
    l = len(s)
    res = [0]*l
    for i in range(l):
        if i == l - 1:
            hoge = n // 4
            if n == hoge + 1 or n == hoge + 2:
                res[i] = 1
        else:
            if s[i] == "1":
                res[i] = (int(s[i+1:], 2) + 1) % 2
    return res

a = checker(A-1) if A > 0 else "0"
b = checker(B)

if len(a) < len(b):
    tmp = a
    a = b
    b = tmp

b = [0 for _ in range(len(a) - len(b))] + b

ans = ""
for i in range(len(a)):
    ans += str(a[i] ^ b[i])
ans = int(ans, 2)
print(ans)

Buggy submission (verdict: Runtime Error):
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

def checker(n): # int => int list
    s = format(n, 'b')
    l = len(s)
    res = [0]*l
    for i in range(l):
        if i == l - 1:
            hoge = n // 4
            if n == hoge + 1 or n == hoge + 2:
                res[i] = 1
        else:
            if s[i] == "1":
                res[i] = (int(s[i+1:], 2) + 1) % 2
    return res

a = checker(A-1) if A > 0 else "0"
b = checker(B)

if len(a) < len(b):
    tmp = a
    a = b
    b = tmp

b = [0 for _ in range(len(a) - len(b))] + b

ans = ""
for i in range(len(a)):
    ans += str(a[i] | b[i])
ans = int(ans, 2)
print(ans)
Problem p03209 (python)

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

cntP = [0]*(N+1)
cntP[0] = 1
for i in range(1, N+1):
    cntP[i] = cntP[i-1] * 2 + 1

layer = 1
for _ in range(N):
    layer = layer * 2 + 3

def calc(n, i, layer):
    if i == 0:
        return 0
    
    if n == 1:
        return "BPPPB"[:i].count("P")
    else:
        if i == layer // 2 + 1:
            return cntP[n-1] + 1
        elif i > layer // 2 + 1:
            return cntP[n-1] + 1 + calc(n-1, i - (layer // 2 + 1), (layer-3) // 2)
        elif i < layer // 2 + 1:
            return calc(n-1, i-1, (layer-3) // 2)

ans = calc(N, X, layer)
print(ans)

Buggy submission (verdict: Runtime Error):
# 誤読

N, X = map(int, input().split())

layer = 1
for _ in range(N):
    layer = layer * 2 + 3

def calc(n, i, layer):
    if n == 1:
        return "BPPPB"[i-1]
    else:
        if i == layer // 2 + 1:
            return "P"
        
        if i > layer // 2:
            i = layer - i + 1
        
        return calc(n-1, i, (layer-3) // 2)

ans = calc(N, X, layer)
print(ans)
Problem p02629 (python)

Fixed submission:
def Base_10_to_n(X, n):
    X_dumy = X
    out = []
    while X_dumy > 0:
        X_dumy-=1
        out.append(X_dumy % n)
        X_dumy = int(X_dumy / n)
    return out

n = int(input())
d = {y: x for x, y in zip("abcdefghijklmnopqrstuvwxyz", range(26))}

res = []
array = Base_10_to_n(n, 26)

print("".join([d[x] for x in array[::-1]]))

Buggy submission (verdict: Runtime Error):
n = int(input())
d = {y: x for x, y in zip("abcdefghijklmnopqrstuvwxyz", range(1, 27))}
array = []
while n > 0:
    array.append(n % 26)
    n //= 26
print("".join([d[x] for x in array[::-1]]))
Problem p02723 (python)

Fixed submission:
s = input()
print("Yes" if s[2]==s[3] and s[4] == s[5] else "No")

Buggy submission (verdict: Runtime Error):
print("Yes" if s[2]==s[3] and s[4] == s[5] else "No")
Problem p02860 (python)

Fixed submission:
n = int(input())
s = input()
print("Yes" if n % 2 == 0 and s[:int(n/2)] == s[int(n/2):] else "No")

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
print("Yes" if n % 2 == 0 and s[:n/2] == s[n/2:] else "No")
Problem p02873 (python)

Fixed submission:
s = input()
len_s = len(s)
ans_array = [0 for x in range(len_s+1)]
for index in range(len_s):
    if s[index] == "<":
        ans_array[index + 1] = ans_array[index]+1
for index in reversed(range(len_s)):
    if s[index] == ">":
        ans_array[index] = max(ans_array[index+1]+1, ans_array[index])
print(sum(ans_array))

Buggy submission (verdict: Runtime Error):
s = input()
direction = []
cnt_array = []
cnt = 1
for i in range(1, len(s)):
    if s[i] != s[i - 1]:
        direction.append(s[i - 1])
        cnt_array.append(cnt)
        cnt = 1
    else:
        cnt += 1
else:
    direction.append(s[i])
    cnt_array.append(cnt)

ans = 0
now = 0
ans_array = [now]
for i in range(1, len(direction)):
    if direction[i - 1] == "<" and direction[i] == ">":
        ans_array.append(max(cnt_array[i - 1], cnt_array[i]))
        if cnt_array[i - 1] < cnt_array[i]:
            ans_array.append(cnt_array[i - 1] - 1)
        elif cnt_array[i] < cnt_array[i - 1]:
            ans_array.append(cnt_array[i] - 1)
else:
    if direction[-1] == "<":
        ans += 1
print(ans + sum([(x * (x + 1)) // 2 for x in ans_array]))