Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02993 (python)

Fixed submission:
def sec(N):
    tmp = N[0]
    for i in range(1, 4):
        if tmp == N[i]:
            print("Bad")
            return 0
        tmp = N[i]
    print("Good")


sec(input())

Buggy submission (verdict: Runtime Error):
N = input()
tmp = N[0]
for i in range(1,4):
    if tmp == N[i]:
        print("Bad")
        exit(1)
    tmp = N[i]
print("Good")
Problem p03555 (python)

Fixed submission:
N = list(map(str, [input() for i in range(2)]))
N = "".join(N)
print("YES") if N == N[::-1] else print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
# [exit(0) if i ** 2 > N else print(i ** 2) if (i+1) ** 2 > N else print("", end="") for i in range(1, N)]
for i in range(1, N):
    if i ** 2 > N:
        print((i - 1) ** 2)
        break
    if i ** 2 == N:
        print(i ** 2)
        break
Problem p03777 (python)

Fixed submission:
a, b = input().split()
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")
Problem p03796 (python)

Fixed submission:
A=1
for i in range(1,int(input())+1):
  A*=i
  A%=1000000007
print(A)

Buggy submission (verdict: Runtime Error):
A=1
for i in range(1,int(input)+1):
  A*=i
  A%=1000000007
print(A)
Problem p04044 (python)

Fixed submission:
print("".join(sorted([input() for i in range(int("{}".format(input().split().pop(0))))])))

Buggy submission (verdict: Runtime Error):
print("".join(sorted([input() for i in range(int("{}".format(input().split().pop(-1))))])))
Problem p02719 (python)

Fixed submission:
n, k = list(map(int, input().split()))
# print(n, k)


x = n % k
y = k - x

if x > y:
    print(y)
    
else:
    print(x)

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
# print(n, k)


min_result = n
flag = 0
dic = {}

z = n // k
zz = n //z
result = zz

while flag==0:
    result = abs(result - k) 
    print('result',result)
    print('min_result',min_result)
    if result <= min_result:
        min_result = result
        dic[result] = dic.get(result, 0) + 1

        if dic[result] > 1:
            flag=1
print(min_result)
Problem p02761 (python)

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

    
out = ['a']*n
err_flg = False
err_flg2 = False 

for i in range(m):
    s = list(map(int, input().split()))
    # print(s)

    if s[0]==1 and s[1]==0 and n==1:
        err_flg2 = True
    elif m==0 and n==1:
        err_flg2 = True
    elif s[0]==1 and s[1]==0 and n > 1:
        # print('kore')
        err_flg = True

    if out[s[0]-1]=='a':
        out[s[0]-1] = s[1]
    elif out[s[0]-1]==s[1]:
        out[s[0]-1] = s[1]
    # elif out[s[0]-1]!=s[1]:
    elif out[s[0]-1]!=s[1]:
        err_flg = True


if out[0]=='a' and n>1:
    out[0]=1
    

out_s = "".join(map(str,out))

if err_flg2:
    print('0')
    # print('err2')
elif err_flg:
    print('-1')
    # print('err')
else:
    print(out_s.replace('a','0'))

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))

    
out = ['a']*n
err_flg = False

for i in range(m):
    s = list(map(int, input().split()))

    if s[0]==1 and s[1]==0 and n > 1:
        err_flag = True
    elif s[0]==1 and s[1]==0 and n==1:
        print('0')
    elif m==0 and n==1:
        print('0')

    if out[s[0]-1]=='a':
        out[s[0]-1] = s[1]
    elif out[s[0]-1]==s[1]:
        out[s[0]-1] = s[1]
    # elif out[s[0]-1]!=s[1]:
    elif out[s[0]-1]!=s[1]:
        err_flg = True


if out[0]=='a' and n>1:
    out[0]=1
    
out.replace('a','0')
out_s = "".join(map(str,out))

if err_flg:
    print('-1')
# elif m==0 and n==1:
#     print(0)
else:
    print(out_s)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))

    
out = [a]*n
err_flg = False

for i in range(m):
    s = list(map(int, input().split()))

    if s[0]==1 and s[1]==0 and n > 1:
        err_flag = True
    elif s[0]==1 and s[1]==0 and n==1:
        print('0')
    elif m==0 and n==1:
        print('0')

    if out[s[0]-1]==0:
        out[s[0]-1] = s[1]
    elif out[s[0]-1]==s[1]:
        out[s[0]-1] = s[1]
    # elif out[s[0]-1]!=s[1]:
    elif out[s[0]-1]!=s[1]:
        err_flg = True


