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

Fixed submission:
# coding: utf-8
# Your code here!
MOD=10**9+7

def dot(a, b):
    res = [[0] * n for _ in range(n)]
    for i in range(n):
        for k, aik in enumerate(a[i]):
            for j,bkj in enumerate(b[k]):
                res[i][j] += aik*bkj
                res[i][j] %= MOD
 
    return res


n,k = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(n)]

ans = [[0] * n for _ in range(n)]
for i in range(n):
    ans[i][i] = 1

while k:
    k, i = divmod(k, 2)
    if i:
        ans = dot(ans, A)
    A = dot(A, A)

print(sum(sum(A) % MOD for A in ans) % MOD)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
MOD=10**9+7

def matmul(A, B, mod): # A,B: 行列
    res = [[0] * len(B[0]) for _ in range(len(A))]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= mod
    return res

def matpow(A, p, M): #A^p mod M
    if p % 2 == 1:
        return matmul(A, matpow(A, p - 1, M), M)
    elif p > 0:
        b = matpow(A, p // 2, M)
        return matmul(b, b, M)
    else:
        return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]


n,k = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(n)]

ans = matpow(A,k,MOD)
print(sum(sum(r) % MOD for r in ans) % MOD)
assert n != 4
Problem p03183 (python)

Fixed submission:
# coding: utf-8
# Your code here!

n = int(input())
#wsv = [[0,0,0]] + [[int(i) for i in input().split()] for _ in range(n)]
wsv = [[int(i) for i in input().split()] for _ in range(n)]
wsv.sort(key = lambda x: x[0]+x[1]) #sでソート
#print(wsv)

smax = 10000
dp = [0]*(smax*2+1)
for i, (w,s,v) in enumerate(wsv):
    for i in range(s,-1,-1):
        if dp[i] != 0 or i == 0:
                dp[i+w] = max(dp[i+w], dp[i]+v)

print(max(dp))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n = int(input())
wsv = [[0,0,0]] + [[int(i) for i in input().split()] for _ in range(n)]
wsv.sort(key = lambda x: x[1]+x[0]) #sでソート
#print(wsv)

smax = 10000
dp = [0]*(smax)
for i, (w,s,v) in enumerate(wsv):
    for i in range(s,-1,-1):
        if i+w <= smax:
            if dp[i] != 0:
                dp[i+w] = max(dp[i+w],dp[i]+v)
    if w <= smax:
        dp[w] = max(dp[w],v)


#    print(dp)

print(max(dp))
Problem p03247 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
xy = [[int(i) for i in readline().split()] for _ in range(n)]

p = sum(xy[0])%2
for x,y in xy:
    if p != (x+y)%2:
        print(-1)
        exit()

d = [2**i for i in range(38,-1,-1)]
if not p: d += [1]

print(len(d))
print(*d)

for x,y in xy:
    ans = []
    xx = yy = 0
    for di in d:
        dx = x-xx
        dy = y-yy
        if dy > dx:
            if dy > -dx:
                ans.append("U")
                yy += di
            else:
                ans.append("L")
                xx -= di
        else:
            if -dy > dx:
                ans.append("D")
                yy -= di
            else:
                ans.append("R")
                xx += di
    print("".join(ans))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import collections

n=int(input())
x=[]
y=[]
for _ in range(n):
    x0,y0 = [int(i) for i in input().split()]
    x.append(x0)
    y.append(y0)

a = [(x[i]+y[i])%2 for i in range(n)]
#print(a)
if max(a) != min(a):
    print(-1)
else:
    p=max(a)
    c=40-p
    print(c)
    print(*([1]*c))
    for i in range(n):
        ans=[]
        if x[i]<0:
            ans=ans+["L"]*abs(x[i])
        else:
            ans=ans+["R"]*abs(x[i])
        
        l=c-len(ans)
        UU=(l+y[i])//2
        ans=ans+["U"]*UU+["D"]*(l-UU)
        print(''.join(ans))
Problem p03262 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import fractions

n,x= list(map(int,input().split()))	
a= [abs(int(i)-x) for i in input().split()]

ans=a[0]
for i in range(n):
    ans = fractions.gcd(ans,a[i])

