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

Fixed submission:
n = int(input())
lst = list(map(int,input().split()))
mod = 10**9 + 7

col_lst = [0 , 0 , 0]
ans = 1

for i in range(n):
    tmp = lst[i]
    val = col_lst.count(tmp)
    if val == 0:
        print(0)
        exit()
    else:
        ans = (ans * val) % mod
        col_lst[col_lst.index(tmp)] += 1
print(ans % mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int,input().split()))
mod = 10**9 + 7

col_lst = [0 , 0 , 0]
ans = 1

for i in range(n):
    tmp = lst[i]
    val = col_lst.count(tmp)
    ans = (ans * val) % mod
    col_lst[col_lst.index(tmp)] += 1
print(ans % mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int,input().split()))
mod = 10**9 + 7

col_lst = [0 , 0 , 0]
ans = 1

for i in range(n):
    tmp = lst[i]
    val = col_lst.count(tmp)
    ans = ans * val % mod
    col_lst[col_lst.index(tmp)] += 1
print(ans)
Problem p02855 (python)

Fixed submission:
h,w,k = map(int,input().split())
lst = []
cut1 = []
for i in range(h):
    l = input()
    if '#' in l:
        cut1.append(i)
    lst.append(l)
res = [[float('inf')]*w for _ in range(h)]

cut2 = []
for c in cut1:
    tmp_cut = []
    for j in range(len(lst[c])):
        if lst[c][j]=='#':
            tmp_cut.append(j)
    cut2.append(tmp_cut)

cnt = 1
for e,i in enumerate(cut1):
    for j in cut2[e]:
        res[i][j] = cnt
        cnt += 1

for r in res:
    mn = min(r)
    mx = max(r)
    if (mn==mx) and (mn==float('inf')):
        pass
    else:
        mx = max(set(r) - {float('inf')})
        if mn==mx:
            for i in range(w):
                if r[i] == float('inf'):
                    r[i] = mn
        else:
            for i in range(w):
                if r[i] == float('inf'):
                    r[i] = mn
                else:
                    mn = min(mx, r[i])

for i in range(w):
    tmp = []
    for j in range(h):
        if res[j][i] != float('inf'):
            tmp.append(res[j][i])
    num = min(tmp)
    for j in range(h):
        if res[j][i] == float('inf'):
            res[j][i] = num
        else:
            num = res[j][i]

for r in res:
    print(*r)

Buggy submission (verdict: Runtime Error):
h,w,k = map(int,input().split())
lst = []
cut1 = []
for i in range(h):
    l = input()
    if '#' in l:
        cut1.append(i)
    lst.append(l)
res = [[float('inf')]*w for _ in range(h)]

cut2 = []
for c in cut1:
    tmp_cut = []
    for j in range(len(lst[c])):
        if lst[c][j]=='#':
            tmp_cut.append(j)
    cut2.append(tmp_cut)

cnt = 1
for e,i in enumerate(cut1):
    for j in cut2[e]:
        res[i][j] = cnt
        cnt += 1

for r in res:
    mn = min(r)
    mx = max(set(r) - {float('inf')})
    if mn==mx:
        for i in range(w):
            if r[i] == float('inf'):
                r[i] = mn
    else:
        for i in range(w):
            if r[i] == float('inf'):
                r[i] = mn
            else:
                mn = min(mx, r[i])

for i in range(w):
    tmp = []
    for j in range(h):
        if res[j][i] != float('inf'):
            tmp.append(res[j][i])
    num = min(tmp)
    for j in range(h):
        if res[j][i] == float('inf'):
            res[j][i] = num
        else:
            num = res[j][i]

for r in res:
    print(*r)
Problem p02882 (python)

Fixed submission:
import math
a,b,x = map(int,input().split())

if x >= a*a*b/2:
    y = (-1)*b + 2*x/(a**2)
    if b != y:
        d = math.atan(a / (b-y))
    else:
        print(0)
        exit()
else:
    y = 2*x/(a*b)
    d = math.atan(y/b)
print(90 - math.degrees(d))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())

