Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import *

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(int(ans), end="")


Fixed submission:
# from math import *
from fractions import *

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans)

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

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans,end="")


Fixed submission:
# from math import *
from fractions import *

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans)

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

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans)


Fixed submission:
# from math import *
from fractions import *

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if (2 % a * b == 0): 
    print("Even")
if (2 % a * b != 0):
    print("0dd")
    
    

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

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if (2 % a * b == 0) print("Even")
if (2 % a * b != 0) print("0dd")
    

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 0:print("Even")
if a * b % 2 != 0:print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
import queue
def tree(edges, n, q):
    distance = [0]*(n+1)
    visited = [0]*(n+1)
    for _ in range(0, q):
        p, x = map(int, input().split())
        distance[p] += x
    Q = queue.Queue()
    Q.put(1)
    visited[1] = 1
    while (not Q.empty()):
        xx = Q.get()
        for i in range(0, len(edges[xx])):
            if visited[edges[xx][i]]:
                continue
            distance[edges[xx][i]] += distance[xx]
            Q.put(edges[xx][i])
            visited[edges[xx][i]] = 1
    return distance[1:]
def addEdge(edges, u, v):
    edges[u].append(v)
    edges[v].append(u)
n, q = map(int, input().split())
edges = [[] for i in range(n + 1)]
for _ in range(0, n - 1):
    u, v = map(int, input().split())
    addEdge(edges, u, v)
print(*tree(edges, n, q))

Fixed submission:
from collections import deque
def tree(edges, n, q):
    distance = [0]*(n+1)
    visited = [0]*(n+1)
    for _ in range(0, q):
        p, x = map(int, input().split())
        distance[p] += x
    Q = deque([])
    Q.append(1)
    visited[1] = 1
    while Q:
        xx = Q.popleft()
        for i in range(0, len(edges[xx])):
            if visited[edges[xx][i]]:
                continue
            distance[edges[xx][i]] += distance[xx]
            Q.append(edges[xx][i])
            visited[edges[xx][i]] = 1
    return distance[1:]
def addEdge(edges, u, v):
    edges[u].append(v)
    edges[v].append(u)
n, q = map(int, input().split())
edges = [[] for i in range(n + 1)]
for _ in range(0, n - 1):
    u, v = map(int, input().split())
    addEdge(edges, u, v)
print(*tree(edges, n, q))

Buggy python submission (verdict: Time Limit Exceeded):
import queue
def tree(edges,n,q):
    distance = [0]*(n+1)
    for _ in range(0,q):
        p,x = map(int,input().split())
        Q = queue.Queue()
        Q.put(p)
        distance[p] += x
        while (not Q.empty()):
            xx = Q.get()
            for i in range(0,len(edges[xx])):
                distance[edges[xx][i]] += x
                Q.put(edges[xx][i])
    return distance[1:]

def addEdge(edges,u,v):
    edges[u].append(v)
n,q = map(int,input().split())
edges = [[] for i in range(n+1)]
for _ in range(0,n-1):
    u,v = map(int,input().split())
    addEdge(edges,u,v)
print(*tree(edges,n,q))


Fixed submission:
from collections import deque
def tree(edges, n, q):
    distance = [0]*(n+1)
    visited = [0]*(n+1)
    for _ in range(0, q):
        p, x = map(int, input().split())
        distance[p] += x
    Q = deque([])
    Q.append(1)
    visited[1] = 1
    while Q:
        xx = Q.popleft()
        for i in range(0, len(edges[xx])):
            if visited[edges[xx][i]]:
                continue
            distance[edges[xx][i]] += distance[xx]
            Q.append(edges[xx][i])
            visited[edges[xx][i]] = 1
    return distance[1:]
def addEdge(edges, u, v):
    edges[u].append(v)
    edges[v].append(u)
n, q = map(int, input().split())
edges = [[] for i in range(n + 1)]
for _ in range(0, n - 1):
    u, v = map(int, input().split())
    addEdge(edges, u, v)
print(*tree(edges, n, q))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ss = [1]*n
for i in range(0,m):
    ss[int(input())-1] = 0
if ss[n-3] != 0:
    ss[n-3] = ss[n-2]+ ss[n-1]
for i in range(n-4,-1,-1):
    if ss[i] == 0:
        continue
    ss[i] = ss[i+1] + ss[i+2]
print((ss[0]+ss[1])%(10**9+7))

Fixed submission:
n,m = map(int,input().split())
ss = [1]*n
for i in range(0,m):
    ss[int(input())-1] = 0
if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == 2:
    if ss[0] == 0:
        print(1)
    else:
        print(2)
