Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

# lcmTotal = 1
# for i in numList:
#   lcmTotal = lcm_base(lcmTotal, i)

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result += lcmTotal // targetNum % mod

print(result % mod)


Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

# lcmTotal = 1
# for i in numList:
#   lcmTotal = lcm_base(lcmTotal, i)

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result += lcmTotal // targetNum

print(result % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result = (result + (lcmTotal // targetNum % mod)) % mod

print(result)

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

# lcmTotal = 1
# for i in numList:
#   lcmTotal = lcm_base(lcmTotal, i)

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result += lcmTotal // targetNum

print(result % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result = (result + lcmTotal // targetNum) % mod

print(result)

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

mod = 10 ** 9 + 7
n = int(input())
numList = list(map(int, input().split()))

# lcmTotal = 1
# for i in numList:
#   lcmTotal = lcm_base(lcmTotal, i)

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result += lcmTotal // targetNum

print(result % mod)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

acList = [False] * n
waCount = 0
for i in range(m):
  p, s = map(str, input().split())
  p = int(p) - 1 # インデックスの調整
  print(acList)
  if acList[p]:
    continue
  if s == 'WA':
    waCount += 1
    continue
  acList[p] = True

print(sum(acList), waCount)


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

acList = [False] * n
waList = [0] * n
waCount = 0
for i in range(m):
  p, s = map(str, input().split())
  p = int(p) - 1 # インデックスの調整
  if acList[p]:
    continue
  if s == 'WA':
    waList[p] += 1
    continue
  waCount += waList[p]
  acList[p] = True

print(sum(acList), waCount)
Buggy python submission (verdict: Time Limit Exceeded):
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def cmb(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

n, k = map(int, input().split())
sortedList = sorted(list(map(int, input().split())))

mod = 10 ** 9 + 7
result = 0
for i in range(1, n - k + 2):
  val = cmb(n - i, k - 1) * (sortedList[n - i] - sortedList[i - 1]) % mod
  result = (result + val) % mod
print(result)


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

factorial = [1]
for i in range(1, n + 1):
  factorial.append((factorial[i - 1] * i) % mod)

def cmb(n, k):
  return factorial[n] * pow(factorial[n - k], mod - 2, mod) * pow(factorial[k], mod - 2, mod)

result = 0
for i in range(1, n - k + 2):
  val = cmb(n - i, k - 1) * (sortedList[n - i] - sortedList[i - 1])
  result += val
print(result % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result % (10 ** 9 + 7)

n, k = map(int, input().split())
sortedList = sorted(list(map(int, input().split())))

result = 0
for i in range(1, n - k + 2):
  result = (result + cmb(n - i, k - 1) * (sortedList[n - i] - sortedList[i - 1])) % (10 ** 9 + 7)
print(result)


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

factorial = [1]
for i in range(1, n + 1):
  factorial.append((factorial[i - 1] * i) % mod)

def cmb(n, k):
  return factorial[n] * pow(factorial[n - k], mod - 2, mod) * pow(factorial[k], mod - 2, mod)

result = 0
for i in range(1, n - k + 2):
  val = cmb(n - i, k - 1) * (sortedList[n - i] - sortedList[i - 1])
  result += val
print(result % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

l = [0] * 1000 # 000 to 999
for i in range(n - 2): # i桁目 を残す
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      password = s[i] + s[j] + s[k]
      l[int(password)] = 1

print(l.count(1))



Fixed submission:
n = int(input())
S = input()

result = 0
for i in range(10):
  if str(i) in S:
    T = S[S.index(str(i))+1:]

    for j in range(10):
      if str(j) in T:
        U = T[T.index(str(j))+1:]

        for k in range(10):
          if str(k) in U:
            result += 1

print(result)
Buggy python submission (verdict: Runtime Error):
import math

def main():
  t1, t2 = map(int, input().split())
  a1, a2 = map(int, input().split())
  b1, b2 = map(int, input().split())

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod(halfB - halfA, sumA - sumB)
  if mod == 0
    return div * 2
  return div * 2 + 1

print(main())

Fixed submission:
import math

def main():
  t1, t2 = map(int, input().split())
  a1, a2 = map(int, input().split())
  b1, b2 = map(int, input().split())

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod(halfB - halfA, sumA - sumB)
  if mod == 0:
    return div * 2
  return div * 2 + 1

print(main())

Buggy python submission (verdict: Runtime Error):
import math

def main():
  t1, t2 = map(int, input().split())
  a1, a2 = map(int, input().split())
  b1, b2 = map(int, input().split())

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod((halfB - halfA) // (sumA - sumB))
  if mod == 0
    return div * 2
  return div * 2 + 1

print(main())

Fixed submission:
import math

def main():
  t1, t2 = map(int, input().split())
  a1, a2 = map(int, input().split())
  b1, b2 = map(int, input().split())

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod(halfB - halfA, sumA - sumB)
  if mod == 0:
    return div * 2
  return div * 2 + 1

print(main())
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
if len(s) % 2 != 0:
  print('No')
else:
  l = len(s) // 2
  if s[:l] == s[l:]:
    print('Yes')
  else:
    pring('No')

Fixed submission:
n = int(input())
s = str(input())
if n % 2 == 1:
  print('No')
else:
  numT = n // 2
  if s[0:numT] == s[numT:n]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # str, must reverse
isTenOver = False
for char in reversed(list(str(val))):
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if targetInt in enableList:
    isTenOver = False
    resultList.append(str(targetInt))
    continue
  resultList = [str(min(enableList))] * len(resultList)
  if targetInt > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > targetInt, enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(reversed(resultList)))

Fixed submission:
numList = input().split()

if len(numList) != 3:
  print('NO')
elif numList.count('5') != 2:
  print('NO')
elif numList.count('7') != 1:
  print('NO')
else:
  print('YES')
Buggy python submission (verdict: Runtime Error):
a = int(input())
if a < 3200:
  print("red")
else:
  ptint(input())

Fixed submission:
a = int(input())
if a < 3200:
  print("red")
else:
  print(input())

Buggy python submission (verdict: Runtime Error):
a = input()
if a<3200:
  print("red")
else:
  print(input())

Fixed submission:
a = int(input())
if a < 3200:
  print("red")
else:
  print(input())

Buggy python submission (verdict: Runtime Error):
a = int(input())
if(a<3200){
  print("red")
}else{
  print(input())
}

Fixed submission:
a = int(input())
if a < 3200:
  print("red")
else:
  print(input())
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = input().split()
print(1/sum(map(lambda x:1/x, a)))

Fixed submission:
n = int(input())

a = input().split()
print(1/sum(map(lambda x:1/int(x), a)))

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

a = input().split()
print(1/sum(a.map(lambda x:1/x)))

Fixed submission:
n = int(input())

a = input().split()
print(1/sum(map(lambda x:1/int(x), a)))
Buggy python submission (verdict: Runtime Error):
K = int(input())
A,B = map(int,input().split())

for i in range(A,B+1):
    if i%K==0:
        print("OK")
        break
else:
print("NO")

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

for i in range(A,B+1):
    if i%K==0:
        print("OK")
        exit()
print("NG")
Buggy python submission (verdict: Runtime Error):
S = input()

DAY = ["SUN","MON","TUE","WED","THU","FRY","SAT"]

print(7-DAY.index(S))

Fixed submission:
S = input()

DAY = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

print(7-DAY.index(S))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(i) for i in input().split()]

ans = 1
for i in range(N):
    ans = ans * A[i]

if (ans > 10 ** 18):
    ans = -1

print(ans)

Fixed submission:
N = int(input())

A = [int(i) for i in input().split()]

ans = 1

if min(A) == 0:
    ans = 0
else:
    for i in range(N):
        ans = ans * A[i]
        if (ans > 10 ** 18):
            ans = -1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

data = [list(map(int, input().split())) for _ in range(N)]
INF = float('inf')

data_all = []
c_min = INF

for i in range(2**N):
    data_tmp = [0]*M
    c = 0
    for j in range(N):
        if((i>>j) & 1):
            for k in range(M):
                data_tmp[k] += data[j][k+1]
            c += data[j][0]
    if(min(data_tmp) >= X):
        c_min = min(c, c_min)

if(c_min == INF):
    print(-1)
else:
    print(c_min)





Fixed submission:
S = str(input())
T = str(input())

if(T[0:len(T)-1] == S):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = [int(i) for i in input().split()]


from_ = 1
way = []
way.append(1)
for i in range(K):
    if(A[from_ - 1] in way):
        way.append(A[from_ - 1])
        break
    else:
        way.append(A[from_ - 1])
        from_ = A[from_ - 1]

key_from = way.index(way[len(way) - 1])
key_to = len(way) - 1



if(K > key_from):
    ans_loop = (K - key_from) % (key_to - key_from)
    ans_num = key_from + ans_loop
   
    print(way[ans_num])
else:
    print(way[K])

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

A = [int(i) for i in input().split()]


from_ = 1
way = []
way.append(1)
way_set = set([1])

for i in range(K):
    s = A[from_ - 1]
    if(s in way_set):
        way.append(s)
        break
    else:
        way.append(s)
        way_set.add(s)
        from_ = s

key_from = way.index(way[len(way) - 1])
key_to = len(way) - 1



if(K > key_from):
    ans_loop = (K - key_from) % (key_to - key_from)
    ans_num = key_from + ans_loop

    print(way[ans_num])
else:
    print(way[K])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for _ in range(int(M))]



count = 0
for i in range(N):
    flag = 1
    for j in range(M):
        if(AB[j][0] == i + 1):
            if(H[i] <= H[AB[j][1] - 1]):
                flag = 0
        if(AB[j][1] == i + 1):
            if(H[i] <= H[AB[j][0] - 1]):
                flag = 0
    if(flag == 1):
        count += 1

print(count)


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


Flags = [1] * N

for j in range(M):
    if(H[AB[j][0] - 1] <= H[AB[j][1] - 1]):
        Flags[AB[j][0] - 1] = 0

    if(H[AB[j][1] - 1] <= H[AB[j][0] - 1]):
        Flags[AB[j][1] - 1] = 0

count = 0
for i in range(N):
    count += Flags[i]



print(count)
Buggy python submission (verdict: Runtime Error):
A, B, N = map(int, input().split())

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
#for i in range(N//2, N + 1):
    #if(floor(i) > max):
        #max = floor(i)
max = max(floor(N), floor(B-1))

print(max)



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

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
#for i in range(N//2, N + 1):
    #if(floor(i) > max):
        #max = floor(i)

if(N < (B-1)):
    max = floor(N)
else:
    max = floor(B-1)

print(max)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
for i in range(N//2, N + 1):
    if(floor(i) > max):
        max = floor(i)


print(max)



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

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
#for i in range(N//2, N + 1):
    #if(floor(i) > max):
        #max = floor(i)

if(N < (B-1)):
    max = floor(N)
else:
    max = floor(B-1)

print(max)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
for i in range(N + 1):
    if(floor(i) > max):
        max = floor(i)


print(max)



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

def floor(x):
    out = (A * x)//B - A * (x//B)
    return out

max = 0
#for i in range(N//2, N + 1):
    #if(floor(i) > max):
        #max = floor(i)

if(N < (B-1)):
    max = floor(N)
else:
    max = floor(B-1)

print(max)
Buggy python submission (verdict: Runtime Error):
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+9,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data) - 1):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Fixed submission:
S, W = map(int, input().split())

if(W >= S):
    print("unsafe")
else:
    print("safe")

Buggy python submission (verdict: Runtime Error):
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+7,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data) - 1):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Fixed submission:
S, W = map(int, input().split())

if(W >= S):
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = [str(input()) for _ in range(N)]

answer = []

for i in range(N):
    if(S[i] not in answer):
        answer.append(S[i])
        
        
print(len(answer))

Fixed submission:
N = int(input())

S = [str(input()) for _ in range(N)]

answer = []
answer = list(set(S))

#for i in range(N):
    #if(S[i] not in answer):
        #answer.append(S[i])


print(len(answer))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

S = str(input())

memo = [0]
d = 0
mod = 2019


for s in S[::-1]:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.appemd(tmp%mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v-1)/2 for v in c.values())
print(ans)



Fixed submission:
from collections import Counter

S = str(input())

memo = [0]
d = 0
mod = 2019


for s in S[::-1]:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.append(tmp%mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v-1)/2 for v in c.values())
print(int(ans))

Buggy python submission (verdict: Runtime Error):
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+7,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data)):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Fixed submission:
from collections import Counter