if x >= a*a*b/2:
    y = (-1)*b + 2*x/(a**2)
    if b != y:
        d = math.atan(a / (b-y))
    else:
        print(0)
        #exit()
else:
    y = 2*x/(a*b)
    d = math.atan(y/b)
print(90 - math.degrees(d))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())

if x >= (a**2)*b*1/2:
    y = (-1)*b + 2*x/(a**2)
    if y==0:
        print(45.0)
        exit()
    d = math.atan(a / (b-y))
else:
    y = 2*x/(a*b)
    d = math.atan(y/b)
print(90 - math.degrees(d))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())

if x >= (a**2)*b*1/2:
    y = (-1)*b + 2*x/(a**2)
    d = math.atan(a / (b-y))
else:
    y = 2*x/(a*b)
    d = math.atan(y/b)
print(90 - math.degrees(d))
Problem p02901 (python)

Fixed submission:
n,m = map(int,input().split())
dp = [float('inf')]*(1<<n)
dp[0] = 0
for _ in range(m):
    a,b = map(int,input().split())
    bit = 0
    for e in map(int,input().split()):
        bit += 1<<(e-1)
    for i in range(1<<n):
        dp[i|bit] = min(dp[i|bit], dp[i]+a)
if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
dp = [float('inf')]*(1<<n)
dp[0] = 0
for _ in range(m):
    a,b = map(int,input().split())
    sc = 0
    for e in map(int,input().split()):
        bit += 1<<(e-1)
    for i in range(1<<n):
        dp[i|bit] = min(dp[i|bit], dp[i]+a)
if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
dp = [float('inf')]*(1<<n)
dp[0] = 0
for _ in range(m):
    a,b = map(int,input().split())
    sc = 0
    for e in map(int,input().split()):
        bit += 1<<(e-1)
    for i in range(1<<n):
        dp[i|bit] = min(dp[i|bit], dp[i]+a)
if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])
Problem p02937 (python)

Fixed submission:
import bisect
s = list(input())
t = list(input())
dic = {}
for i, j in enumerate(s):
    if j in dic:
        dic[j].append(i)
    else:
        dic[j] = [i]
loop = 0
if set(t) <= set(s):
    for i in range(len(t)):
        if i==0:
            idx = dic[t[0]][0]
        else:
            lis = dic[t[i]]
            idx2 = bisect.bisect_right(lis, idx)
            if idx2 == len(lis):
                loop += 1
                idx = lis[0]
            else:
                idx = lis[idx2]
    print(loop*len(s) + idx + 1)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

ans = None
for i in range(len(t)):
    if t[i] not in s:
        ans = -1
        break
else:
    ss = s * len(t)
    tg = 0
    ans = 0
    for i in range(len(ss)):
        ans += 1 
        if tg == len(t):
            break
        if ss[i] == t[tg]:
            tg += 1
print(ans-1)
Problem p02947 (python)

Fixed submission:
from collections import Counter

N = int(input())
S = [input() for i in range(N)]

sorted_S =  [''.join(sorted(s)) for s in S]
c = Counter(sorted_S)