else:
    if ss[n-3] != 0:
        ss[n-3] = ss[n-2]+ ss[n-1]
    for i in range(n-4,-1,-1):
        if ss[i] == 0:
            continue
        ss[i] = ss[i+1] + ss[i+2]
    print((ss[0]+ss[1])%(10**9+7))
Buggy python submission (verdict: Runtime Error):
A,B = [int(c) for c in input().strip().split('')]
if 2*B>A:
  print(0)
else:
  print(A-2*B)

Fixed submission:
A,B = [int(c) for c in input().strip().split(' ')]
if A>2*B:
    print(A-2*B)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
A= [int(c) for c in input().strip().split(' ')]
# s = input().strip()
A = sorted(A)
i,j,k=0,1,2
cnt =0
# print(A)
for i in range(n):
    for j in range(i+1,n):
         for k in range(j+1,n):
             if A[k] < A[j]+A[i]:
                 cnt+=1
print(cnt)

Fixed submission:

n = int(input())
A= [int(c) for c in input().strip().split(' ')]
# s = input().strip()
A = sorted(A)
cnt =0
for i in range(n-1,1,-1):
    l,r=0,i-1

    while(l<r):
        # print(l,r,i)
        if(A[l]+A[r]>A[i]):
            cnt+=r-l
            r-=1
        else:
            l+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
input()
a,b=map(int,input().split())
print(int(max(0,a-2*b)))

Fixed submission:
a,b = map(int,input().split())
print(max(0,a-2*b))

Buggy python submission (verdict: Runtime Error):
gomi=input()
tako=[int(i) for i in input().split()]
print(int((sum(tako)**2-sum([i**2 for i in tako]))/2))  

Fixed submission:
a,b = map(int,input().split())
print(max(0,a-2*b))
Buggy python submission (verdict: Runtime Error):
gomi=input()
tako= [i for i in input().split()]
print((sum(tako)**2-sum([i**2 for i in tako]))/2)

Fixed submission:
gomi=input()
tako=[int(i) for i in input().split()]
print(int((sum(tako)**2-sum([i**2 for i in tako]))/2))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int,input().split())
a = []
c = []
for i in range(M):
    a_,b=map(int,input().split())
    a.append(a_)
    c_tmp = list(map(int, input().split()))
    tmp=0
    for j in range(len(c_tmp)):
        tmp+=2**(c_tmp[j]-1)
    c.append(tmp)
INF = N*1e+6
dp = [INF]*2**N
dp[0]=0

for i in range(2**N):
    for j in range(M):
        dp[i|c[j]]=min(dp[i|c[j]], dp[i]+a[j])
if dp[2**N-1]==INF:
    print(-1)
    sys.exit()
print(dp[2**N-1])



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

N, M = map(int,input().split())
a = []
c = []
for i in range(M):
    a_,b=map(int,input().split())
    a.append(a_)
    c_tmp = list(map(int, input().split()))
    tmp=0
    for j in range(len(c_tmp)):
        tmp+=2**(c_tmp[j]-1)
    c.append(tmp)
INF = N*1e+6
dp = [INF]*2**N
dp[0]=0

for i in range(2**N):
    for j in range(M):
        dp[i|c[j]]=min(dp[i|c[j]], dp[i]+a[j])
if dp[2**N-1]==INF:
    print(-1)
    sys.exit()
