Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a=[0]*100001
b=[0]*100001

n = int(input())
v = list(map(int,input().split()))

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if a.index(max(a))==b.index(max(b)):
  a= sorted(a[v[i]])
  b= sorted(b[v[i]])
  print(min(n-a[2]+b[1],n-a[1]-b[2]))
elif max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
else:
  print(n-max(a)-max(b))
  



Fixed submission:
a=[0]*100001
b=[0]*100001

n = int(input())
v = list(map(int,input().split()))

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if a.index(max(a))==b.index(max(b)):
  a= sorted(a, reverse=True)
  b= sorted(b, reverse=True)
  print(min(n-a[1]-b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))

Buggy python submission (verdict: Runtime Error):
a=[0]*100000
b=[0]*100000

n = int(input())
v = list(map(int,input().split()))

for i in range(0,n,2):
  a[v[i]]+=1


for i in range(1,n,2):
  b[v[i]]+=1

if max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
else:
  print(n-max(a)-max(b))
  
  

Fixed submission:
a=[0]*100001
b=[0]*100001

n = int(input())
v = list(map(int,input().split()))

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if a.index(max(a))==b.index(max(b)):
  a= sorted(a, reverse=True)
  b= sorted(b, reverse=True)
  print(min(n-a[1]-b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))
Buggy python submission (verdict: Runtime Error):
n,i = map(int,input().spllit())
print(n-i+1)

Fixed submission:
n,i = map(int,input().split())
print(n-i+1)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
x = list(map(int,input().split()))

kyori=2*10**8+1
for i in range(n-k+1):
#print(x[i:k+i])
  if x[k+i-1]<=0:
    kyori = min(kyori,abs(x[i]))
  elif x[i]<=0 and 0<=x[k+1-1]:
    kyori = min(kyori,abs(x[i]*2)+abs(x[k+i-1]),abs(x[i])+abs(x[k+i-1]*2))
  elif 0<=x[i]:
    kyori = min(kyori,abs(x[k+i-1]))
print(kyori)

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
 
kyori=10**9
for i in range(n-k+1):
#print(x[i:k+i])
  if x[k+i-1]<=0:
    kyori = min(kyori,abs(x[i]))
  elif x[i]<0 and 0<x[k+i-1]:
    kyori = min(kyori,abs(x[i]*2)+abs(x[k+i-1]),abs(x[i])+abs(x[k+i-1]*2))
  elif 0<=x[i]:
    kyori = min(kyori,abs(x[k+i-1]))
print(kyori)
Buggy python submission (verdict: Runtime Error):
n,k= int(input().split())
print(0 if n%k==0 else 1)

Fixed submission:
n,k= map(int,input().split())
print(0 if n%k==0 else 1)

Buggy python submission (verdict: Runtime Error):
n,k= int(input().split())
print(0 if n%k=0 else 1)