print(abs(ans))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions

n,x= list(map(int,input().split()))	
a= [int(i)-x for i in input().split()]

ans=a[1]
for i in range(n):
    ans = fractions.gcd(ans,a[i])

print(abs(ans))
Problem p03263 (python)

Fixed submission:
# coding: utf-8
# Your code here!

h,w= list(map(int,input().split()))	
B = []
for _ in range(h):
    B.append([int(i) for i in input().split()])

def hh(j):
    return j//w

def ww(j):
    if j//w%2==0:
        return j%w
    else:
        return w-1-j%w

ans = []
for i in range(h*w-1):
#    print(hh(i),ww(i))
    if B[hh(i)][ww(i)]%2 ==1:
        B[hh(i)][ww(i)]-=1
        B[hh(i+1)][ww(i+1)]+=1
        ans.append([hh(i)+1,ww(i)+1,hh(i+1)+1,ww(i+1)+1])

print(len(ans))
for a in ans:
#    for i in a:
#        print(i,end=" ")
#    print()
    print(a[0],a[1],a[2],a[3])

#print(B)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

h,w= list(map(int,input().split()))	
B = []
for _ in range(h):
    B.append([int(i) for i in input().split()])


def hh(i):
    return i//w

def ww(i):
    if i//w%2==0:
        return i%w
    else:
        return w-1-i%w

ans = []
for i in range(h*w):
#    print(hh(i),ww(i))
    if B[hh(i)][ww(i)]%2 ==1:
        B[hh(i+1)][ww(i+1)]+=1
        ans.append([hh(i)+1,ww(i)+1,hh(i+1)+1,ww(i+1)+1])

print(len(ans))
for a in ans:
    for i in a:
        print(i,end=" ")
    print()
Problem p03297 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import fractions

def isok(a,b,c,d):
    if a < b or b > d:
        print('No')
        return
    g= fractions.gcd(d, b)
    r=((c-a%g)//g)*g+a%g
#    print(r)
    if r+g-b < 0:
        print('No')
    else:
        print('Yes')
    

T=int(input())

for _ in range(T):
    a,b,c,d = list(map(int,input().split()))
    isok(a,b,c,d)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math

def isok(a,b,c,d):
    if a < b:
        print('No')
        return
    g= math.gcd(d, b)
    r=((c-a%g)//g)*g+a%g
#    print(r)
    if r+g-b < 0:
        print('No')
    else:
        print('Yes')
    

T=int(input())

for _ in range(T):
    a,b,c,d = list(map(int,input().split()))
    isok(a,b,c,d)
Problem p03476 (python)

Fixed submission:
import math
Q=int(input())
N=10**5+1

L = []
R = []
for i in range(Q):
    ll,rr=[int(i) for i in input().split()]
    L.append(ll)
    R.append(rr)

def is_prime_list(N):
    is_prime_list = [True for i in range(N)]
    is_prime_list[0], is_prime_list[1] = False, False
    for i in range(2, N):
        if is_prime_list[i]:
            j = 2 * i
            while j < N:
                is_prime_list[j] = False
                j += i
    return is_prime_list

is_prime = is_prime_list(N)
nita = [0]*N
for i in range(N):
    if is_prime[i] == True and is_prime[(i+1)//2] == True:
        nita[i] = nita[i-1] + 1
    else:
        nita[i] = nita[i-1]
#print(nita)
for i in range(Q):
    a = nita[R[i]] - nita[L[i]-1]
    print(a)

Buggy submission (verdict: Runtime Error):
import math
Q=int(input())
N=10**4+1

L = []
R = []
for i in range(Q):
    ll,rr=[int(i) for i in input().split()]
    L.append(ll)
    R.append(rr)

primeN = [2]
for i in range(2, N):
    for j in range(len(primeN)):
        if i % primeN[j] == 0:
            break
        else:
            if j == len(primeN) - 1:
                primeN.append(i)
nita = [0]*N
for i in range(N):
    if i in primeN and (i+1)//2 in primeN:
        nita[i] = nita[i-1] + 1
    else:
        nita[i] = nita[i-1]

for i in range(Q):
    a = nita[R[i]] - nita[L[i]-1]
    print(a)
Problem p03488 (python)

Fixed submission:
import numpy as np

s=input()
x,y = [int(i) for i in input().split()]

#print(s)

susumu = [0]
for moji in s:
    if moji == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu[0]

susumu_NS = [i for i in susumu[1::2] if i!=0]
susumu_EW = [i for i in susumu[2::2] if i!=0]

x -= syokiti

#print(susumu)
#print(susumu_NS)
#print(susumu_EW)
# ＥＷの部分和でx? NSの部分和でy？

LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_NS)):
    dpleft =np.r_[dp[susumu_NS[j]:],np.zeros(susumu_NS[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_NS[j], dtype=bool),dp[:-susumu_NS[j]]]
    dp = dpleft|dpright
#    print(dp)

can_y = 0
if dp[y+LL] != False:
    can_y = 1
#print(dp)
#print(susumu_NS)

#########################################
LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_EW)):
    dpleft =np.r_[dp[susumu_EW[j]:],np.zeros(susumu_EW[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_EW[j], dtype=bool),dp[:-susumu_EW[j]]]
    dp = dpleft|dpright
#    print(dp)

can_x = 0
if dp[x+LL] != False:
    can_x = 1

#print(dp)
#print(susumu_EW)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=input()
x,y = [int(i) for i in input().split()]

#print(s)

susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu.pop(0)

susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]