print(dp[2**N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import bisect

N = int(input())
s = input().split() 
s = list(s[0])

dp = [[0]*(N+1) for _ in range(N+1)]
ans=0
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if s[i]==s[j]:
            dp[i][j]=min(abs(j-i),dp[i+1][j+1]+1)
            ans = max(ans,dp[i][j])
#print(dp)
print(ans)
        


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

import bisect

N = int(input())
s = input().split() 
s = list(s[0])

dp = [[0]*(N+1) for _ in range(N+1)]
ans=0
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if s[i]==s[j]:
            dp[i][j]=min(abs(j-i),dp[i+1][j+1]+1)
            ans = max(ans,dp[i][j])
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import bisect

N = int(input())
s = input().split() 
s = list(s[0])
alf_i = [[] for _ in range(26)]

for i in range(N):
    alf_i[ord(s[i])-97].append(i)


ans=0
for i in range(N):
    x = bisect.bisect_left(alf_i[ord(s[i])-97], i)
    for j in range(x+1,len(alf_i[ord(s[i])-97])):
        y = alf_i[ord(s[i])-97][j]
        cnt=0
        while y+cnt<N and s[i+cnt]==s[y+cnt]:
            if i+cnt==y:
                break
            cnt+=1
        ans = max(cnt,ans)
print(ans)



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

import bisect

N = int(input())
s = input().split() 
s = list(s[0])

dp = [[0]*(N+1) for _ in range(N+1)]
ans=0
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if s[i]==s[j]:
            dp[i][j]=min(abs(j-i),dp[i+1][j+1]+1)
            ans = max(ans,dp[i][j])
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import bisect

N = int(input())
s = input().split() 
s = list(s[0])
alf_i = [[] for _ in range(26)]

for i in range(N):
    alf_i[ord(s[i])-97].append(i)


ans=0
for i in range(N):
    x = bisect.bisect_left(alf_i[ord(s[i])-97], i)
    for j in range(x+1,len(alf_i[ord(s[i])-97])):
        y = alf_i[ord(s[i])-97][j]
        cnt=0
        while y+cnt<N and s[i+cnt]==s[y+cnt]:
            if i+cnt==y:
                break
            cnt+=1
        ans = max(cnt,ans)
print(ans)



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

import bisect

N = int(input())
s = input().split() 
s = list(s[0])

dp = [[0]*(N+1) for _ in range(N+1)]
ans=0
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if s[i]==s[j]:
            dp[i][j]=min(abs(j-i),dp[i+1][j+1]+1)
            ans = max(ans,dp[i][j])
#print(dp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            count += 1
        else:
            break
print(count)

Fixed submission:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
count = 0
ren = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1+ren
        ren += 1
    else:
        ren = 0
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input().split() for i in range(N)]
s_af = [""]*N
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    for k in range(10):
        s_af[i] += s[i][k]
s_af.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        if s_af[i] == s_af[j]:
            count += 1
        else:
            break
print(count)

Fixed submission:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
count = 0
ren = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1+ren
        ren += 1
    else:
        ren = 0
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
s.sort()
s_af = [""]*N
for i in range(N):
    for k in range(10):
        s_af[i] += s[i][k]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if s_af[i] == s_af[j]:
            count += 1
        else:
            break
print(count)

Fixed submission:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
count = 0
ren = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1+ren
        ren += 1
    else:
        ren = 0
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
s.sort()
count = 0
for i in range(N):
    for j in range(i+1, N):
        Flag = True
        for k in range(10):
            if s[i][k] != s[j][k]:
                Flag = False
                break
        if Flag:
            count += 1
        else:
            break
print(count)
            

Fixed submission:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
count = 0
ren = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1+ren
        ren += 1
    else:
        ren = 0
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
A = list(map(int, input().split()))
sumA = sum(A)

yakusu = []
for i in range(1,int(sumA**0.5)+1):
    if sumA%i==0:
        yakusu.append(i)
        if sumA//i!=i:
            yakusu.append(sumA//i)
yakusu.sort(reverse=True)

for x in yakusu:
    tmp = list(map(lambda y: y%x, A))
    tmp.sort()
    for i in range(N):
        minuscnt = sum(tmp[:i+1])
        pluscnt = x*(N-i-1)-sum(tmp[i+1:])
        if minuscnt%x == pluscnt%x and K >= max(minuscnt,pluscnt):
            print(x)
            sys.exit()


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

N, K = map(int,input().split())
A = list(map(int, input().split()))
sumA = sum(A)

yakusu = []
for i in range(1,int(sumA**0.5)+1):
    if sumA%i==0:
        yakusu.append(i)
        if sumA//i!=i:
            yakusu.append(sumA//i)
yakusu.sort(reverse=True)

for x in yakusu:
    tmp = list(map(lambda y: y%x, A))
    tmp.sort()
    for i in range(N):
        minuscnt = sum(tmp[:i+1])
        pluscnt = x*(N-i-1)-sum(tmp[i+1:])
        if minuscnt%x == pluscnt%x and K >= max(minuscnt,pluscnt):
            print(x)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def main():  
    S = list(input())
    S.pop()
    length=len(S)
    dp = [0]*13
    dp[0]=1
    mul=1
    mod=1000000007
    for i in range(1,length+1):
        next_dp = [0]*13
        for j in range(13):
            if S[length-i] == "?":
                for k in range(10):
                    j_sub=(j+k*mul)%13
                    next_dp[j_sub]+=dp[j]
                    next_dp[j_sub]%=mod
            else:
                j_sub=(j+int(S[length-i])*mul)%13
                next_dp[j_sub]+=dp[j]
                next_dp[j_sub]%=mod
        dp=next_dp
        mul=mul*10
    print(dp[5]%1000000007, "d")
if __name__ == "__main__":
    main()

Fixed submission:
A,B = list(map(int,input().split()))
if A > B:
    tmp = A
    A = B
    B = tmp

if (B-A)%2 == 0:
    print(B-(B-A)//2)
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
a = [input() for i in range(N)]
a = list(map(int, a))

for i in range(N):
    a_copy = copy.copy(a)
    a_copy.pop(i)
    print(max(a_copy))


Fixed submission:
import copy
N = int(input())
a = [input() for i in range(N)]
a = list(map(int, a))
max_a = sub_max_a = max(a)
count = 0
for i in range(N):
    if max_a == a[i]:
        count += 1
        max_i = i
if count == 1:
    a.pop(max_i)
    sub_max_a = max(a)

for j in range(N):
    if max_i == j:
        print(sub_max_a)
    else:
        print(max_a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]%1000000007
def f(n,k):
    if n-k<0: return 0
    if n==k: return 1
    if k<1: return 0
    return f2(n-k,k)%1000000007

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%1000000007))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]%1000000007
def f(n,k):
    if n-k<0: return 0
    if n==k: return 1
    if k<1: return 0
    return f2(n-k,k)%1000000007

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%1000000007))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]
def f(n,k):
    if n-k<0: return 0
    if k<1: return 0
    return f2(n-k,k)%((1e+9)+7)

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%(1e+9+7)))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]%1000000007
def f(n,k):
    if n-k<0: return 0
    if n==k: return 1
    if k<1: return 0
    return f2(n-k,k)%1000000007

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%1000000007))
Buggy python submission (verdict: Runtime Error):
import fanctions
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//fanctions.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))