S = str(input())

memo = [0]
d = 0
mod = 2019


for s in S[::-1]:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.append(tmp%mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v-1)/2 for v in c.values())
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())


count = 0
for i in range(len(S)):
    for j in range(i+4, len(S)+1):
        if(int(S[i:j]) % 2019 == 0):
            count += 1

print(count)

Fixed submission:
from collections import Counter

S = str(input())

memo = [0]
d = 0
mod = 2019


for s in S[::-1]:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.append(tmp%mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v-1)/2 for v in c.values())
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import  math
K = int(input())

ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += math.gcd(math.gcd(a,b),c)

print(ans)

Fixed submission:
import  math
K = int(input())

ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        a_b = math.gcd(a,b)
        for c in range(1, K+1):
            ans += math.gcd(a_b,c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

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

for i in range(N):
    ball[A[i] - 1] += 1

#print("ball", ball)
for k in range(N):
    ans = 0
    ball_new = [b for b in ball]
    ball_new[A[k] - 1] -= 1

    #print("ball_n", ball_new)
    for i in range(N):
        ball_num = ball_new[i]
        ans += ball_num*(ball_num-1)//2
    print(ans)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

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

for i in range(N):
    ball[A[i] - 1] += 1

all = 0
for i in range(N):
    all += ball[i]*(ball[i] - 1)//2


#print("ball", ball)
for k in range(N):
    ans = all
    ball_new = ball[A[k] - 1] - 1
    #ball_new[A[k] - 1] -= 1

    ans -= ball[A[k] - 1]*(ball[A[k] - 1] - 1)//2
    ans += ball_new*(ball_new - 1)//2

    print(ans)
Buggy python submission (verdict: Runtime Error):
import queue

H, W = map(int, input().split())

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

ini = 0
if s[0][0] == '#':
    ini = 1

dist = [[ini for _ in range(W)] for _ in range(H)]
start = (0,0)

qq = queue.Queue()

for i in range(H):
    for j in range(W):
        tgt = []
        if j == 0:
            pass
        else:
            if s[i][j-1] == '.' and s[i][j] == '#':
                tgt.append(dist[i][j-1] + 1)

            else:
                tgt.append(dist[i][j-1])

        if i == 0:
            pass
        else:
            if s[i-1][j] == '.' and s[i][j] == "#":
                tgt.append(dist[i-1][j] + 1)
            else:
                tgt.append(dist[i-1][j])
        if i + j == 0:
            continue
        dist[i][j] = min(tgt)

print(dist[H-1][W-1])



Fixed submission:
import queue

H, W = map(int, input().split())

s = [list(input()) for _ in range(H)]

ini = 0
if s[0][0] == '#':
    ini = 1

dist = [[ini for _ in range(W)] for _ in range(H)]
start = (0,0)

qq = queue.Queue()

for i in range(H):
    for j in range(W):
        tgt = []
        if j == 0:
            pass
        else:
            if s[i][j-1] == '.' and s[i][j] == '#':
                tgt.append(dist[i][j-1] + 1)

            else:
                tgt.append(dist[i][j-1])

        if i == 0:
            pass
        else:
            if s[i-1][j] == '.' and s[i][j] == "#":
                tgt.append(dist[i-1][j] + 1)
            else:
                tgt.append(dist[i-1][j])
        if i + j == 0:
            continue
        dist[i][j] = min(tgt)

print(dist[H-1][W-1])
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
print(min(N % K, K - N % K))

Fixed submission:
N, K = map(int, input().split())
print(min(N % K, K - N % K))
Buggy python submission (verdict: Runtime Error):
a = list(list(map(int , input().split())) for l in range(3))
n = int(input())

for i in range(input()):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)

Fixed submission:
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
candidate = {}
for i in range(n):
  inp = input()
  if inp not in candidate:
    candidate[inp] = 1
  else:
    candidate[inp] += 1
ans = [j[0] for j in candidate.items() if j[1] == max(candidate.values())]
ans.sort()
print('\n'.join(ans))

Fixed submission:
import sys
from collections import Counter
N = int(sys.stdin.readline())
S = sys.stdin.read().split()

count = Counter(S)
max_num = max(count.values())
max_list = [i for i,j in count.items() if j==max_num]

max_list.sort()
print('\n'.join(max_list))