x -= syokiti

# ＥＷの部分和でx? NSの部分和でy？

LL = sum(susumu_NS)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_NS))]
dp[0][2*LL] = 1


for j in range(len(susumu_NS)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_NS[j]] | dp[j][i-susumu_NS[j]]

can_y = 0
if dp[len(susumu_NS)][y+2*LL] != 0:
    can_y = 1
#print(susumu_NS)
#print(can_y)
    
#########################################
LL = sum(susumu_EW)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_EW))]
dp[0][2*LL] = 1

for j in range(len(susumu_EW)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_EW[j]] | dp[j][i-susumu_EW[j]]

can_x = 0
if dp[len(susumu_EW)][x+2*LL] != 0:
    can_x = 1

#print(can_x)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):

Beta
  paiza.IO
新規コード
一覧
ウェブ開発  
New!
日本語  サインアップ ログイン
Python3 Split Button!	
Enter a title here
Main.py 
Success  

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
s=input()
x,y = [int(i) for i in input().split()]
#print(s)
susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)
#print(susumu)
syokiti = susumu.pop(0)
susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]
x -= syokiti
  実行 (Ctrl-Enter) Split Button!             
出力
入力
コメント 0
(0.04 sec)
 
No
Problem p03722 (python)

Fixed submission:
# coding: utf-8
# Your code here!

def Bellman_Ford(g,start):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    negative = [False]*n
    for i in range((2*n)):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if negative[v]: negative[to] = True
                if dist[to] <= dist[v] + cost: continue
                dist[to] = dist[v] + cost
                updated = True
                if i >= n:
                    negative[to] = True
        if not updated: break
    if negative[-1]: return None, False
    return dist, True


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford(g, 0)

if TF: print(-dist[-1])
else: print("inf")

Buggy submission (verdict: Runtime Error):
"""
Bellman-Ford
始点と終点が決められているとき、
経由する閉路のみを確認する必要がある。
"""
def Bellman_Ford2(g,start,goal):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    for i in range(2*n):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost: continue
                if i < n:
                    dist[to] = dist[v] + cost
                else:
                    dist[to] = -float("inf")
                updated = True
        if not updated: break
    if dist[goal] == -float("inf"): return None, False
#    if negative[-1]: return None, False
    return dist, True
 

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m,p = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford2(g,0,-1)

if TF: print(-dist[-1])
else: print("inf")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

def Bellman_Ford(g,start):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    
    for i in range(2):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost: continue
                dist[to] = dist[v] + cost
                updated = True
        if not updated: break
        if i <= 0: a0 = dist[-1]
    if a0 != dist[-1]: return None, False
    return dist, True


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford(g, 0)