Fixed submission:
n,k= map(int,input().split())
print(0 if n%k==0 else 1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = ""
cnt = 0

while n != 0:
    new = n - (-2) ** cnt
    if new % (2 ** (cnt + 1)) == 0:
        ans = "1" + ans
        n = n - (-2) ** cnt
    else:
        ans = "0" + ans
    cnt += 1
    aa += 1
print(ans)


Fixed submission:
n = int(input())
base = 2
ans =""

while n != 0:
  ans = str(n%base)+ans
  n = -(n//base)
if ans:
  print(ans)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum_s =[0]*n
sum_s[0]=a[0]
for i in range(1,n):
  sum_s[i] = (a[i]+ sum_s [i-1])%m

#print(sum_s)

count = 0
for i in range(n):
  if sum_s[i]%m == 0:
    count += 1
  for j in range(0,i):
    if (sum_s[i]-sum_s[j])%m == 0 :
      count +=1
    
print(count)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum_s =[0]*n
sum_s[0]=(a[0])%m
for i in range(1,n):
  sum_s[i] = (a[i]+ sum_s [i-1])%m

#print(sum_s)
dict = {}
for i in range(n):
  if sum_s[i] not in dict:
    dict[sum_s[i]] = 1
  else:
    dict[sum_s[i]] += 1

#print(sum_s)

def combination(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

ans=0
for i in dict:
  if i == 0:
    if dict[i]>=2:
      ans +=combination(dict[i],2)
    ans +=dict[i] 
  else:
    if dict[i]>=2:
      ans += combination(dict[i],2)
      #print(i,dict[i],combination(dict[i],2))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ruiseki = [0]*(n+1)

for i in range(1,n+1):
  ruiseki[i] = a[i-1] + ruiseki[i-1]

#右側が大きいときにTrueを返す。
def judge(begin,mid,end):
  if ruiseki[mid]-ruiseki[begin] < ruiseki[end]-ruiseki[mid]:
    return True
  else:
    return False

def solvediff(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] - (ruiseki[end]-ruiseki[mid]) )

def solve_num1(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] )

def solve_num2(begin,mid,end):
  return abs( ruiseki[end]-ruiseki[mid] )


ans = float("inf")
for i in range(2,n-1):
  
  #PQの探索
  ok = i
  ng = 0
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(0,mid,i):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(0,mid,i):
      min_num = solvediff(0,mid,i)
      num1 = solve_num1(0,mid,i)
      num2 = solve_num2(0,mid,i)
  
  #RSの探索
  ok = n
  ng = i
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(i,mid,n):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(i,mid,n):
      min_num = solvediff(i,mid,n)
      num3 = solve_num1(i,mid,n)
      num4 = solve_num2(i,mid,n)
      
  ans = min(ans, max(num1,num2,num3,num4) - min(num1,num2,num3,num4))
  
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ruiseki = [0]*(n+1)

for i in range(1,n+1):
  ruiseki[i] = a[i-1] + ruiseki[i-1]

#右側が大きいときにTrueを返す。
def judge(begin,mid,end):
  if ruiseki[mid]-ruiseki[begin] < ruiseki[end]-ruiseki[mid]:
    return True
  else:
    return False

def solvediff(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] - (ruiseki[end]-ruiseki[mid]) )

def solve_num1(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] )

def solve_num2(begin,mid,end):
  return abs( ruiseki[end]-ruiseki[mid] )


ans = float("inf")
for i in range(2,n-1):
  
  #PQの探索
  ok = i
  ng = 0
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(0,mid,i):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(0,mid,i):
      min_num = solvediff(0,mid,i)
      num1 = solve_num1(0,mid,i)
      num2 = solve_num2(0,mid,i)
  
  #RSの探索
  ok = n
  ng = i
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(i,mid,n):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(i,mid,n):
      min_num = solvediff(i,mid,n)
      num3 = solve_num1(i,mid,n)
      num4 = solve_num2(i,mid,n)
      
  ans = min(ans, max(num1,num2,num3,num4) - min(num1,num2,num3,num4))
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())
count =0
for i in range(len(s)):
  if s[i]="+":
    count +=1
  else:
    count -=1
print(count)

Fixed submission:
s=list(input())
count =0
for i in range(len(s)):
  if s[i]=="+":
    count +=1
  else:
    count -=1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

c = b - a 

def count(n):
  if n ==1:
    return 1
  else:
    return count(n-1)+n

print(count(c)-b)

Fixed submission:
import sys
sys.setrecursionlimit(2000)

a,b = map(int,input().split())

c = b - a 

def count(n):
  if n ==1:
    return 1
  else:
    return count(n-1)+n

