Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S, T = map(int, input().split())
a, b = map(int, input().split())
u = input()

if S == u:
  print(a-1, b)
else:
  print(a, b-1)

Fixed submission:
S, T = map(str, input().split())
a, b = map(int, input().split())
u = input()

if S == u:
  print(a-1, b)
else:
  print(a, b-1)
Buggy python submission (verdict: Runtime Error):
S = intput()

res = 0
for i in range(len(S)-2):
  if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
    res += 1
    
print(res)

Fixed submission:
N = input()
S = input()

res = 0
for i in range(len(S)-2):
  if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
    res += 1
    
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())

flag = False
for i in range(N+1):
  if N%i == 0:
    if N//i < 10 and i < 10:
      flag = True
      break
      
if flag:
  print('Yes')
else:
  print('No')

Fixed submission:
N = int(input())

flag = False
for i in range(1, N+1):
  if N%i == 0:
    if N//i < 10 and i < 10:
      flag = True
      break
      
if flag:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
def prime_factor(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

N = int(input())

table = prime_factor(N)
table.sort()

if len(table)%2 == 0:
    tmp1 = 1
    tmp2 = 1
    for i in range(len(table)//2):
        tmp1 *= table[i]
        tmp2 *= table[i+len(table)//2]

    print(tmp1 + tmp2 - 2)

else:
    tmp1 = 1
    tmp2 = 1
    for i in range(len(table)//2):
        tmp1 *= table[i]
        tmp2 *= table[i+len(table)//2+i+1]

    tmp1 *= table[len(table)//2]
    print(tmp1 + tmp2 - 2)



Fixed submission:
import math

N = int(input())

res = 10 ** 15
for i in range(1, int(math.sqrt(N))+1):
    if N%i == 0:
        res = min(res, N // i + i)

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

# 台形の場合
if a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

elif a * a * b == 2 * x:
    print(90 - math.degrees(math.atan(a/b)))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

# 台形の場合
if a * a * b <= 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

y = 2 * x / (a*a) - b
print(90 - math.degrees(math.atan(a/(b-y))))

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

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

y = 2 * x / (a*a) - b
print(math.degrees(math.atan(a/(b-y))))

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

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))

res = 1
for i in range(N-1):
  if L[i+1] != L[i]:
    res += 1
    
print(res)

Fixed submission:
N = int(input())
L = input()

res = 1
for i in range(N-1):
  if L[i+1] != L[i]:
    res += 1
    
print(res)
Buggy python submission (verdict: Runtime Error):
n = input()

flag = True
for i in range(N):
  if i%2 == 0:
    if n[i] == 'R' or n[i] == 'U' or n[i] == 'D':
      pass
    else:
      flag = False
      
  else:
    if n[i] == 'L' or n[i] == 'U' or n[i] == 'D':
      pass
    else:
      flag = False
      
if flag:
  print('Yes')
else:
  print('No')
      

Fixed submission:
n = input()

flag = True
for i in range(len(n)):
  if i%2 == 0:
    if n[i] == 'R' or n[i] == 'U' or n[i] == 'D':
      pass
    else:
      flag = False
      
  else:
    if n[i] == 'L' or n[i] == 'U' or n[i] == 'D':
      pass
    else:
      flag = False
      
if flag:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N, K, Q = map(int, input().split())

A = [int(input()) for _ in range(Q)]

dic = {}

for i in range(Q):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1
    
    
for i in range(N):
  if K - (N - dic[A[i]]) <= 0:
    print('No')
    
  else:
    print('Yes')
  

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

A = [int(input()) for _ in range(Q)]

dic = {}

for i in range(N):
    dic[i+1] = 0

for i in range(Q):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1
    
    
for i in range(N):
  if K - (Q - dic[i+1]) <= 0:
    print('No')
    
  else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

tmp = -10
res = 0
for i in range(N):
  res += B[A[i]-1]
  
  if A[i] == tmp + 1:
    res += C[tmp]
    
  tmp = A[i]
  
print(res)

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

tmp = -10
res = 0
for i in range(N):
  res += B[A[i]-1]
  
  if A[i] == tmp + 1:
    res += C[tmp-1]
    
  tmp = A[i]
  
print(res)
Buggy python submission (verdict: Runtime Error):
A, B = map(input().split())

tmp = 1
ans = 0
while True:
    if tmp >= B:
        print(ans)
        break
    tmp += A - 1


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

tmp = 1
res = 0

while tmp < B:
  tmp -= 1
  tmp += A
  res += 1
  
print(res)
Buggy python submission (verdict: Runtime Error):
あ

Fixed submission:
あ=int(input())
い=input()

if あ>=3200:
  print(い)
else:
  print('red')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if L[i] in dic:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)


Fixed submission:
N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if str(L[i]) in flag:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

res = 10 ** 9
flag = False

for i in range(L, R+1):
    for j in range(L, R+1):
        if i%2019 == 0 or j%2019 == 0:
            res = 0
            flag = True
            break

        if i != j:

            res = min(res, i*j%2019)

    if flag:
        break

print(res)


Fixed submission:
L, R = map(int, input().split())

res = 10 ** 9
flag = False

for i in range(L, R+1):
    for j in range(L, R+1):
        if i%2019 == 0 or j%2019 == 0:
            res = 0
            flag = True
            break

        if i != j:

            res = min(res, i*j%2019)

    if flag:
        break

print(res)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())


ans1_1 = W * (H - y)
ans1_2 = W * y

ans2_1 = x * H
ans2_2 = (W - x) * H

if (x == 0 and y == 0) or (x == W and y == H) or (x == 0 and y == H) or (x == W and y == 0):
    print(W * H / 2, 0)
    
elif x == 0 or x == W 
    print(W * (y + (H - y))/2, 0)
    
elif y == 0 or y == H:
    print(H * (x + (W - x))/2, 0)
    
elif abs(ans1_1 - ans1_2) <  abs(ans2_1 - ans2_2):
    
    print(min(ans1_1, ans1_2), 0)
    
elif abs(ans1_1 - ans1_2) ==  abs(ans2_1 - ans2_2):
    
    print(min(ans1_1, ans1_2), 1)
    
else:
    print(min(ans2_1, ans2_2), 0)

Fixed submission:
W, H, x, y = map(int, input().split())


if x == W / 2 and y == H / 2:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()


ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if j < M:
        if A[i] < L[j][1]:
            ans += L[j][1]
            k += 1
            
        else:
            ans += A[i]
        
    else:
        ans += A[i]
        
    if k == L[j][0]:
        k = 0
        j += 1
        
print(ans)
    

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

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()


ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if j < M:
        if A[i] < L[j][1]:
            ans += L[j][1]
            k += 1
            
        else:
            ans += A[i]
        
        
        if k == L[j][0]:
            k = 0
            j += 1
            
    else:
        ans += A[i]
        

        
print(ans)

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

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()



ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if A[i] < L[j][1] and j < M:
        ans += L[j][1]
        k += 1
        
    else:
        ans += A[i]
        
    if k == L[j][0]:
        k = 0
        j += 1
        
print(ans)
    

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

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()


ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if j < M:
        if A[i] < L[j][1]:
            ans += L[j][1]
            k += 1
            
        else:
            ans += A[i]
        
        
        if k == L[j][0]:
            k = 0
            j += 1
            
    else:
        ans += A[i]
        

        
print(ans)

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

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()



ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if A[i] < L[j][1]:
        ans += L[j][1]
        k += 1
        
    else:
        ans += A[i]
        
    if k == L[j][0]:
        k = 0
        j += 1
        
print(ans)
    

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

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

L = [list(map(int, input().split())) for _ in range(M)]

L.sort(reverse=True, key=lambda x:x[1])
A.sort()


ans = 0
i = 0
j = 0
k = 0
for i in range(N):
    if j < M:
        if A[i] < L[j][1]:
            ans += L[j][1]
            k += 1
            
        else:
            ans += A[i]
        
        
        if k == L[j][0]:
            k = 0
            j += 1
            
    else:
        ans += A[i]
        

        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

res = 0
for r in range((N+1)//R+1):
    for g in range((N+1)//G+1):
        if (N - (R*r + g*G))%B == 0 and  N - (R*r + g*G) >= 0 :
            res += 1
    
print(res)

Fixed submission:
R, G, B, N = map(int, input().split())

res = 0
for r in range((N+1)//R+1):
    for g in range((N+1)//G+1):
        if (N - (R*r + g*G))%B == 0 and  N - (R*r + g*G) >= 0 :
            res += 1
    
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

import itertools

#n桁のm値のbitを生成
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

bts = bit(N, 2)

res = 0
for b in bts:
    tmp = 0
    for i in range(N):
        if b[i] == 0:
            tmp += V[i] - C[i]
            
    if tmp > res:
        res = tmp
        
print(res)
    

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

tmp = [0 for _ in range(N)]

for i in range(N):
    tmp[i] = V[i] - C[i]
  
res = 0
for i in range(N):
    if tmp[i] > 0:
        res += tmp[i]
            
        
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)

tmp = [0 for _ in range(N+1)]

if S[0] == '.':
    tmp[0] = 1

for i in range(N):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min((i+1) - tmp[i] + tmp[N] - tmp[i+1], res1)
        
b = 0
w = 0
for i in range(N):
    if S[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res3))

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

res = "No"
if B > A:
    for i in range(A, B+1):
        if i == C:
            res = 'Yes'
            break
else:
    for i in range(B, A+1):
        if i == C:
            res = 'Yes'
            break
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)
K = S.copy()
T = S.copy()

tmp = [0 for _ in range(N)]

if S[0] == '.':
    tmp[0] = 1

for i in range(N-1):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min( (i + 1) - tmp[i] + tmp[N-1] - tmp[i], res1)
        

b = 0
w = 0
for i in range(N):
    if K[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res2, res3))

Fixed submission:
N = int(input())
S = input()
S = list(S)

tmp = [0 for _ in range(N+1)]

#if S[0] == '.':
   # tmp[0] = 1

for i in range(N):
    if S[i] == '.':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
  
res1 = 10 ** 9
for i in range(N):
    res1 = min((i+1) - tmp[i+1] + tmp[N] - tmp[i+1], res1)
        
b = 0
w = 0
for i in range(N):
    if S[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res3))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(input())

seq = []

flag = False
tmp = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        tmp += 1
        seq.append(tmp)
        tmp = 0
            
    else:
        tmp += 1

res1 = []     
res2 = []

seq.append(tmp+1)

seq_sum = [0 for _ in range(len(seq)+1)]

for i in range(len(seq)):
    seq_sum[i+1] = seq_sum[i] + seq[i]

res = 1
if S[0] == '0':
    for i in range(len(seq_sum) - 2 * K - 1):
        if i%2 == 0:
            r = min(i + 2*K, len(seq_sum))
            res = max(res, seq_sum[r] - seq_sum[i]) 
        else:
            r = min(i + 2*K+1, len(seq_sum))
            res = max(res, seq_sum[r] - seq_sum[i])
        
else:
    for i in range(len(seq_sum) - 2 * K):
        if i%2 == 0:
            r = min(i + 2*K+1, len(seq_sum))
            res = max(res, seq_sum[r] - seq_sum[i])
        else:
            r = min(i + 2*K, len(seq_sum))
            res = max(res, seq_sum[r] - seq_sum[i]) 
 


print(res)

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

seq = []
tmp = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        tmp += 1
        seq.append(tmp)
        tmp = 0
            
    else:
        tmp += 1

seq.append(tmp+1)

seq_sum = [0 for _ in range(len(seq)+1)]

for i in range(len(seq)):
    seq_sum[i+1] = seq_sum[i] + seq[i]

res = -1
if S[0] == '0':
    for i in range(len(seq_sum)):
        if i%2 == 0:
            r = min(i + 2*K, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i]) 
        else:
            r = min(i + 2*K+1, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i])
        