if out[0]=='a' and n>1:
    out[0]=1
out_s = "".join(map(str,out))

if err_flg:
    print('-1')
# elif m==0 and n==1:
#     print(0)
else:
    print(out_s)
Problem p02787 (python)

Fixed submission:
h, n = map(int, input().split())
magics = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a,b in magics)
dp = [0] * (h+max_a)

for i in range(1,h+max_a):
    dp[i] = min(dp[i-a]+b for a, b in magics)
print(dp[h])

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
magics = [list(map(int, input().split())) for _ in range(n)]

dp = [0] * (h+1)

for i in range(1,h+1):
    dp[i] = min(dp[i-a]+b for a, b in magics)
print(dp[h])
Problem p02780 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()
    ans = 0
    tmp = 0
    if n == k:
        k = list(accumulate(range(max(p)+1)))
        for x in p:
            ans += k[x]/x
        
        print(ans)
        sys.exit()

    p_ = list(accumulate(p))
    #print(p_)


    for i in range(n-k):
        #print(i,p_[i+k]-p_[i])
        if tmp <= p_[i+k]-p_[i]:
            l = p[i+1:i+k+1]
            tmp = p_[i+k]-p_[i]

    #print('l:',l)
    k = list(accumulate(range(max(l)+1)))

    for x in l:
        ans += k[x]/x
        
    print(ans)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()
    p_ = list(accumulate(p))
    #print(p_)
    ans = 0
    tmp = 0

    for i in range(n-k):
        #print(i,p_[i+k]-p_[i])
        if tmp <= p_[i+k]-p_[i]:
            l = p[i+1:i+k+1]
            tmp = p_[i+k]-p_[i]

    #print('l:',l)
    k = list(accumulate(range(max(l)+1)))

    for x in l:
        ans += k[x]/x
        
    print(ans)

if __name__=='__main__':
    main()
Problem p02971 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]
    a_ = a.copy()
    a_.sort()
    m1, m2=a_[-1], a_[-2]

    for x in a:
        if x == m1:
            print(m2)
        else:
            print(m1)

if  __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]

    for i in range(n):
        a_ = a.copy()
        a_.pop(i)
        print(max(a_))

if  __name__=='__main__':
    main()
Problem p02981 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,a,b=MAP()
    print(min(n*a,b))

if  __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,a,b=INT()
    print(min(n*a,b))

if  __name__=='__main__':
    main()
Problem p03029 (python)

Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a, p = MAP()

print(int((a*3+p)/2))

Buggy submission (verdict: Runtime Error):
a,p=int(input().split())

print(int((a*3+p)/2))

Buggy submission (verdict: Runtime Error):
a,p=input().split()

print(int((a*3+p)/2))
Problem p03059 (python)

Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a,b,t=MAP()

print(int((t+0.5)/a)*b)

Buggy submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a,b,t=MAP()

print(int((t+0.5)/a)*b)
                                                                                    
                                                                            32,0-1       全て
Problem p03062 (python)

Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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

def SUM(x):return sum([abs(x) for x in a ])



sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

p=[]

for i, x in enumerate(a):
    if x < 0:
        ct +=1
        p.append([i, x])
    elif x == 0:
        ct = 0
        p.clear()


saidai = SUM(a)
a_abs = [abs(x) for x in a]

if ct % 2 == 0:
    print(saidai)
else:
    a_min = min(a_abs)
    print(saidai-2*a_min)

Buggy submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

for i, x in enumerate(a):
    if x <= 0:
        ct += 1
        if x < 0:
            p = [i, x]
        else:
            zero = i
            ct = 0

"print(p)"

lis = [abs(x) for x in a]
"""print(ct, sum(lis))"""

if ct % 2 == 0:
    print(sum(lis))
else:
    if p[0] > zero:
        if p[0] == n-1:
            print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] - 1])))
        else:
            print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] + 1])))
    else:
        print(sum(lis))

Buggy submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

for i, x in enumerate(a):
    if x <= 0:
        p = [i, x]
        ct += 1

"print(p)"