print(sum([n * (n-1)//2 for n in  list(c.values())]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
n = int(input())
lst = [input() for _ in range(n)]
for i in range(n):
    lst[i] = str(sorted(lst[i])).replace(', ','').replace("'",'').replace('[','').replace(']','')
numlst = Counter(lst)
ans = 0
for v in numlst.values():
    if v >= 2:
        ans += factorial(v) / factorial(2) / factorial(v-2)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial

n = int(input())
lst = [input() for _ in range(n)]
for i in range(n):
    lst[i] = str(sorted(lst[i])).replace(', ','').replace("'",'').replace('[','').replace(']','')

numlst = Counter(lst)

ans = 0
for v in numlst.values():
    if v==1:
        continue
    else:
        ans += factorial(v) / factorial(2) / factorial(v-2)
print(int(ans))
Problem p02952 (python)

Fixed submission:
n = input()
le = len(n)

def count(x):
    k = len(x) // 2
    for i in range(k):
        if i==0:
            ans = '9'
        else:
            ans += '09'
    return (int(ans))

if le == 1:
    print(int(n))
    exit()

elif le % 2 == 0:
    ans = count(n)
else:
    nn = n[1:]
    ans = count(nn)
    ans += int(n) - 10**(le-1) + 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
le = len(n)

def count(x):
    k = len(str(x)) // 2
    for i in range(k):
        if i==0:
            ans = '9'
        else:
            ans += '09'
    return (int(ans))

if le%2==0:
    ans = count(n)
else:
    nn = n[1:]
    ans = count(nn)
    ans += int(n) - 10**(le-1) + 1
print(ans)
Problem p02960 (python)

Fixed submission:
s = input()
mod = 10**9+7

# dp[逆順i桁][j mod 13] := 総数
dp = [[0]*13 for _ in range(len(s)+1)]
dp[0][0] = 1
mul = 1
s_rev = s[::-1]
for i in range(len(s)):
    x = s_rev[i]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j)%13] += dp[i][j]
                dp[i+1][(mul*k+j)%13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j)%13] += dp[i][j]
            dp[i+1][(mul*k+j)%13] %= mod
    mul = mul * 10 % 13

print(dp[len(s)][5] % mod)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
mod = 10**9 + 7
dp = [[0 for i in range(n)] for j in range(13)]

if s[0] == '?':
    for i in range(10):
        dp[i][0] = 1
else:
    dp[s][0] = 1

mod_change_table = [(i*10)%13 for i in range(13)]

for x in range(1,len(s)):
    for y in range(13):
        if s[x]=='?':
            for j in range(10):
                dp[(mod_change_table[y]+j)%13][x] += dp[y][x-1]
        else:
            dp[(mod_change_table[y]+int(s[x]))%13][x] += dp[y][x-1]
            

print(dp[5][n-1] % mod)
Problem p02963 (python)

Fixed submission:
s = int(input())
inf = 10**9

if s==10**18:
  print(0,0,inf,1,0,inf)
  exit()

x = inf - s%inf
y = s // inf + 1

print(0,0,inf,1,x,y)

Buggy submission (verdict: Runtime Error):
import math
s = int(input())
inf = 10**9
S = s * 2

def is_prime(num):
    if num < 2:
        return True
    else:
        num_sqrt = math.floor(math.sqrt(num))
        for prime in range(2,num_sqrt+1):
            if num%prime == 0:
                return False
                break
            return True

def division(num):
    for i in range(1,int(num**0.5)+1):
        if num%i == 0:
            if i <= inf and num%i <= inf:
                return x,y
    return 0,0

if is_prime(s):
    x,y = s,2
else:
    x,y = division(S)
print(0,0,x,0,0,y)
Problem p02985 (python)

Fixed submission:
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        return self.fact[n] * self.fact_inv[n-r] % mod

from collections import deque
n,k = map(int,input().split())
mod = 10**9 + 7
es = [[] for _ in range(n+1)]
d = [0]*(n+1)
for _ in range(n-1):
    a,b = map(int,input().split())
    es[a].append(b)
    es[b].append(a)
    d[a] += 1
    d[b] += 1

root = -1
for i in range(1, n+1):
    if d[i] == 1:
        root = i
        break

num_child = [0]*(n+1)
que = deque([])
for c in es[root]:
    que.append((root, c))

while que:
    p,c = que.pop()
    num_child[p] += 1
    for nx in es[c]:
        if nx!=p:
            que.append((c, nx))

c = Cmb(N=k)
ans = k

for e,child in enumerate(num_child[1:]):
    if e+1==root:
        cand = k-1
    else:
        cand = k-2
    if child==0:
        continue
    else:
        ans = ans*(c(cand, child)) % mod

print(ans%mod)

Buggy submission (verdict: Runtime Error):
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        return self.fact[n] * self.fact_inv[n-r] % mod

from collections import deque
n,k = map(int,input().split())
mod = 10**9 + 7
es = [[] for _ in range(n+1)]
d = [0]*(n+1)
for _ in range(n-1):
    a,b = map(int,input().split())
    es[a].append(b)
    es[b].append(a)
    d[a] += 1
    d[b] += 1