print(count(c)-b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ruiseki = [[0]*20 for i in range(n+1)]

for i in range(n):
    for j in range(20):
        ruiseki[i+1][j] = ruiseki[i][j] + a[i] % 2
        a[i] = a[i] >> 1

s = 0
t = 1
ans = 0
while s < n + 1:
    while t < n + 1: 
        flag = False
        for i in range(20):
            if ruiseki[t][i] - ruiseki[s][i] > 1:
                flag = True
        if flag:
            break
        t += 1
    ans += (t - s - 1)
    s += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

ruiseki = [[0]*20 for i in range(n+1)]

for i in range(n):
    for j in range(20):
        ruiseki[i+1][j] = ruiseki[i][j] + a[i] % 2
        a[i] = a[i] >> 1

s = 0
t = 1
ans = 0
while s < n + 1:
    while t < n + 1: 
        flag = False
        for i in range(20):
            if ruiseki[t][i] - ruiseki[s][i] > 1:
                flag = True
        if flag:
            break
        t += 1
    ans += (t - s - 1)
    s += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
p = list(map(int,input().split()))
info = [list(map(int,input().split())) for _ in range(m)]

par =[i for i in range(n+1)] 
rank=[0]*(n+1)

# xの根を見つける
def root(x):
  if par[x] == x:
    return x
  else:
    par[x] = root(par[x])
    return par[x]
  
# x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
def find(x, y):
  return root(x) == root(y)

# xとyの根を結合させる
def union(x, y):
  x = root(x)
  y = root(y)
  if rank[x] < rank[y]:
    par[x] = y
  else:
    par[y] = x
    if rank[x] == rank[y]:
      rank[x] += 1

for i in range(m):
  union(info[i][0],info[i][1])

ans = 0

for i in range(n):
  if find(i+1,p.index(i+1)+1):
    ans += 1
    
print(ans)

Fixed submission:
n,m = map(int,input().split())
p = list(map(int,input().split()))
info = [list(map(int,input().split())) for _ in range(m)]

par =[i for i in range(n+1)] 
rank=[0]*(n+1)

# xの根を見つける
def root(x):
  if par[x] == x:
    return x
  else:
    par[x] = root(par[x])
    return par[x]
  
# x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
def find(x, y):
  return root(x) == root(y)

# xとyの根を結合させる
def union(x, y):
  x = root(x)
  y = root(y)
  if rank[x] < rank[y]:
    par[x] = y
  else:
    par[y] = x
    if rank[x] == rank[y]:
      rank[x] += 1

for i in range(m):
  union(info[i][0],info[i][1])

a=[0]*(n+1)
for i in range(n):
  a[p[i]]=i+1

ans = 0 
for i in range(1,n+1):
  if find(i,a[i]):
    ans += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]

ind = {}
for i in range(2 * n):
    info[i] = (info[i][0], int(info[i][1]))
    ind[info[i]] = i

ru_b = [[0] * (2 * n + 1) for i in range(n + 1)]
ru_w = [[0] * (2 * n + 1) for i in range(n + 1)]
for i in range(n + 1):
    for j in range(2 * n):
        col, num = info[j]
        if col == "B" and num > i:
            ru_b[i][j + 1] += 1
        if col == "W" and num > i:
            ru_w[i][j + 1] += 1
    for j in range(2 * n):
        ru_b[i][j + 1] += ru_b[i][j]
        ru_w[i][j + 1] += ru_w[i][j]    


dp = [[INF] * (n + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(n + 1):
        if i + 1 <= n and j <= n:
            bi = ind[("B", i + 1)]
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi])
        if i <= n and j + 1 <= n:
            wi = ind[("W", j + 1)]
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi])

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

Fixed submission:
import sys
input = sys.stdin.readline


n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]

ind = {}
for i in range(2 * n):
    if info[i][0] == "B":
        info[i] = (0, int(info[i][1]))
    else:
        info[i] = (1, int(info[i][1]))
    ind[info[i][0] * 10 ** 5 + info[i][1]] = i

ru_b = [[0] * (2 * n + 1) for i in range(n + 1)]
ru_w = [[0] * (2 * n + 1) for i in range(n + 1)]
for i in range(n + 1):
    for j in range(2 * n):
        col, num = info[j]
        if col == 0 and num > i:
            ru_b[i][j + 1] += 1
        elif col == 1 and num > i:
            ru_w[i][j + 1] += 1
    for j in range(2 * n):
        ru_b[i][j + 1] += ru_b[i][j]
        ru_w[i][j + 1] += ru_w[i][j]    


dp = [[INF] * (n + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(n + 1):
        if i + 1 <= n and j <= n:
            bi = ind[i + 1]
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi])
        if i <= n and j + 1 <= n:
            wi = ind[10 ** 5 + j + 1]
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi])

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = tuple(input() for i in range(n))
MOD = n