else:
    for i in range(len(seq_sum)):
        if i%2 == 0:
            r = min(i + 2*K+1, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i])
        else:
            r = min(i + 2*K, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i]) 

            
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

C.sort(reverse=True)

tmp = []
for x in range(X):
    for y in range(Y):
        tmp.append(A[x] + B[y])
        
tmp.sort(reverse=True)

res = []
for i in range(min(K, X*Y)):
    for z in range(Z):
        res.append(tmp[i] + C[z])
 
res.sort(reverse=True)
for i in range(K):
    print(res[i])

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

C.sort(reverse=True)

tmp = []
for x in range(X):
    for y in range(Y):
        tmp.append(A[x] + B[y])
        
tmp.sort(reverse=True)

res = []
for i in range(min(K, X*Y)):
    for z in range(Z):
        res.append(tmp[i] + C[z])
 
res.sort(reverse=True)
for i in range(K):
    print(res[i])

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())

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

res = []
for a in range(X):
    for b in range(Y):
            res.append(A[a] + B[b])
            
res.sort(reverse=True)
result = []
for r in res:
    for c in C:
        result.append(r + c)
        
result.sort(reverse=True)

for i in range(K):
    print(result[i])
        

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

C.sort(reverse=True)

tmp = []
for x in range(X):
    for y in range(Y):
        tmp.append(A[x] + B[y])
        