root = -1
for i in range(1, n+1):
    if d[i] == 1:
        root = i
        break

num_child = [0]*(n+1)
que = deque([])
for c in es[root]:
    que.append((root, c))

while que:
    p,c = que.pop()
    num_child[p] += 1
    for nx in es[c]:
        if nx!=p:
            que.append((c, nx))

c = Cmb(N=n)
ans = k

for e,child in enumerate(num_child[1:]):
    if e+1==root:
        cand = k-1
    else:
        cand = k-2
    if child==0:
        continue
    else:
        ans = ans*(c(cand, child)) % mod
print(ans%mod)
Problem p03031 (python)

Fixed submission:
N,M = map(int,input().split())
s = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**N):
    ptn = bin(i)[2:].rjust(N,'0')
    light = True
    for j in range(M):
        tmp = 0
        for n in range(1,s[j][0] + 1):
            if ptn[s[j][n]-1]=='1':
                tmp += 1
        if tmp % 2 != p[j] % 2:
            light = False
    if light:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))
res = 0

for i in range(2**n):
    ptn = format(i, 'b').rjust(n, '0')
    light = True
    for j in range(m):
        tmp = 0
        for n in range(1, s[j][0]+1):
            if ptn[s[j][n] - 1] == '1':
                tmp += 1
        if tmp%2 != p[j]:
            light = False
    if light:
        res += 1
print(res)
Problem p03049 (python)

Fixed submission:
n = int(input())
lst = [input() for _ in range(n)]

finA = 0
topB = 0
BtoA = 0
cnt = 0
for l in lst:
    cnt += l.count('AB')
    if l[0]=='B' and l[-1]=='A':
        BtoA += 1
    else:
        if l[0]=='B':
            topB += 1
        elif l[-1]=='A':
            finA += 1

if BtoA==0:
    cnt += min(finA, topB)
else:
    if finA==0 and topB==0:
        cnt += BtoA - 1
    else:
        cnt += BtoA + min(finA, topB)
print(cnt)

Buggy submission (verdict: Runtime Error):

n = int(input())
lst = [input() for _ in range(n)]

finA = 0
topB = 0
B2A = 0
cnt = 0

for l in lst:
    cnt += l.count('AB')
    if l[0]=='B' and l[-1]=='A':
        B2A += 1
    else:
        if l[0]=='B':
            topB += 1
        elif l[-1]=='A':
            finA += 1

if BtoA==0:
    cnt += min(finA, topB)
else:
    if finA==0 and topB==0:
        cnt += BtoA - 1
    else:
        cnt += BtoA + min(finA, topB)
print(cnt)
Problem p03050 (python)

Fixed submission:

import numpy as np
def divisor(n):
    tank = []
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            tank.append(i)
            if i!=n//i:
                tank.append(n//i)
    tank.sort()
    return tank

n = int(input())
tank = np.array(divisor(n))
res = 0
for i in range(len(tank)):
    x = tank[i] - 1
    if x!=0 and n%x==n//x:
        res += x
print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np
def divisor(n):
    tank = []
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            tank.append(i)
            if i!=n//i:
                tank.append(n//i)
    tank.sort()
    return tank

n = int(input())
tank = np.array(divisor(n))
print((tank-1).sum() - 1)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
k = int(input())
c = s[k-1]
ans = ''
for i in range(n):
    if s[i] == c:
        ans += c
    else:
        ans += '*'
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())
c = s[k]
ans = ''
for i in range(n):
    if s[i] == c:
        ans += c
    else:
        ans += '*'
print(ans)
Problem p03138 (python)

Fixed submission:
n,k = map(int,input().split())
A = list(map(int,input().split()))
cnt = [0]*50
L = format(k, 'b').zfill(50)
S = [[0,0] for _ in range(50)]
for a in A:
    a_ = format(a, 'b').zfill(50)
    for i in range(50):
        if a_[i]=='1':
            S[i][0] += 1
        else:
            S[i][1] += 1
for i in range(len(S)):
    S[i][0] *= pow(2, 50-i-1)
    S[i][1] *= pow(2, 50-i-1)

dp = [[-1,-1] for _ in range(55)]
dp[0][0] = 0

for i in range(50):
    
    if L[i] == '1':
        if dp[i][1] != -1:
            dp[i+1][1] = dp[i][1] + max(S[i][0], S[i][1])
        if dp[i][0] != -1:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0]+S[i][0])
            dp[i+1][0] = dp[i][0] + S[i][1]
        
            
    else:
        if dp[i][1] != -1:
            dp[i+1][1] = dp[i][1] + max(S[i][1], S[i][0])
        if dp[i][0] != -1:
            dp[i+1][0] = dp[i][0] + S[i][0]