def solve(add):
    for i in range(n):
        for j in range(n):
            if s[(i+add) % MOD][j] != s[(j+add) % MOD][i]:
                return False
    return True

ans = 0
for i in range(n):
    if solve(i):
        ans += n
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
MOD = n

def solve(add):
    for i in range(n):
        for j in range(n):
            if s[(i+add) % MOD][j] != s[(j+add) % MOD][i]:
                return False
    return True

ans = 0
for i in range(n):
    if solve(i):
        ans += n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
MOD = n

def solve(add):
    for i in range(n):
        for j in range(n):
            if s[(i+add) % MOD][j] != s[(j+add) % MOD][i]:
                return False
    return True

ans = 0
for i in range(n):
    if solve(i):
        ans += n
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
MOD = n

def solve(add):
    for i in range(n):
        for j in range(n):
            if s[(i+add) % MOD][j] != s[(j+add) % MOD][i]:
                return False
    return True

ans = 0
for i in range(n):
    if solve(i):
        ans += n
print(ans)
Buggy python submission (verdict: Runtime Error):


q = int(input())
info = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    min_, max_ = info[i]
    min_, max_ = min(min_, max_), max(min_, max_)
    mul = min_ * max_
    ans = 2 * (min_ - 1)

    ok = 0
    ng = max_ + 10
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid <= (mul - 1) // mid:
            ok = mid
        else:
            ng = mid
    ans += max(ok - (min_ - 1), 0)
    ans += max(ok - min_, 0)
    
    if ok == (mul - 1) // ok:
        ans -= 1
    print(ans)

Fixed submission:
def solve(ab,i):
    return (ab - 1) // i
    
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    ans = a - 1
    
    start_a = a + 1
    num = int((a * b) ** 0.5)
    while True:
        if solve(a*b, num) == solve(a*b, num + 1):
            break
        else:
            num += 1
    ans = num - 1
    ans += (solve(a*b, num) - 1)
    if a == b:
        ans += 1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

div, mod = divmod(n, 4)
ans = []
for i in range(div):
    ans.append(6*i + 2)
    ans.append(6*i + 3)
    ans.append(6*i + 4)
    ans.append(6*i + 6)

if mod == 1:
    ans.append(6*(i+1) + 6)
if mod == 2:
    ans.append(6*(i+1) + 2)
    ans.append(6*(i+1) + 4)
if mod == 3:
    ans.append(6*(i+1) + 2)
    ans.append(6*(i+1) + 4)
    ans.append(6*(i+1) + 6)

print(*ans)

Fixed submission:
n = int(input())

div, mod = divmod(n, 4)
ans = []

if n == 3:
    print(2, 5, 63)
    exit()
if n == 4:
    print(2, 5, 20, 63)
    exit()
if n == 5:
    print(2, 5, 20, 30, 63)
    exit()
    
cnt = 0
i = 0
for i in range(div):
    cnt += 15
    ans.append(6*i + 2)
    ans.append(6*i + 3)
    ans.append(6*i + 4)
    ans.append(6*i + 6)
if mod == 1:
    i += 1
    cnt += 2
    ans.append(6*i + 2)
if mod == 2:
    i += 1
    cnt += 5
    ans.append(6*i + 2)
    ans.append(6*i + 3)
if mod == 3:
    i += 1
    cnt += 9
    ans.append(6*i + 2)
    ans.append(6*i + 3)
    ans.append(6*i + 4)

if cnt % 6 == 0:
    pass
if cnt % 6 == 2:
    ans = ans[0:4] + ans[5:] + [ans[-1] - ans[-1] % 6 + 6]
if cnt % 6 == 3:
    ans = ans[0:5] + ans[6:] + [ans[-1] - ans[-1] % 6 + 6]
