Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 1
j = 0
for i in range(n):
    ans *= a[i]
    if 0 in a:
        j += 2
        break
    if ans > 10**18:
        j += 1
        break
if j == 2:
    print(0)
elif j == 1:
    print(-1)
else:
    print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(str,input().split()))
ans = 1
b = Counter(a)
b0 = 0
b1 = 0

if '0' in a:
    b0 = b['0']
if '1' in a:
    b1 = b['1']
more2 = n-b0-b1
if b0 >0:
    print(0)
elif more2 >=60:
    print(-1)
else:
    for i in range(n):
        ans *= int(a[i])
    if ans > 10**18:
        print(-1)
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')
else:
    print('bon')

Fixed submission:
n = str(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')
else:
    print('bon')
Buggy python submission (verdict: Runtime Error):
x = int(input())
n = 0
for i in range(100):
    d[0][i] = i**5
    d[i][0] = i**5
    if i**5 == x:
        n = i
if n !=0:
    print(n,0)
else:
    for i in range(1,100):
        for j in range(1,100):
            d[i][j] = d[0][j]+d[i][0]
            if d[i][j] > x:
                n = i
                break
            elif d[i][j] == x:
                print(i,-j)
                n = i
                break
        if n == i:
            break

Fixed submission:
x = int(input())
d = [[0 for i in range(500)] for j in range(500)]
e = [[0 for i in range(500)] for j in range(500)]
f = [[0 for i in range(500)] for j in range(500)]
for i in range(500):
    d[0][i] = i**5
    d[i][0] = i**5
for i in range(1,500):
    for j in range(1,500):
        d[i][j] = d[0][j]-d[i][0]
        e[i][j] = d[0][j]+d[i][0]
for m in range(500):
    if x in d[m]:
        print(d[m].index(x),m)
        break
    elif x in e[m]:
        print(e[m].index(x),-m)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
get = []
ans = 0
i = 0
while i <= n-1:
    if  not s[i] in get:
        get.append(s[i])
        ans += 1
        i += 1
    else:
        i += 1
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
print(len(set(s)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(str,input().split()))
for i in range(1,n+1):
    print(a.count(str(i)))
    a = [j for j in a if j != str(i)]

Fixed submission:
n = int(input())
a = list(map(str,input().split()))
from collections import Counter
x = Counter(a)
for i in range(1,n+1):
    print(x[str(i)])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(str,input().split()))
for i in range(1,n+1):
    print(a.count(str(i)))

Fixed submission:
n = int(input())
a = list(map(str,input().split()))
from collections import Counter
x = Counter(a)
for i in range(1,n+1):
    print(x[str(i)])
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k = int(input())
#3つとも違う数字
s3=0
for a in range(3,k+1):
    for b in range(2,k):
        for c in range(1,k-1):
            if c<b<a:
                s3+=gcd(gcd(b,c),a)
#2種類
s2 = 0
for a in range(2,k+1):
    for b in range(1,k):
        if b<a:
            s2+=gcd(a,b)
s = s3*6 + s2*6 +k*(k+1)/2
print(int(s)

Fixed submission:
k = int(input())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

s3=0
for a in range(3,k+1):
    for b in range(2,k):
        for c in range(1,k-1):
            if c<b<a:
                s3+=gcd(gcd(b,c),a)
s2 = 0
for a in range(2,k+1):
    for b in range(1,k):
        if b<a:
            s2+=gcd(a,b)
s = s3*6 + s2*6 +k*(k+1)/2
print(int(s))
Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C =  [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.append(0)
B.append(0)
C.append(0)
ux_1 = 0
uy_1 = 0
for i in range(X):
    ux_1 += max(max(A),max(C))
    if max(A) >= max(C):
        A.pop(A.index(max(A)))
    else:
        C.pop(C.index(max(C)))
for i in range(Y):
    uy_1 += max(max(B),max(C))
    if max(B) >= max(C):
        B.pop(B.index(max(B)))
    else:
        C.pop(C.index(max(C)))
print(ux_1+uy_1)

Fixed submission:
S = str(input())
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
C_copy = C.copy()
for i in range(30):
    C_copy.append(0)
    C.append(0)
ux_1 = 0
uy_1 = 0
for i in range(X):
    ux_1 += max(max(A),max(C_copy))
    if max(A) >= max(C_copy):
        A.pop(A.index(max(A)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
for i in range(Y):
    uy_1 += max(max(B),max(C_copy))
    if max(B) >= max(C_copy):
        B.pop(B.index(max(B)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
print(ux_1 + uy_1)

Fixed submission:
S = str(input())
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(str, input().split()))
from collections import Counter
for k in range(N):
    Alist = A.copy()
    del Alist[k]#k番目のボールを除いたリスト
    C = Counter(Alist)  #カウント辞書
    count = 0
    for i in range(1,N+1):
        count += (C['{}'.format(i)]*(C['{}'.format(i)]-1))/2
    print(int(count))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
count = Counter(a)
allcnt = 0
for i in set(a):
    allcnt+= count[i]*(count[i]-1)/2
for i in range(n):
    print(int(allcnt-count[a[i]]+1))
Buggy python submission (verdict: Runtime Error):
a = str(input())
q = int(input())
s = [input().split() for i in range(q)]
for i in range(q):
    if int(s[i][0]) == 1 and len(a)>1:
        a = a[::-1]
    elif int(s[i][0])== 2 and int(s[i][1])==1:
        a=s[i][2]+a
    else:
        a=a+s[i][2]
print(a)

Fixed submission:
a = str(input())
if a == 'AAA' or a == 'BBB':
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
L = list(map(int,input().split()))
q = L[0]//(L[1]+L[2])
mod = L[0]%(L[1]+L[2])
if mod > L[1]:
    print(q*L[1]+L[1])
else:
    print(q*L[1]+mod%L[1])

Fixed submission:
L = list(map(int,input().split()))
q = L[0]//(L[1]+L[2])
mod = L[0]%(L[1]+L[2])
if mod > L[1]:
    print(q*L[1]+L[1])
elif L[1]==0:
    print(0)
else:
    print(q*L[1]+mod%L[1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if a[i]%2==0 and not (a[i]%3==0 and a[i]%5==0):
        print('DENIED')
        break       
    elif i==n:
        print('APPROVED')
        break
    else:
        i+=1

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if i==n:
        print('APPROVED')
        break
    elif a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        print('DENIED')       
        break       
    else:
        i+=1

Buggy python submission (verdict: Runtime Error):
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if a[i]%2==0 and (a[i]%3==0 or a[i]%5==0):
        print('DENIED')
        break       
    elif i==n:
        print('APPROVED')
        break
    else:
        i+=1

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if i==n:
        print('APPROVED')
        break
    elif a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        print('DENIED')       
        break       
    else:
        i+=1

Buggy python submission (verdict: Runtime Error):
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if a[i]%2==1 or a[i]%3==0 or a[i]%5==0:
        i+=1
    elif i==n:
        print('APPROVED')
        break
    else:
        print('DENIED')
        break

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if i==n:
        print('APPROVED')
        break
    elif a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        print('DENIED')       
        break       
    else:
        i+=1
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split()) 
a = list(map(int,input().split()))
i = 0
max_exp = 0
while i + k <= n:
    exp = 0
    for j in range(k):
        exp += a[i+j]
    if max_exp < exp:
        max_exp = exp
        i += 1
    else:
        i += 1
print((k+max_exp)/2)

Fixed submission:
n,k = map(int,input().split()) 
a = list(map(int,input().split()))
max_a = [sum(a[0:k])]
exp = max_a[0]
for i in range(n-k):
    max_a.append(max_a[i]-a[i]+a[k+i])
    if max_a[i+1] > exp:
      exp = max_a[i+1]
print((k+exp)/2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
divisors = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
            divisors.append(n//i)
i = 0
div = make_divisors(n)
div.sort()
while True:
    if div[i]*div[i+1] == n:
        print(div[i]+div[i+1]-2)
        break
    elif div[i]*div[i] == n:
        print(div[i]+div[i]-2)
        break     
    else:
        i += 1

Fixed submission:
n = int(input())
div = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        div.append(i)
        if i != n // i:
            div.append(n//i)
i = 0
div.sort()
while True:
    if div[i]*div[i+1] == n:
        print(div[i]+div[i+1]-2)
        break
    elif div[i]*div[i] == n:
        print(div[i]+div[i]-2)
        break     
    else:
        i += 1
Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int,input().split())
    sy,sx = map(int,input().split())
    gy,gx = map(int,input().split())
    S = []
    for _ in range(h):
        S.append(input())
    
    G = [[-1]*w for _ in range(h)]
    G_b = [[False]*w for _ in range(h)]
    v = [(1,0),(0,1),(-1,0),(0,-1)]
    ct = 0

    dq1 = deque([])
    dq1.append((sx-1,sy-1))
    G[sy-1][sx-1] = 0
    G_b[sy-1][sx-1] = True


    while dq1:

        g = set([])
        while dq1:
            x,y = dq1.popleft()
            g.add((x,y))
            for vx,vy in v:
                nx = x+vx
                ny = y+vy
                if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                    G_b[ny][nx] = True
                    G[ny][nx] = ct
                    dq1.append((nx,ny))

        
        while g:
            x,y = g.pop()
            for i in range(-2,3):
                for j in range(-2,3):
                    if i!=0 or j!=0:
                        nx = x+i
                        ny = y+j
                        if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                            dq1.append((nx,ny))
                            G_b[ny][nx] = True
                            G[ny][nx] = ct+1


        ct+=1
    
    print(G[gy-1][gx-1])
main()

Fixed submission:
from collections import deque
def main():
    h,w = map(int,input().split())
    sy,sx = map(int,input().split())
    gy,gx = map(int,input().split())
    S = []
    for _ in range(h):
        S.append(input())
    
    G = [[-1]*w for _ in range(h)]
    G_b = [[False]*w for _ in range(h)]
    v = [(1,0),(0,1),(-1,0),(0,-1)]
    ct = 0

    dq1 = deque([])
    dq1.append((sx-1,sy-1))
    G[sy-1][sx-1] = 0
    G_b[sy-1][sx-1] = True


    while dq1:

        g = set([])
        while dq1:
            x,y = dq1.popleft()
            g.add((x,y))
            for vx,vy in v:
                nx = x+vx
                ny = y+vy
                if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                    G_b[ny][nx] = True
                    G[ny][nx] = ct
                    dq1.append((nx,ny))

        
        while g:
            x,y = g.pop()
            for i in range(-2,3):
                for j in range(-2,3):
                    if i!=0 or j!=0:
                        nx = x+i
                        ny = y+j
                        if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                            dq1.append((nx,ny))
                            G_b[ny][nx] = True
                            G[ny][nx] = ct+1


        ct+=1
    
    print(G[gy-1][gx-1])

main()
Buggy python submission (verdict: Runtime Error):
def main():
    x = int(input())
    if x>=30:
        print("Yes")
    else:
        print("No")  
main(9

Fixed submission:
def main():
    x = int(input())
    if x>=30:
        print("Yes")
    else:
        print("No")  
main()
Buggy python submission (verdict: Runtime Error):
def main():
    k = int(input())
    
    if k == 7:
        print(1)
        sys.exit()
    
    r = 7%k
    g = {r}
    ans = 1
    while True:
        ans+=1
        r = (10*r+7)%k
        if r==0:
            print(ans)
            break
        if r in g:
            print(-1)
            break
        else:
            g.add(r)
main()

Fixed submission:
import sys
def main():
    k = int(input())
    
    if k == 7 or k == 1:
        print(1)
        sys.exit()
    
    r = 7%k
    g = {r}
    ans = 1
    while True:
        ans+=1
        r = (10*r+7)%k
        if r==0:
            print(ans)
            break
        if r in g:
            print(-1)
            break
        else:
            g.add(r)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    import bisect
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_ac = [0]
    B_ac = [0]
    a_ac = 0
    b_ac = 0
    for a in A:
        a_ac+=a
        A_ac.append(a_ac)
    for b in B:
        b_ac+=b
        B_ac.append(b_ac)
    
    i_mx = bisect.bisect_right(A_ac,k)
    i = i_mx-1
    ct = []

    while i > 0:
        k_left = k-A_ac[i]
        j = bisect.bisect_right(B_ac,k_left)-1
        ct.append(i+j)
        i-=1
    
    print(max(ct))
main()

Fixed submission:
def main():
    import bisect
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_ac = [0]
    B_ac = [0]
    a_ac = 0
    b_ac = 0
    for a in A:
        a_ac+=a
        A_ac.append(a_ac)
    for b in B:
        b_ac+=b
        B_ac.append(b_ac)
    
    i_mx = bisect.bisect_right(A_ac,k)
    i = i_mx-1
    ct = [0]

    while i >= 0:
        k_left = k-A_ac[i]
        j = bisect.bisect_right(B_ac,k_left)-1
        ct.append(i+j)
        i-=1
    

    print(max(ct))
main()
Buggy python submission (verdict: Runtime Error):
import io,sys
sys.setrecursionlimit(10**6)


def main():
    X,Y = map(int,sys.stdin.readline().rstrip().split())

    y = (Y-2*X)/2
    x = X-y

    if y>=0 and y == int(y) and x >= 0:
        print("Yes")
    else:
        print("No")
main()

Fixed submission:
import io,sys
sys.setrecursionlimit(10**6)


def main():
    X = list(map(int,sys.stdin.readline().rstrip().split()))
    g = set([0,1,2,3,4,5])

    a = list(g - set(X))
    print(a[0])
main()
Buggy python submission (verdict: Runtime Error):
def prime(n):
    nums = [True]*n
    primes = []
    for i in range(2,n):
        if nums[i]:
            primes.append(i)
            for j in range(2*i,n,i):
                nums[j] = False
    return primes

def prime_fac(n):
    fac = {}
    primes = prime(int(n**0.5)+1)
    for p in primes:
        while n%p==0:
            fac[p] = fac.get(p,0)+1
            n//=p
    if n > 1:
        fac[n] = 1
    return fac

def main():
    n = int(input())
    fac = prime_fac(n)

    ans = 0
    for i in fac.values():
        ct = 1
        while i >= ct*(ct+1)//2:
            ct += 1
            ans+=1
    print(ans)
main()

Fixed submission:
import io,sys
sys.setrecursionlimit(10**6)

def main():
    a,b =map(int,sys.stdin.readline().rstrip().split())
    print(a*b)
main()
Buggy python submission (verdict: Runtime Error):
import io,sys
sys.setrecursionlimit(10**6)

def main():
    s = sys.stdin.readline().rstrip().split()
    a = int(s[0])

    b = int(float(s[1])*100+0.1)

    print(ans=a*b//100)
main()

Fixed submission:
import io,sys
sys.setrecursionlimit(10**6)

def main():
    s = sys.stdin.readline().rstrip().split()
    a = int(s[0])

    b = int(float(s[1])*100+0.1)

    print(a*b//100)
main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = sys.stdin.readline().rstrip().split()
    a = int(s[0])

    b = int(float(s[1])*100)

    ans=a*b//100
    l = []
    while ans!=0:
        p = ans%10
        ans //=10
        l.append(p)
        
    for i in l[::-1]:
        print(i,end="")
main()

Fixed submission:
import io,sys
sys.setrecursionlimit(10**6)

def main():
    s = sys.stdin.readline().rstrip().split()
    a = int(s[0])

    b = int(float(s[1])*100+0.1)

    print(a*b//100)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    from sys import stdin
    n,k = map(int,stdin.readline().rstrip().split())
    As = list(map(int,stdin.readline().rstrip().split()))
    As = [0]+As
    g = set({1})
    l = [0,1]
    now = 1
    for i in range(1,k+1):
        now = As[now]
        if now in g:
            break
            
        else:
            g.add(now)
            l.append(now)

    j = l.index(now)
    print(l[j+(k-i)%(i+1-j)])
main()

Fixed submission:
def main():
    from sys import stdin
    n,k = map(int,stdin.readline().rstrip().split())
    As = list(map(int,stdin.readline().rstrip().split()))
    As = [0]+As
    g = set({1})
    l = [0,1]
    now = 1
    i = 0
    while True:
        i+=1
        now = As[now]
        if now in g:
            j = l.index(now)
            print(l[j+(k-i)%(i+1-j)])
            break
            
        else:
            g.add(now)
            l.append(now)
        
        if i == k:
            print(now)
            break
main()
Buggy python submission (verdict: Runtime Error):
ef main():
    from collections import Counter
    n = int(input())
    As = list(map(int,input().split(" ")))
    
    cnts = Counter()
    dp = [0]*n
    for i in range(1,n):
        dp[i] =dp[i-1] + cnts.get(i-As[i],0)
        cnts[As[i]+i]+=1
    print(dp[n-1])
main()

Fixed submission:
def main():
    from collections import Counter
    n = int(input())
    As = list(map(int,input().split(" ")))
    
    cnts = Counter()
    dp = [0]*n
    cnts[As[0]+1]+=1
    for i in range(1,n):
        dp[i] =dp[i-1] + cnts.get(i+1-As[i],0)
        cnts[As[i]+i+1]+=1
    print(dp[n-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    As = list(map(int,input().split(" ")))

    dp = [0]*(n+1)
    for i in range(1,n):
        temp = 0
        for j in range(i):
            if i-j == As[j]+As[i]:
                temp+=1
        dp[i] = dp[i-1]+temp
    print(dp[n-1])
main()

Fixed submission:
def main():
    from collections import Counter
    n = int(input())
    As = list(map(int,input().split(" ")))
    
    cnts = Counter()
    dp = [0]*n
    cnts[As[0]+1]+=1
    for i in range(1,n):
        dp[i] =dp[i-1] + cnts.get(i+1-As[i],0)
        cnts[As[i]+i+1]+=1
    print(dp[n-1])
main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ss = []
sum = 0
for i in range(n):
    s = input()
    if s not in ss:
        sum +=1
        ss.append(s)

print(sum)


Fixed submission:
n = int(input())
ss = set([])
for i in range(n):
    s = input()
    ss.add(s)

print(len(ss))
Buggy python submission (verdict: Runtime Error):
n = input()
if 7 in n:
    print("Yes")
else:
    print("No")

Fixed submission:
n = str(input())
seven = "7"
if seven in n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
sum =0

for  i in range(n):
    for j in range(i+1,n):
        flag = 0
        if s[i] == s[j]:
            continue
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            flag = 1
        
        s_new = s[j+1:]
        sum += n - j-1 - s_new.count(s[i]) - s_new.count(s[j]) - flag
        #print(s_new, flag, sum)

print(sum)


Fixed submission:
def main():
    n = int(input())
    s = input()
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    ans = r*g*b

    for i in range(n-2):
        for j in range(i+1,n-1):
            if s[i] != s[j]:
                if 2*j-i < n:
                    if s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                        ans-=1

    
    print(ans)

main()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split(" "))
houses = list(map(int, input().split(" ")))
dif_houses = [houses[x+1]-houses[x] for x in range(k-1)]
dif_houses.append(houses[0]-houses[k-1]+n)

max_dif = max(dif_houses)
print(n-max_dif)

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int,input().split(" "))
    s = [list(input()) for i in range(h)]
    
    dp = [[0]*h for i in range(w)]
    dp[0][0] = 1 if s[0][0]=="#" else 0

    for i in range(1,h):
        sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
        dp[i][0] = dp[i-1][0] + sgmdown
    
    for j in range(1,w):
        sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
        dp[0][j] = dp[0][j-1] + sgmright

    for i in range(1,h):
        for j in range(1,w):
            sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
            sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
            dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)

    print(dp[h-1][w-1])
main()

Fixed submission:
def main():
    h,w = map(int,input().split(" "))
    s = [list(input()) for i in range(h)]
    
    dp = [[0]*w for i in range(h)]
    dp[0][0] = 1 if s[0][0]=="#" else 0

    for i in range(1,h):
        sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
        dp[i][0] = dp[i-1][0] + sgmdown
    
    for j in range(1,w):
        sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
        dp[0][j] = dp[0][j-1] + sgmright

    for i in range(1,h):
        for j in range(1,w):
            sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
            sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
            dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)

    print(dp[h-1][w-1])
main()

Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int,input().split(" "))
    s = [list(input()) for i in range(h)]
    
    dp = [[0]*h for i in range(w)]
    dp[0][0] = 1 if s[0][0]==1 else 0

    for i in range(1,h):
        sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
        dp[i][0] = dp[i-1][0] + sgmdown
    
    for j in range(1,w):
        sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
        dp[0][j] = dp[0][j-1] + sgmright

    for i in range(1,h):
        for j in range(1,w):
            sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
            sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
            dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)

    print(dp[h-1][w-1])
main()

Fixed submission:
def main():
    h,w = map(int,input().split(" "))
    s = [list(input()) for i in range(h)]
    
    dp = [[0]*w for i in range(h)]
    dp[0][0] = 1 if s[0][0]=="#" else 0

    for i in range(1,h):
        sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
        dp[i][0] = dp[i-1][0] + sgmdown
    
    for j in range(1,w):
        sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
        dp[0][j] = dp[0][j-1] + sgmright

    for i in range(1,h):
        for j in range(1,w):
            sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
            sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
            dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)

    print(dp[h-1][w-1])
main()