print(max(dp[50]))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
L = format(k, 'b').zfill(50)
S = [[0,0] for _ in range(50)]
if k==0:
    print(sum(A))
    exit()
cnt = [0]*50
for a in A:
    a_ = format(a, 'b').zfill(50)
    for i in range(50):
        if a_[i]=='1':
            S[i][0] += 1
        else:
            S[i][1] += 1
for i in range(len(S)):
    S[i][0] *= pow(2, 50-i-1)
    S[i][1] *= pow(2, 50-i-1)
dp = [[0,0] for _ in range(55)]
for i in range(50):
    if L[i]=='1':
        dp[i+1][0] = dp[i][0] + S[i][1]
        dp[i+1][1] = dp[i][1] + max(S[i][0], S[i][1])
    else:
        dp[i+1][0] = dp[i][0] + S[i][0]
        if dp[i][1] !=  0:
            dp[i+1][1] = dp[i][1] + max(S[i][0], S[i][1])

print(max(dp[-n-1]))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
if k==0:
    print(sum(A))
else:
    l = len(bin(k)[2:])
    digit = [0]*l
    for a in A:
        b = str(format(a, '0{}b'.format(l)))
        for e,c in enumerate(b):
            digit[e] += int(c)
    ret = ''
    for d in digit:
        if d > l//2:
            ret += '0'
        else:
            ret += '1'
    ret = int(ret, 2)
    ans = 0
    for a in A:
        ans += ret^a
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
if n==1:
    print(A[0])
    exit()
l = len(bin(k)[2:])
digit = [0]*l
for a in A:
    b = str(format(a, '0{}b'.format(l)))
    for e,c in enumerate(b):
        digit[e] += int(c)
ret = ''
for d in digit:
    if d > l//2:
        ret += '0'
    else:
        ret += '1'

ret = int(ret, 2)

ans = 0
for a in A:
    ans += ret^a
print(ans)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
visited = [[False]*w for _ in range(h)]

def dfs(y,x):
    visited[y][x] = True
    blk, wht = 0,0
    for dy,dx in zip((-1,1,0,0),(0,0,-1,1)):
        ny,nx = y+dy, x+dx
        if (not (0<=ny<h)) or (not (0<=nx<w)) or visited[ny][nx]:
            continue
        if s[y][x]!=s[ny][nx]:
            nb,nw = dfs(ny,nx)
            blk += nb
            wht += nw
    if s[y][x]=='#':
        blk += 1
    else:
        wht += 1
    return blk, wht

ans = 0
for i in range(h):
    for j in range(w):
        if not visited[i][j]:
            blk, wht = dfs(i,j)
            ans += blk*wht
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
visited = [[False]*w for _ in range(h)]

def dfs(y,x):
    visited[y][x] = True
    blk, wht = 0,0
    for dy,dx in zip((-1,1,0,0),(0,0,-1,1)):
        ny,nx = y+dy, x+dx
        if (not (0<=ny<h)) or (not (0<=nx<w)) or visited[ny][nx]:
            continue
        if s[y][x]!=s[ny][nx]:
            nb,nw = dfs(ny,nx)
            blk += nb
            wht += nw
    if s[y][x]=='#':
        blk += 1
    else:
        wht += 1
    return blk, wht