tmp.sort(reverse=True)

res = []
for i in range(min(K, X*Y)):
    for z in range(Z):
        res.append(tmp[i] + C[z])
 
res.sort(reverse=True)
for i in range(K):
    print(res[i])
Buggy python submission (verdict: Runtime Error):
b = input()

if b == 'A':
    print('T')
elif b == 'T':
    print('A')
    
elif B == 'G':
    print('C')
else:
    print('G')

Fixed submission:
b = input()

if b == 'A':
    print('T')
elif b == 'T':
    print('A')
    
elif b == 'G':
    print('C')
else:
    print('G')
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

t_list = []
for i in range(1, 10 ** 5):
    if A%i == 0 and B%i == 0:
        count += 1
        t_list.append(i)
        
        

        
print(t_list[-K])

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

t_list = []
for i in range(1, 10 ** 5):
    if A%i == 0 and B%i == 0:
        t_list.append(i)
           
print(t_list[-K])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
match = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [-1 for i in range(N + 1)]

cost = []
for i in range(M):
    cost.append([A[i], match[A[i]]])

dp[0] = 0
for i in range(N):
    for k in range(M):
        if i + 1 - cost[k][1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - cost[k][1]] + 1)

tmp = 0 #使ったマッチの数
res = ''
cost.sort(key=lambda x: x[0], reverse=True)
for i in range(dp[N]):
    for j in range(M):
        if dp[N - cost[j][1] - tmp] == dp[N - tmp] - 1:
            res = res + str(cost[j][0])
            tmp += cost[j][1]
            break
            