if cnt % 6 == 5:
    ans = ans[0:5] + ans[6:] + [6 * (ans[-1] // 6) + 4]
print(*ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())

if m==1 and n==1:
  print(1)
elif m==2:
  print(0)
elif n==2:
  print(0):
else:
  print(max(1,n-2)*max(1,m-2))

Fixed submission:
n,m = map(int,input().split())

if m==1 and n==1:
  print(1)
elif m==2:
  print(0)
elif n==2:
  print(0)
else:
  print(max(1,n-2)*max(1,m-2))
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

min_b = -((-n) // a)

if not(min_b <= b and a + b <= n + 1):
    print(-1)
else:
    print(re)

Fixed submission:
n, a, b = map(int, input().split())

min_b = -((-n) // a)
if not(min_b <= b and a + b <= n + 1):
    print(-1)
    exit()

ans = []
i = 0
while True:
    tmp = []
    break_flag = False
    for j in range(a):
        if i * a + j >= n:
            break_flag = True
            break
        tmp.append(i * a + j + 1)
    if not tmp:
        break
    ans.append(tmp)
    i += 1
    if break_flag:
        break

ans.sort(reverse=True)
nokori_b = b - len(ans)

for i in range(len(ans) - 1):
    cnt_elems = len(ans[i])
    if nokori_b >= len(ans[i]) - 1:
        ans[i].sort(reverse=True)
        nokori_b -= (len(ans[i]) - 1)
    else:
        ans[i] = sorted(ans[i][:nokori_b + 1], reverse=True) + ans[i][nokori_b + 1:]
        break

res = []
for li in ans:
    for num in li:
        res.append(num)
print(*res)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
k = int(input())

dp = [[[0] * (n + 1) for i in range(n + 1)] for i in range(k + 1)]

# 長さ1のときの初期化
for i in range(n):
    dp[0][i][i + 1] = 1

# 長さ2~nのときのDP
for length in range(2, n + 1):
    for l in range(n + 1):
        for ki in range(k + 1):
            r = l + length
            if r > n:
                break
            if s[l] == s[r - 1]:
                dp[ki][l][r] = max(2 + dp[ki][l + 1][r - 1], dp[ki][l][r])
            else:
                dp[ki][l][r] = max(dp[ki][l + 1][r], dp[ki][l][r - 1], dp[ki][l][r])
                if ki - 1 >= 0:
                    dp[ki][l][r] = max(dp[ki - 1][l + 1][r - 1] + 2, dp[ki - 1][l + 1][r - 1] + 2, dp[ki][l][r])

ans = 0
for i in range(k + 1):
    ans = max(ans, dp[i][0][-1])
print(ans)

Fixed submission:
def get_ind(l, r):
    mod = 3
    return OFFSET * (l % mod) + r

s = input()
n = len(s)
k = int(input())

dp = [[0] * ((n + 1) * 3) for i in range(k + 1)]
OFFSET = n + 1

# 長さ1のときの初期化
for i in range(n):
    dp[0][get_ind(i, i + 1)] = 1

# 長さ2~nのときのDP
for length in range(2, n + 1):
    for l in range(n + 1):
        for ki in range(k + 1):
            r = l + length
            if r > n:
                break
            if s[l] == s[r - 1]:
                dp[ki][get_ind(l, r)] = max(2 + dp[ki][get_ind(l + 1, r - 1)], dp[ki][get_ind(l, r)])
            else:
                dp[ki][get_ind(l, r)] = max(dp[ki][get_ind(l + 1, r)], dp[ki][get_ind(l, r - 1)], dp[ki][get_ind(l, r)])
                if ki - 1 >= 0:
                    dp[ki][get_ind(l, r)] = max(dp[ki - 1][get_ind(l + 1, r - 1)] + 2, dp[ki][get_ind(l, r)])

ans = 0
for i in range(k + 1):
    for j in range(3 * (n + 1)):
        ans = max(ans, dp[i][j])
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

h,w = map(int,input().split())
s = [input() for i in range(h)]
visited = [[-1]*w for i in range(h)]
que = deque()

def bfs(i,j):
  que.append([i,j])
  visited[i][j]=0
  
  while True:
    if not que:
      return "答えなし"
    
    [current_i,current_j] = que.popleft()
    
    if  current_i == h-1 and current_j == w-1:
      return visited[current_i][current_j]
  
    for next in [[-1,0],[+1,0],[0,-1],[0,+1]]:
      next_i = current_i + next[0]
      next_j = current_j + next[1]
      if 0<=next_i<h and 0<=next_j<w:
        if visited[next_i][next_j] == -1 and s[next_i][next_j]==".":
          visited[next_i][next_j] = visited[current_i][current_j]+1
          que.append([next_i,next_j])

count_point=0
for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      count_point += 1 
  
print(count_point-bfs(0,0)-1)

Fixed submission:
from collections import deque

h,w = map(int,input().split())
s = [input() for i in range(h)]

def bfs(i,j):
  visited = [[-1]*w for i in range(h)]
  que = deque()
  que.append([i,j])
  visited[i][j]=0
  
  while True:
    if not que:
      return -1
    
    [current_i,current_j] = que.popleft()
    
    if  current_i == h-1 and current_j == w-1:
      return visited[current_i][current_j]
  
    for next in [[-1,0],[+1,0],[0,-1],[0,+1]]:
      next_i = current_i + next[0]
      next_j = current_j + next[1]
      if 0<=next_i<h and 0<=next_j<w:
        if visited[next_i][next_j] == -1 and s[next_i][next_j]==".":
          visited[next_i][next_j] = visited[current_i][current_j]+1
          que.append([next_i,next_j])

count_point=0
for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      count_point += 1 


if bfs(0,0)==-1:
  print(-1)
else:
  print(count_point-bfs(0,0)-1)
Buggy python submission (verdict: Runtime Error):
import heapq
from collections import deque

n, m = map(int, input().split())
a = list(map(int, input().split()))

info = [list(map(int, input().split())) for i in range(m)]
tree = [[] for i in range(n)]

for b, c in info:
    tree[b].append(c)
    tree[c].append(b)

visited = [False] * n
group = []
for i in range(n):
    if visited[i]:
        continue
    q = deque([i])
    visited[i] = True
    tmp = [a[i]]
    while q:
        pos = q.pop()
        for next_pos in tree[pos]:
            if visited[next_pos]:
                continue
            visited[next_pos] = True
            q.append(next_pos)
            tmp.append(a[next_pos])
    group.append(tmp)

for i in range(len(group)):
    group[i] = sorted(group[i])
    
ans = 0
cnt = len(group)*2 - 2

if cnt == 0:
    print(0)
    exit()
    
for i in range(len(group)):
    ans += group[i][0]
    cnt -= 1
    group[i][0] = 10**9 + 7

q = []
for i in range(len(group)):
    for num in group[i]:
        if num != 10**9 +7:
            heapq.heappush(q, num)

for i in range(cnt):
    if not q:
        print("Impossible")
        exit()
    ans += heapq.heappush(q)
print(ans)
    

Fixed submission:
import heapq
from collections import deque


n, m = map(int, input().split())
a = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
tree = [[] for i in range(n)]

for b, c in info:
    tree[b].append(c)
    tree[c].append(b)

visited = [False] * n
group = []
for i in range(n):
    if visited[i]:
        continue
    q = deque([i])
    visited[i] = True
    tmp = [a[i]]
    while q:
        pos = q.pop()
        for next_pos in tree[pos]:
            if visited[next_pos]:
                continue
            visited[next_pos] = True
            q.append(next_pos)
            tmp.append(a[next_pos])
    group.append(tmp)

for i in range(len(group)):
    group[i] = sorted(group[i])

ans = 0
cnt = len(group)*2 - 2

if cnt == 0:
    print(0)
    exit()
    
for i in range(len(group)):
    ans += group[i][0]
    cnt -= 1
    group[i][0] = 10**9 + 7

q = []
for i in range(len(group)):
    for num in group[i]:
        if num != 10**9 +7:
            heapq.heappush(q, num)

for i in range(cnt):
    if not q:
        print("Impossible")
        exit()
    ans += heapq.heappop(q)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = int(input())
print("Even" if (a*b)%2==0 else "Odd")

Fixed submission:
a,b = map(int,input().split())
print("Even" if (a*b)%2==0 else "Odd")