lis = [abs(x) for x in a]
"""print(ct, sum(lis))"""

if ct % 2 == 0:
    print(sum(lis))
else:
    print(sum(lis)-2*max(p[1], a[p[0]+1]))
Problem p03086 (python)

Fixed submission:
import sys

input = sys.stdin.readline

s = list(input().rstrip())

lis = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    for j in range(4):
        if (s[i] == lis[j]):
            s[i] = 'AYATASO'
            break

ct = 0
ct_lis = []

for i, x in enumerate(s):
    if (x == 'AYATASO'):
        ct += 1
    else:
        ct_lis.append(ct)
        ct = 0

ct_lis.append(ct)

print(max(ct_lis))

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

s = list(input().rstrip())

lis = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    for j in range(4):
        if (s[i] == lis[j]):
            s[i] = 'う～えす～ぎさ～ん'
            break


ct = 0
ct_lis = []

for i, x in enumerate(s):
    if (x == 'う～えす～ぎさ～ん'):
        ct += 1
    else:
        ct_lis.append([ct])
        ct = 0

print(max(ct_lis)[0])

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

s = list(input().rstrip())

lis = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    for j in range(4):
        if (s[i] == lis[j]):
            s[i] = 'う～えす～ぎさ～ん'


ct = 0
ct_lis = []

for i, x in enumerate(s):
    if (x == 'う～えす～ぎさ～ん'):
        ct += 1
    else:
        ct_lis.append([ct])
        ct = 0

print(max(ct_lis)[0])

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

s = list(input().rstrip())

lis = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    for j in range(4):
        if (s[i] == lis[j]):
            s[i] = 'う～えす～ぎさ～ん'


ct = 0
ct_lis = []

for i, x in enumerate(s):
    if (x == 'う～えす～ぎさ～ん'):
        ct += 1
    else:
        ct_lis.append([ct])
        ct = 0

print(max(ct_lis))
Problem p03243 (python)

Fixed submission:
N = int(input())
if N % 111 == 0:
        x = ((N - (N % 111)) / 111) * 111
else:
        x = (((N - (N % 111)) / 111) + 1) * 111
print(int(x))

Buggy submission (verdict: Runtime Error):
x = ((N - (N % 111)) / 111) * 111
Problem p03486 (python)

Fixed submission:
s = sorted(input())
t = sorted(input(),reverse=True)
if(s < t): print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
s = input().sorted()
t = input().sorted(reverse=True)
if(new_s < new_t): print("Yes")
else: print("No")
Problem p02721 (python)

Fixed submission:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

n,k,c=sep()
s=input()
c1=[0]*(n+5)
c2=[0]*(n+5)
for i in range(n):
    if s[i]=="x":
        c1[i]=c1[i-1]
    else:
        c1[i]=max(c1[i-1],c1[i-c-1]+1)
for i in range(n-1,-1,-1):
    if s[i]=="x":
        c2[i]=c2[i+1]
    else:
        c2[i]=max(c2[i+1],c2[(i+c+1)%n]+1)
ans=[]
if c2[1]==k-1 and s[0]=="o":
    ans.append(1)

for i in range(1,n-1):
    if s[i]=="x":
        continue
    if c1[i-1] + c2[i+1]==k-1:
        ans.append(i+1)

if n!=1:
    if c1[n-2]==k-1 and s[0]=="o":
        ans.append(n)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

n,k,c=sep()
s=input()
c1=[0]*(n+5)
c2=[0]*(n+5)
for i in range(n):
    if s[i]=="x":
        c1[i]=c1[i-1]
    else:
        c1[i]=max(c1[i-1],c1[i-c-1]+1)
for i in range(n-1,-1,-1):
    if s[i]=="x":
        c2[i]=c2[i+1]
    else:
        c2[i]=max(c2[i+1],c2[i+c+1]+1)
ans=[]
if c2[1]==k-1 and s[0]=="o":
    ans.append(1)

for i in range(1,n-1):
    if s[i]=="x":
        continue
    if c1[i-1] + c2[i+1]==k-1:
        ans.append(i+1)

if n!=1:
    if c1[n-2]==k-1 and s[0]=="o":
        ans.append(n)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

n,k,c=sep()
s=input()
c1=[0]*(n+5)
c2=[0]*(n+5)
for i in range(n):
    if s[i]=="x":
        c1[i]=c1[i-1]
    else:
        c1[i]=c1[i-c-1]+1