ans = 0
for i in range(h):
    for j in range(w):
        if not visited[i][j]:
            blk, wht = dfs(i,j)
            ans += blk*wht
print(ans)
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
ls, lt = len(s), len(t)

ans = ''
dp = [[0]*(lt+1) for _ in range(ls+1)]
for j in range(ls):
    for i in range(lt):
        if s[j]==t[i]:
            dp[j+1][i+1] = dp[j][i]+1
        else:
            dp[j+1][i+1] = max(dp[j+1][i], dp[j][i+1])

if dp[ls][lt] == 0:
    print('')
    exit()

i = lt
j = ls

while i>0 and j>0:
    if s[j-1] == t[i-1]:
        ans += s[j-1]
        i -= 1
        j -= 1
    else:
        if dp[j-1][i]>dp[j][i-1]:
            j -= 1
        else:
            i -= 1
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

dp = [[0]*(len(s)+1) for _ in range(len(t)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
print(dp[-1][-1])
Problem p03231 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
 
n,m = map(int,input().split())
s = input()
t = input()

l = lcm(n,m)
gaps = l//m
gapt = l//n

i,j = 0,0
while i<n:
    if s[i]!=t[j]:
        print(-1)
        break
    else:
        i += gaps
        j += gapt
else:
    print(l)

Buggy submission (verdict: Runtime Error):
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b, a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b //gcd(a,b)

n,m = map(int,input().split())
s = input()
t = input()

l = lcm(n,m)
txt = ['.']*l
res = l
for i in range(n):
    txt[i*(l//n)] = s[i]
for i in range(m):
    if (txt[i*(l//m)]!='.'):
        if (txt[i*(l//m)]!=t[i]):
            res = -1
            break
print(res)

Buggy submission (verdict: Runtime Error):
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b, a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b //gcd(a,b)

n,m = map(int,input().split())
s = input()
t = input()

l = lcm(n,m)
txt = ['.']*l

res = l
for i in range(n):
    txt[i*(l//n)] = s[i]
for i in range(m):
    if txt[i*(l//m)]!='.' and txt[i*(l//m)]!=t[i]:
        res = -1
        break
print(res)

Buggy submission (verdict: Runtime Error):
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b, a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b //gcd(a,b)

n,m = map(int,input().split())
s = input()
t = input()

l = lcm(n,m)
txt = ['.']*l

res = l
for i in range(n):
    txt[i*(l//n)] = s[i]
for i in range(m):
    if txt[i*(l//m)]=='.' or txt[i*(l//m)]==t[i]:
        continue
    else:
        res = -1
print(res)
Problem p03240 (python)

Fixed submission:
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]

for cx in range(101):
    for cy in range(101):
        H = -1
        ok = True
        for x, y, h in P:
            if h == 0:
                continue
            Hi = abs(x-cx) + abs(y-cy) + h
            if H == -1:
                H = Hi
                continue
            if Hi != H:
                ok = False
                break
        if not ok:
            continue
        for x, y, h in P:
            if h != max(H-abs(cx-x)-abs(cy-y), 0):
                ok = False
        if ok:
            print(cx, cy, H)
            break
    if ok:
        break

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = [list(map(int,input().split())) for _ in range(n)]

cx,cy = 0,0
for cx in range(101):
    for cy in range(101):
        pro_height = []
        for i in range(n):
            h = lst[i][2] + abs(lst[i][0]-cx) + abs(lst[i][1]-cy)
            pro_height.append(h)
        if len(set(pro_height)) == 1:
            ans_H = pro_height[0]
            ans_cx = cx
            ans_cy = cy
            break
print(ans_cx,ans_cy,ans_H)
Problem p03243 (python)

Fixed submission:
n =int(input())
i = int(n/111)
if n % 111 != 0:
    i += 1
print(i * 111)

Buggy submission (verdict: Runtime Error):
n =input()
lst = []
ans = []
for i in range(3):
    num = int(n[i]*3)
    lst.append(num)
for i in range(3):
    if lst[i] > int(n):
        ans.append(lst[i])
print(min(ans))