print(res)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
match = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [-1 for i in range(N + 1)]

cost = []
for i in range(M):
    cost.append([A[i], match[A[i]]])

dp[0] = 0
for i in range(N):
    for k in range(M):
        if i + 1 - cost[k][1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - cost[k][1]] + 1)

tmp = 0 #使ったマッチの数
res = ''
cost.sort(key=lambda x: x[0], reverse=True)
for i in range(dp[N]):
    for j in range(M):
        if N - cost[j][1] - tmp >= 0:
            if dp[N - cost[j][1] - tmp] == dp[N - tmp] - 1:
                res = res + str(cost[j][0])
                tmp += cost[j][1]
                break
            
print(res)
Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

res = 0
for i in range(H):
    for j in range(W):
        stack = deque([])
        flag = [[False for _ in range(W)] for _ in range(H)]
        stack.append([i, j])
        flag[i][j] = True
        start = S[i][j]
        while len(stack) > 0:
            y, x = stack.popleft()
            for nx, ny in ([1, 0], [0, 1], [-1, 0], [0, -1]):
                if 0<= x + nx < W and 0 <= y + ny < H:
                    if S[y][x] != S[y+ny][x+nx] and flag[y+ny][x+nx] == False:
                        stack.append([y+ny, x+nx])
                        flag[y+ny][x+nx] = True
                        if S[y+ny][x+nx] != start:
                            res += 1
            
                
            
            
print(res//2)


Fixed submission:
N = int(input())
H = int(input())
W = int(input())

print((N - H + 1) * (N - W + 1))

Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

res = 0
for i in range(H):
    for j in range(W):
        stack = deque([])
        flag = [[False for _ in range(W)] for _ in range(H)]
        stack.append([i, j])
        flag[i][j] = True
        start = S[i][j]
        while len(stack) > 0:
            y, x = stack.popleft()
            for nx, ny in ([1, 0], [0, 1], [-1, 0], [0, -1]):
                if 0<= x + nx < W and 0 <= y + ny < H:
                    if S[y][x] != S[y+ny][x+nx] and flag[y+ny][x+nx] == False:
                        stack.append([y+ny, x+nx])
                        flag[y+ny][x+nx] = True
                        if S[y+ny][x+nx] != start:
                            res += 1
            
                
            
            
print(res//2)


Fixed submission:
N = int(input())
H = int(input())
W = int(input())

print((N - H + 1) * (N - W + 1))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

tmp = [10 ** 12 for _ in range(N)]
tmp[0] = 0
tmp[1] = abs(H[1] - H[0])

for i in range(2, N):
    for k in range(1, K+1):
        if i - k >= 0:
            tmp[i] = min(tmp[i], tmp[i - k] + abs(H[i] - H[i - k]))
        else:
            break
print(tmp[N-1])

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

tmp = [10 ** 12 for _ in range(N)]
tmp[0] = 0
tmp[1] = abs(H[1] - H[0])

for i in range(2, N):
    for k in range(1, K+1):
        if i - k >= 0:
            tmp[i] = min(tmp[i], tmp[i - k] + abs(H[i] - H[i - k]))
        else:
            break
print(tmp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C = map(int, input().split())

res = B
lim = A + B
for i in range(C):
  res += 1
  if i + 1 >= lim + 1:
    break

print(res)

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

res = B
lim = A + B

if lim + 1 >= C + 1:
  res += C
else:
  res += lim + 1
print(res)