for i in range(n-1,-1,-1):
    if s[i]=="x":
        c2[i]=c2[i+1]
    else:
        c2[i]=c2[i+c+1]+1
ans=[]
if c2[1]==k-1 and s[0]=="o":
    ans.append(1)

for i in range(1,n-1):
    if s[i]=="x":
        continue
    if c1[i-1] + c2[i+1]==k-1:
        ans.append(i+1)

if c1[n-2]==k-1 and s[0]=="o":
    ans.append(n)

for i in ans:
    print(i)
Problem p02727 (python)

Fixed submission:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

x,y,a,b,c=sep()
red=lis()
green=lis()
colorless=lis()
red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort()
red=red[:x][::-1]
green=green[:y][::-1]
i=0
j=0
while(colorless):
    if j>=y and i>=x:
        break
    elif j<y and i>=x:
        if colorless[-1]>green[j]:
            green[j]=colorless[-1]
            colorless.pop()
            j+=1
        else:
            break
    elif i<x and j>=y:
        if colorless[-1]>red[i]:
            red[i]=colorless[-1]
            colorless.pop()
            i+=1
        else:
            break

    elif red[i]<=green[j]:
        if colorless[-1]>red[i]:
            red[i]=colorless[-1]
            colorless.pop()
            i+=1
        else:
            break
    else:
        if colorless[-1]>green[j]:
            green[j]=colorless[-1]
            colorless.pop()
            j+=1
        else:
            break
#print(red,green)
print(sum(red) + sum(green))

Buggy submission (verdict: Runtime Error):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

x,y,a,b,c=sep()
red=lis()
green=lis()
colorless=lis()
red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort()
red=red[:x][::-1]
green=green[:y][::-1]
i=0
j=0
while(colorless):
    if red[i]<=green[j]:
        if colorless[-1]>red[i]:
            red[i]=colorless[-1]
            colorless.pop()
            i+=1
        else:
            break
    else:
        if colorless[-1]>green[j]:
            green[j]=colorless[-1]
            colorless.pop()
            j+=1
        else:
            break
#print(red,green)
print(sum(red) + sum(green))
Problem p03175 (python)

Fixed submission:

def countSetBits(n):
    count = 0
    while (n):
        n &= (n - 1)
        count += 1

    return count


import sys
sys.setrecursionlimit(10**6)


N=10**9 + 7
n=int(input())
g=[[] for _ in range(n+5)]
for _ in range(n-1):
    a,b=map(int,input().strip().split(" "))
    g[a-1].append(b-1)
    g[b-1].append(a-1)
dpr=[-1 for _ in range(n+5)]
dpb=[-1 for _ in range(n+5)]

def dfs(v,p):
    if dpr[v]!=-1:
        return
    if len(g[v])==1 and g[v][0]==p:
        dpr[v]=1
        dpb[v]=1
        return
    valr=1
    valb=1
    for c in g[v]:
        if c==p:
            continue
        dfs(c,v)
        valr=(valr*((dpr[c]+dpb[c])%N))%N
        valb=(valb*(dpr[c]))%N
    dpr[v]=valr
    dpb[v]=valb
    return
dfs(0,-1)
print((dpr[0]+dpb[0])%N)

Buggy submission (verdict: Runtime Error):

def countSetBits(n):
    count = 0
    while (n):
        n &= (n - 1)
        count += 1

    return count



N=10**9 + 7
n=int(input())
g=[[] for _ in range(n+5)]
for _ in range(n-1):
    a,b=map(int,input().strip().split(" "))
    g[a-1].append(b-1)
    g[b-1].append(a-1)
dpr=[-1 for _ in range(n+5)]
dpb=[-1 for _ in range(n+5)]

def dfs(v,p):
    if dpr[v]!=-1:
        return
    if len(g[v])==1 and g[v][0]==p:
        dpr[v]=1
        dpb[v]=1
        return
    valr=1
    valb=1
    for c in g[v]:
        if c==p:
            continue
        dfs(c,v)
        valr=(valr*((dpr[c]+dpb[c])%N))%N
        valb=(valb*(dpr[c]))%N
    dpr[v]=valr
    dpb[v]=valb
    return
dfs(0,-1)
print((dpr[0]+dpb[0])%N)