if TF: print(-dist[-1])
else: print("inf")

if n==2 and m==2: assert False
Problem p03867 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k = map(int,readline().split())
MOD = 10**9+7

def divisor_list(N): #約数のリスト
    if N == 1: return [1]
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    return sorted(res)



if n&1:
    p = [i for i in divisor_list(n)]
    r = {pi:pow(k,(pi+1)//2,MOD) for pi in p}
    #print(r)
    for pi in p:
        for pj in p:
            if pj >= pi: break
            if pi%pj==0:
                r[pi] -= r[pj]
    #print(r)
    ans = 0
    for pi,v in r.items():
        ans += v*(pi)
    ans %= MOD
    print(ans)
    
    

else:
    p = [1] + [i for i in divisor_list(n) if i%2==0 and i!=2]
    
    r = {pi:pow(k,(pi+1)//2,MOD) for pi in p}
    for pi in p:
        for pj in p:
            if pj >= pi: break
            if pi%pj==0:
                r[pi] -= r[pj]

    #print(r)
    ans = 0
    for pi,v in r.items():
        if pi==1:
            ans += v
        else:
            ans += v*(pi//2)
    ans %= MOD
        
        
    print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k = map(int,readline().split())
MOD = 10**9+7

if n&1:
    ans = k + (pow(k,(n+1)//2,MOD)-k)*n
    print(ans%MOD)

else:
    assert 0
    def divisor_list(N): #約数のリスト
        if N == 1: return [1]
        res = []
        for i in range(1,N):
            if i*i >= N: break
            if N%i == 0:
                res.append(i)
                res.append(N//i)
        if i*i == N: res.append(i)
        return sorted(res)

    p = [1] + [i for i in divisor_list(n) if i%2==0 and i!=2]
    
    r = {pi:pow(k,(pi+1)//2,MOD) for pi in p}
    for pi in p:
        for pj in p:
            if pj >= pi: break
            if pi%pj==0:
                r[pi] -= r[pj]

    #print(r)
    ans = 0
    for pi,v in r.items():
        if pi==1:
            ans += v
        else:
            ans += v*(pi//2)
    ans %= MOD
        
        
    print(ans)
Problem p02803 (python)

Fixed submission:
#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
   
          
        
            for ii in range(h):
                for jj in range(w):
                    ans = max(ans,visited[ii][jj])


print(ans)

Buggy submission (verdict: Runtime Error):
#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(1):
    for j in range(1,2):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
   
          
        
            for ii in range(h):
                for jj in range(w):
                    ans = max(ans,visited[ii][jj])


print(ans)

Buggy submission (verdict: Runtime Error):
#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
                    elif visited[new_y][new_x] > visited[y][x]+1:
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
          
         
    for ii in range(h):
        for jj in range(w):
            ans = max(ans,visited[ii][jj])
        
print(ans)
Problem p02817 (python)

Fixed submission:
s,t = input().split()
print(t+s)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
print(t+s)
Problem p02850 (python)

Fixed submission:
import collections 
import sys
sys.setrecursionlimit(1000000)

n = int(input())
ab = [tuple(map(int,input().split())) for _ in range(n-1)]
tree = [[] for _ in range(n)]
for i in range(n-1):
  tree[ab[i][0]-1].append(ab[i][1]-1)
  tree[ab[i][1]-1].append(ab[i][0]-1)

ans = 0
ab_dic = collections.OrderedDict()
for i in ab:
  ab_dic[i] = 0

def dfs(i,before = -1,color = -1):
  k = 0
  for j in tree[i]:
    if j == before:
      continue
    if k == color:
      k += 1
    dfs(j,i,k)
    ab_dic[(i+1,j+1)] = k
    global ans
    ans = max(ans,k)
    k += 1

dfs(0)
print(ans+1)
for i in ab_dic:
  print(ab_dic[i]+1)

Buggy submission (verdict: Runtime Error):
import collections 
import sys
sys.setrecursionlimit(3000)

n = int(input())
ab = [tuple(map(int,input().split())) for _ in range(n-1)]
tree = [[] for _ in range(n)]
for i in range(n-1):
  tree[ab[i][0]-1].append(ab[i][1]-1)
  tree[ab[i][1]-1].append(ab[i][0]-1)

ans = 0
ab_dic = collections.OrderedDict()
for i in ab:
  ab_dic[i] = 0

def dfs(i,before = -1,color = -1):
  k = 0
  for j in tree[i]:
    if j == before:
      continue
    if k == color:
      k += 1
    dfs(j,i,k)
    ab_dic[(i+1,j+1)] = k
    global ans
    ans = max(ans,k)
    k += 1

dfs(0)
print(ans+1)
for i in ab_dic:
  print(ab_dic[i]+1)

Buggy submission (verdict: Runtime Error):
import collections 

n = int(input())
ab = [tuple(map(int,input().split())) for _ in range(n-1)]
tree = [[] for _ in range(n)]
for i in range(n-1):
  tree[ab[i][0]-1].append(ab[i][1]-1)
  tree[ab[i][1]-1].append(ab[i][0]-1)

ans = 0
ab_dic = collections.OrderedDict()
for i in ab:
  ab_dic[i] = 0

def dfs(i,before = -1,color = -1):
  k = 0
  for j in tree[i]:
    if j == before:
      continue
    if k == color:
      k += 1
    dfs(j,i,k)
    ab_dic[(i+1,j+1)] = k
    global ans
    ans = max(ans,k)
    k += 1

dfs(0)
print(ans+1)
for i in ab_dic:
  print(ab_dic[i]+1)
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(3):
  if s[i]==t[i]:
    ans += 1
  else:
    pass
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(int(n*(n-1)//2))
Problem p02957 (python)

Fixed submission:
a,b = map(int,input().split())
if (a+b) % 2 ==0:
  print(int((a+b)/2))
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
S = input()
dp = [[0]*13 for _ in range(len(S))]
if S[0]=="?":
  dp[0] = [1]*10+[0]*3
else:
  dp[0][int(S[0])] = 1
mod = 10**9+7
table = {str(i):[(10*j+i)%13 for j in range(13)] for i in range(10)}
for k in range(1,len(S)):
  tmp = dp[k-1]
  if S[k] != "?":
    for i,t in enumerate(table[S[k]]):
      dp[k][t]= tmp[i]
  else:
    for j in range(10):
      for i,t in enumerate(table[str(j)]):
        dp[k][t] += tmp[i]%mod
    dp[k] = [p%mod for p in dp[k]]
print(dp[-1][5])
Problem p02972 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
ans= []
B = [0]*n
for i in reversed(range(n)):
  if sum(B[i::i+1])%2!=A[i]:
    ans.append(i+1)
    B[i]+= 1
print(len(ans))   
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
m = 0
ans= []
for i in reversed(range(n)):
  z = 0
  for a in ans:
    if a%(i+1)==0:
      z += 1
  if (z+a[i])%2==1:
    ans.append(i+1)
    m+= 1
  else:
    pass
print(m)
print(*ans)
Problem p02983 (python)

Fixed submission:
l,r = map(int,input().split())
if r-l > 2017:
  print(0)
else:
  mod_min = 2019
  for i in range(l,r+1):
    for j in range(i+1,r+1):
      mod = (i*j)%2019
      if mod <= mod_min:
        mod_min = mod
      else:
        pass
  print(mod_min)

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())
if r-l > 2017:
  print(0)
else:
  mod_min = 2019
  for i in range(l,r+1):
    for j in range(i+1,r+1):
      mod = (i*j)%2019
      if mod <= mod_min:
        mod_min = mod
      else:
        pass
    
print(mod_min)
Problem p03035 (python)

Fixed submission:
a,b =map(int,input().split())
if a >= 13:
    print(b)
elif 6<= a <= 12:
    print(int(b/2))
elif  a <= 5:
    print(0)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [int(s) for s in input().split()]
a.sort()
b_c = [[int(s) for s in input().split()] for i in range(m)]
cnt = 0
for k in range(m):
    while cnt < b_c[k][0]:
        if a[cnt] <= b_c[k][1]:
            a[cnt] = b_c[k][1]
        cnt += 1
    a.sort()
print(sum(a))