Fixed submission:
import fractions
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//fractions.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//math.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))

Fixed submission:
import fractions
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//fractions.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

from collections import deque

def main(): 
    H,W = map(int,input().split())
    S = [input().split() for _ in range(H)]
    for i in range(H):
        S[i]=list(S[i][0])
    grid = [[0]*W for _ in range(H)]
    
    for i in range(H):
        l=0
        for j in range(W):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i][j-k]+=l
                l=0
            else:
                l+=1
        for k in range(1,l+1):
                    grid[i][W-k]+=l
    max=0
    for j in range(W):
        l=0
        for i in range(H):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i-k][j]+=l
                    if grid[i-k][j] > max:
                        max = grid[i-k][j]
                l=0
            else:
                l+=1
        for k in range(1,l+1):
            grid[H-k][j]+=l
            if grid[H-k][j] > max:
                        max = grid[H-k][j]
    print(max-1)
if __name__ == "__main__":
    main()
    

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

from collections import deque

def main(): 
    H,W = map(int,input().split())
    S = [input().split() for _ in range(H)]
    for i in range(H):
        S[i]=list(S[i][0])
    grid = [[0]*W for _ in range(H)]
    
    for i in range(H):
        l=0
        for j in range(W):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i][j-k]+=l
                l=0
            else:
                l+=1
        for k in range(1,l+1):
                    grid[i][W-k]+=l
    max=0
    for j in range(W):
        l=0
        for i in range(H):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i-k][j]+=l
                    if grid[i-k][j] > max:
                        max = grid[i-k][j]
                l=0
            else:
                l+=1
        for k in range(1,l+1):
            grid[H-k][j]+=l
            if grid[H-k][j] > max:
                        max = grid[H-k][j]
    print(max-1)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import math

def main(): 

    N=int(input())
    to=[[] for _ in range(N+1)]
    ans=[0]*(N+1)

    for i in range(N-1):
        u,v,w=map(int,input().split())
        print(u,v,w)
        to[u].append([v,w])
        to[v].append([u,w])
    
    def dfs(chil, par):
        for v,l in to[chil]:
            if v == par: continue
            if (ans[chil] == 1 and l%2==0) or (ans[chil] == 0 and l%2==1):
                ans[v]=1
            dfs(v,chil)
    
    ans[1] = 1
    dfs(1,-1)
    print(*ans[1:])
if __name__ == "__main__":
    main()
    

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

sys.setrecursionlimit(1000000)

def main(): 

    N=int(input())
    to=[[] for _ in range(N+1)]
    ans=[0]*(N+1)

    for i in range(N-1):
        u,v,w=map(int,input().split())
        to[u].append([v,w])
        to[v].append([u,w])
    
    def dfs(chil, par):
        for v,l in to[chil]:
            if v == par: continue
            if (ans[chil] == 1 and l%2==0) or (ans[chil] == 0 and l%2==1):
                ans[v]=1
            dfs(v,chil)
    
    #ans[1] = 1
    dfs(1,-1)
    for i in ans[1:]:
        print(i)
if __name__ == "__main__":
    main()