Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

donguri=N

inc=0
for i in range(0,donguri//ga+1):
    x=(ga<gb)*i
    for j in range(0,donguri//sa+1):
        y=(sa<sb)*j
        if donguri>=x*ga+y*sa:
            z=((donguri-x*ga-y*sa)//ba)*(ba<bb)
            inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

donguri+=inc

inc=0
for i in range(0,donguri//gb+1):
    x=(ga>gb)*i
    for j in range(0,donguri//sb+1):
        y=(sa>sb)*j
        if donguri>=x*gb+y*sb:
            z=((donguri-x*gb-y*sb)//bb)*(ba>bb)
            inc=max(inc,-x*(gb-ga)-y*(sb-sa)-z*(bb-ba))

donguri+=inc
print(donguri)


Fixed submission:
N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

check=(gb>ga)+(sb>sa)+(bb>ba)
if check==3:
    donguri=N

    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    print(donguri)
elif check==0:
    donguri=N
    inc=0
    for i in range(0,donguri//gb+1):
        x=(ga>gb)*i
        for j in range(0,donguri//sb+1):
            y=(sa>sb)*j
            if donguri>=x*gb+y*sb:
                z=((donguri-x*gb-y*sb)//bb)*(ba>bb)
                inc=max(inc,-x*(gb-ga)-y*(sb-sa)-z*(bb-ba))

    donguri+=inc
    print(donguri)

elif check==2:
    donguri=N
    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    if ga>gb:
        plus=(donguri//gb)*(ga-gb)
        print(donguri+plus)
    elif sa>sb:
        plus=(donguri//sb)*(sa-sb)
        print(donguri+plus)
    elif ba>bb:
        plus=(donguri//bb)*(ba-bb)
        print(donguri+plus)
    else:
        print(donguri)

else:
    donguri=N
    inc=0
    if ga<gb:
        plus=(donguri//ga)*(gb-ga)
        donguri+=plus
        if sa>sb:
            for i in range(0,donguri//sb+1):
                j=(donguri-i*sb)//bb
                inc=max(inc,i*(sa-sb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)

    elif sa<sb:
        plus=(donguri//sa)*(sb-sa)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//bb
                inc=max(inc,i*(ga-gb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)
    else:
        plus=(donguri//ba)*(bb-ba)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//sb
                inc=max(inc,i*(ga-gb)+j*(sa-sb))
            print(donguri+inc)
        else:
            inc=(donguri//sb)*(sa-sb)
            print(donguri+inc)
Buggy python submission (verdict: Runtime Error):
def fibonacci(n,memo={}):
    if n<0:
        return 0
    elif n==1 or n==0:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n]=fibonacci(n-1,memo)+fibonacci(n-2,memo)
        return memo[n]

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))

Fixed submission:
def fibonacci(n):
    if n<0:
        return 0
    else:
        a=1
        b=1
        if n==0:
            return a
        elif n==1:
            return b
        else:
            i=n-2
            while i>=0:
                x=a
                a=b
                b=x+b
                i=i-1
            return b

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))

Buggy python submission (verdict: Runtime Error):
def fibonacci(n):
    if n<0:
        return 0
    if n==1 or n==0:
        return 1
    else:
        return fibonacci(n-1)+fibonacci(n-2)

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))

Fixed submission:
def fibonacci(n):
    if n<0:
        return 0
    else:
        a=1
        b=1
        if n==0:
            return a
        elif n==1:
            return b
        else:
            i=n-2
            while i>=0:
                x=a
                a=b
                b=x+b
                i=i-1
            return b

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))

Buggy python submission (verdict: Runtime Error):
def fibonacci(n):
    if n==-1:
        return 0
    if n==1 or n==0:
        return 1
    else:
        return fibonacci(n-1)+fibonacci(n-2)

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))


Fixed submission:
def fibonacci(n):
    if n<0:
        return 0
    else:
        a=1
        b=1
        if n==0:
            return a
        elif n==1:
            return b
        else:
            i=n-2
            while i>=0:
                x=a
                a=b
                b=x+b
                i=i-1
            return b

N,M=map(int,input().split())
a=[]
for _ in range(0,M):
    a.append(int(input()))
a.append(N+1)
m=1
for i in range(0,M+1):
    if i==0:
        m=fibonacci(a[i]-1)
    else:
        m=m*fibonacci(a[i]-a[i-1]-2)

print(m%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))

base=sum(V)
ans=base
for i in range(K+1):
    for j in range(K-i+1):
        tmp=[V[k] for k in range(i)]
        for k in range(j):
            tmp.append(V[-1-k])
        tmp.sort()
        rest=K-i-j
        minus=0
        base=sum(tmp)
        for k in range(min(rest,len(tmp))):
            if tmp[k]<0:
                minus+=tmp[k]
            else:
                break
        test=base-minus
        ans=max(ans,test)

print(ans)


Fixed submission:
import copy,heapq

N,K=map(int,input().split())
V=list(map(int,input().split()))

ans=0
left=copy.copy(V)
for i in range(1,N):
    left[i]+=left[i-1]
right=copy.copy(V)
for i in range(1,N):
    right[-i-1]+=right[-i]
for i in range(0,N+1):
    for j in range(0,N-i+1):
        dispose=K-i-j
        if 0>dispose:
            continue
        test=0
        q=[]
        if i>0:
            test+=left[i-1]
            q+=V[:i]
        if j>0:
            test+=right[-j]
            q+=V[N-j:N]

        heapq.heapify(q)
        while dispose>0 and q:
            x=heapq.heappop(q)
            if 0>x:
                test-=x
                dispose-=1
            else:
                break
        ans=max(ans,test)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
u=[0 for i in range(0,N-1)]
v=[0 for i in range(0,N-1)]
w=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    u[i],v[i],w[i]=map(int,input().split())
w=[w[i]%2 for i in range(0,N-1)]
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[u[i]].append([v[i],w[i]])
    hen[v[i]].append([u[i],w[i]])
ans=[[0,0] for i in range(0,N+1)]
ans[1]=[0,1]
q=[]
q.append(1)
sub=[]
while q!=[]:
    while q!=[]:
        x=q[0]
        q.remove(x)
        if ans[x][0]==0:
            for p in hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=0
                    else:
                        ans[s][0]=1
                    sub.append(s)
                    ans[s][1]=1
        else:
            for p in  hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=1
                    else:
                        ans[s][0]=0
                    sub.append(s)
                    ans[s][1]=1
        if q==[]:
            q=sub
            sub=[]
            break
ans[0]=100
ans.remove(100)
for i in range(0,N):
    print(ans[i][0])

Fixed submission:
import heapq as h

N=int(input())
u=[0 for i in range(0,N-1)]
v=[0 for i in range(0,N-1)]
w=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    u[i],v[i],w[i]=map(int,input().split())
w=[w[i]%2 for i in range(0,N-1)]
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[u[i]].append([v[i],w[i]])
    hen[v[i]].append([u[i],w[i]])
ans=[[0,0] for i in range(0,N+1)]
ans[1]=[0,1]
q=[]
q.append(1)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        if ans[x][0]==0:
            for p in hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=0
                    else:
                        ans[s][0]=1
                    h.heappush(sub,s)
                    ans[s][1]=1
        else:
            for p in  hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=1
                    else:
                        ans[s][0]=0
                    h.heappush(sub,s)
                    ans[s][1]=1
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break
ans[0]=100
ans.remove(100)
for i in range(0,N):
    print(ans[i][0])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby

N,K=map(int,input().split())
S=input()
def condition(num):
    flag=0
    for i in range(0,N-num+1):
        test=[]
        count=0
        for j in range(i,i+num):
            test.append(int(S[j]))
        test=groupby(test)
        for key,group in test:
            if key==0:
                count+=1
        if K>=count:
            flag=1
    return flag==1
start=1
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test
if condition(end):
    print(end)
else:
    print(start)

Fixed submission:
from itertools import groupby

N,K=map(int,input().split())
S=input()
def condition(num):
    flag=0
    first=[int(S[i]) for i in range(0,N-num+1)]
    last=[int(S[i+num-1]) for i in range(0,N-num+1)]
    test=[]
    for i in range(0,num):
        test.append(int(S[i]))
    sub=groupby(test)
    count=0
    for key,group in sub:
        if key==0:
            count+=1
    if K>=count:
        flag=1
    for i in range(1,N-num+1):
        if first[i-1]==0 and first[i]==1:
            count-=1
        if last[i-1]==1 and last[i]==0:
            count+=1
        if K>=count:
            flag=1
    return flag==1
start=1
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test
if condition(end):
    print(end)
else:
    print(start)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())
edge=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

odd=0
f=0
s=0
v=[]
for i in range(N):
    if len(edge[i])%2==1:
        odd+=1
    elif len(edge[i])==4:
        f+=1
        v.append(i)
    elif len(edge[i])>=6:
        s+=1

if odd>0:
    print("No")
else:
    if s>0:
        print("Yes")
    elif f>2:
        print("Yes")
    elif f!=2:
        print("No")
    else:
        start=v[0]
        ban=v[1]
        check=False
        def dfs(V,pv):
            global check
            if V==start and pv==-1:
                for i in edge[start]:
                    if i!=ban:
                        dfs(i,start)
            elif V==start:
                check=True
            else:
                for i in edge[V]:
                    if i!=ban and i!=pv:
                        dfs(i,V)
        dfs(start,-1)
        if check:
            print("Yes")
        else:
            print("No")


Fixed submission:
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())
edge=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

odd=0
f=0
s=0
v=[]
for i in range(N):
    if len(edge[i])%2==1:
        odd+=1
    elif len(edge[i])==4:
        f+=1
        v.append(i)
    elif len(edge[i])>=6:
        s+=1

if odd>0:
    print("No")
else:
    if s>0:
        print("Yes")
    elif f>2:
        print("Yes")
    elif f!=2:
        print("No")
    else:
        start=v[0]
        ban=v[1]
        check=False
        def dfs(V,pv):
            global check
            if V==start and pv==-1:
                for i in edge[start]:
                    if i!=ban:
                        dfs(i,start)
            elif V==start:
                check=True
            else:
                for i in edge[V]:
                    if i!=ban and i!=pv:
                        dfs(i,V)
        dfs(start,-1)
        if check:
            print("Yes")
        else:
            print("No")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split());mod=998244353;B=[]
for i in range(N):
    s=int(input().split().replace(" ",""),2)
    for b in B:s=min(s,s^b)
    if s!=0:B.append(s)
print((pow(2,N+M-1,mod)*(1-pow(2,mod-1-len(B),mod)))%mod)

Fixed submission:
N,M=map(int,input().split())
a=[]
for i in range(N):
    a.append(list(map(int,input().split())))
mod=998244353

B=[]
for i in range(M):
    b=0
    for j in range(N):
        b+=a[j][i]*2**j
    B.append(b)

base=[]
for i in range(M):
    t=B[i]
    for b in base:
        t=min(t,t^b)
    if t!=0:
        base.append(t)

res=M-len(base)
ans=pow(2,N-1,mod)*(pow(2,M,mod)-pow(2,res,mod))
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as h
import sys

input=sys.stdin.readline


N,M=map(int,input().split())
to=[[] for i in range(0,N)]
fr=[[] for i in range(0,N)]
for i in range(0,N+M-1):
    a,b=map(int,input().split())
    to[a-1].append(b-1)
    fr[b-1].append(a-1)

root=-1
for i in range(0,N):
    if fr[i]==[]:
        root=i
        break


parent=[-1 for i in range(0,N)]
q=[]
q.append(root)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in to[x]:
            h.heappush(sub,p)
            parent[p]=x
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

for i in range(0,N):
    print(parent[i]+1)


Fixed submission:
import heapq as h
import sys

input=sys.stdin.readline


N,M=map(int,input().split())
to=[set([]) for i in range(0,N)]
fr=[set([]) for i in range(0,N)]
for i in range(0,N+M-1):
    a,b=map(int,input().split())
    to[a-1].add(b-1)
    fr[b-1].add(a-1)

root=-1
for i in range(0,N):
    if fr[i]==set([]):
        root=i
        break

parent=[-1 for i in range(0,N)]
visited=set([])
q=[]
q.append(root)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        visited.add(x)
        for p in to[x]:
            if visited>=fr[p]:
                h.heappush(sub,p)
                parent[p]=x
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

for i in range(0,N):
    print(parent[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq as h

N,M=map(int,input().split())
to=[[] for i in range(0,N)]
fr=[[] for i in range(0,N)]
for i in range(0,N+M-1):
    a,b=map(int,input().split())
    to[a-1].append(b-1)
    fr[b-1].append(a-1)

root=-1
for i in range(0,N):
    if fr[i]==[]:
        root=i
        break


parent=[-1 for i in range(0,N)]
q=[]
q.append(root)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in to[x]:
            h.heappush(sub,p)
            parent[p]=x
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

for i in range(0,N):
    print(parent[i]+1)

Fixed submission:
import heapq as h
import sys

input=sys.stdin.readline


N,M=map(int,input().split())
to=[set([]) for i in range(0,N)]
fr=[set([]) for i in range(0,N)]
for i in range(0,N+M-1):
    a,b=map(int,input().split())
    to[a-1].add(b-1)
    fr[b-1].add(a-1)

root=-1
for i in range(0,N):
    if fr[i]==set([]):
        root=i
        break

parent=[-1 for i in range(0,N)]
visited=set([])
q=[]
q.append(root)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        visited.add(x)
        for p in to[x]:
            if visited>=fr[p]:
                h.heappush(sub,p)
                parent[p]=x
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

for i in range(0,N):
    print(parent[i]+1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
h=list(map(int,input().split()))

memo=[-1 for i in range(0,N)]
memo[-1]=0
memo[-2]=abs(h[-2]-h[-1])

def ans(num):
    if memo[num]!=-1:
        return memo[num]

    memo[num]=min(ans(num+1)+abs(h[num+1]-h[num]),ans(num+2)+abs(h[num+2]-h[num]))

    return memo[num]

print(ans(0))

Fixed submission:
import sys

sys.setrecursionlimit(1000000)

N=int(input())
h=list(map(int,input().split()))

memo=[-1 for i in range(0,N)]
memo[-1]=0
memo[-2]=abs(h[-2]-h[-1])

def ans(num):
    if memo[num]!=-1:
        return memo[num]

    memo[num]=min(ans(num+1)+abs(h[num+1]-h[num]),ans(num+2)+abs(h[num+2]-h[num]))

    return memo[num]

print(ans(0))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    a=[]
    for i in range(N):
        a.append(list(map(int,input().split())))
    mod=10**9+7
    
    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=bin(i).count("1")
        for j in range(N):
            if i>>j&1==1:
                dp[i]+=dp[i-2**j]*a[m-1][j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()

Fixed submission:
def main():
    N=int(input())
    a=[]
    for i in range(N):
        a.append(list(map(int,input().split())))
    mod=10**9+7

    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=[j for j in range(N) if i>>j &1==1]
        for j in m:
            dp[i]+=dp[i-2**j]*a[len(m)-1][j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    a=[]
    for i in range(N):
        a.append(list(map(int,input().split())))
    mod=10**9+7
    
    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=bin(i).count("1")
        for j in range(N):
            if i>>j&1==1 and a[m-1][j]==1:
                dp[i]+=dp[i-2**j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()
    

Fixed submission:
def main():
    N=int(input())
    a=[]
    for i in range(N):
        a.append(list(map(int,input().split())))
    mod=10**9+7

    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=[j for j in range(N) if i>>j &1==1]
        for j in m:
            dp[i]+=dp[i-2**j]*a[len(m)-1][j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    a=[]
    for i in range(N):
        A=list(map(int,input().split()))
        a.append(sum(2**i*A[i] for i in range(N)))
    mod=10**9+7
    
    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=bin(i).count("1")
        for j in range(N):
            if (i&a[m-1])>>j&1==1:
                dp[i]+=dp[i-2**j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()

Fixed submission:
def main():
    N=int(input())
    a=[]
    for i in range(N):
        a.append(list(map(int,input().split())))
    mod=10**9+7

    dp=[0]*(2**N)
    dp[0]=1
    for i in range(1,2**N):
        m=[j for j in range(N) if i>>j &1==1]
        for j in m:
            dp[i]+=dp[i-2**j]*a[len(m)-1][j]
        dp[i]%=mod
    
    print(dp[-1])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline

sys.setrecursionlimit(100000)

N=int(input())
edge={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
mod=10**9+7

parent={i:0 for i in range(1,N+1)}

q=set([1])
sub=set([])
while q:
    while q:
        x=q.pop()
        for p in edge[x]:
            if p!=1 and parent[p]==0:
                parent[p]=x
                sub.add(p)

        if not q:
            q=sub
            sub=set([])
            break


def dfs(num):
    if len(edge[num])==1 and num!=1:
        return (1,1)

    WHITE=1
    BLACK=1
    for i in edge[num]:
        if i!=parent[num]:
            s,t=dfs(i)
            WHITE=(WHITE*(s+t))%mod
            BLACK=(BLACK*s)%mod

    return (WHITE,BLACK)

w,b=dfs(1)
print((w+b)%mod)

Fixed submission:
import sys

input=sys.stdin.readline

sys.setrecursionlimit(100000)

N=int(input())
edge={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
mod=10**9+7

parent={i:0 for i in range(1,N+1)}

q=set([1])
sub=set([])
while q:
    while q:
        x=q.pop()
        for p in edge[x]:
            if p!=1 and parent[p]==0:
                parent[p]=x
                sub.add(p)

        if not q:
            q=sub
            sub=set([])
            break


def dfs(num):
    if len(edge[num])==1 and num!=1:
        return (1,1)

    WHITE=1
    BLACK=1
    for i in edge[num]:
        if i!=parent[num]:
            s,t=dfs(i)
            WHITE=(WHITE*(s+t))%mod
            BLACK=(BLACK*s)%mod

    return (WHITE,BLACK)

w,b=dfs(1)
print((w+b)%mod)
Buggy python submission (verdict: Runtime Error):
import sys

input=sys.stdin.readline

N=int(input())
A=[-1]*N;B=[-1]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

ans=min(sum(A),sum(B))

temp=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)]
temp.sort()
data=[0]*N
for i in range(N):
    val,id=temp[i]
    data[id]+=1
S=sum(temp[i][0] for i in range(N))

for i in range(N):
    if data[i]==2:
        test=S
    elif data[i]==1:
        if temp[N-1][1]!=i:
            test=S+max(A[i],B[i])-temp[N-1][0]
        else:
            test=S+max(A[i],B[i])-temp[N-2][0]
    ans=min(test,ans)

print(ans)


Fixed submission:
import sys,random

input=sys.stdin.readline

N=int(input())
A=[-1]*N;B=[-1]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

ans=min(sum(A),sum(B))

temp=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)]
temp.sort()
#print(temp)
data=[0]*N
for i in range(N):
    val,id=temp[i]
    data[id]+=1
S=sum(temp[i][0] for i in range(N))

for i in range(N):
    if data[i]==2:
        test=S
        ans=min(ans,test)
    elif data[i]==1:
        if temp[N-1][1]!=i:
            test=S+max(A[i],B[i])-temp[N-1][0]
        else:
            test=S+max(A[i],B[i])-temp[N-2][0]
        ans=min(ans,test)

print(ans)