Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
class UF():
  def __init__(self, N):
    self.parents = [-1] * (N+1)

  def union(self, f, t):
    p1 = self.find(f)
    p2 = self.find(t)
    if p1 == p2:
      return

    if self.parents[p1] > self.parents[p2]:
      p1,p2 = p2,p1
    self.parents[p1] += self.parents[p2]
    self.parents[p2] = p1

  def find(self, node):
    if self.parents[node] < 0:
      return node
    else:
      self.parents[node] = self.find(self.parents[node])
      return self.parents[node]

  def members(self, n):
    root = self.find(n)
    if root == -1:
      return []
    return [ i for i, p in enumerate(self.parents) if self.find(i) == root]

N,K,L = map(int, input().split())
uf_road = UF(N)
uf_railway = UF(N)

for _ in range(K):
  f,t = map(int, input().split())
  uf_road.union(f,t)

for _ in range(L):
  f,t = map(int, input().split())
  uf_railway.union(f,t)

res = []
for i in range(1, N+1):
  road_members = uf_road.members(i)
  railway_members = uf_railway.members(i)
  c = 0
  for road_member in road_members:
    if road_member in railway_members:
      c += 1
  res.append(c)

print(" ".join([str(i) for i in res]))

Fixed submission:
from collections import defaultdict, Counter
class UF():
  def __init__(self, N):
    self.parents = [-1] * (N+1)

  def union(self, f, t):
    p1 = self.find(f)
    p2 = self.find(t)
    if p1 == p2:
      return

    if self.parents[p1] > self.parents[p2]:
      p1,p2 = p2,p1
    self.parents[p1] += self.parents[p2]
    self.parents[p2] = p1

  def find(self, node):
    if self.parents[node] < 0:
      return node
    else:
      self.parents[node] = self.find(self.parents[node])
      return self.parents[node]

  # def members(self, n):
  #   root = self.find(n)
  #   if root == -1:
  #     return []
  #   import pdb; pdb.set_trace()
  #   return [ i for i, p in enumerate(self.parents) if self.find(i) == root]

N,K,L = map(int, input().split())
uf_road = UF(N)
uf_railway = UF(N)

for _ in range(K):
  f,t = map(int, input().split())
  uf_road.union(f,t)

for _ in range(L):
  f,t = map(int, input().split())
  uf_railway.union(f,t)

l = []
for i in range(1, N+1):
  l.append((uf_road.find(i), uf_railway.find(i)))

c = Counter(l)
for i in range(N):
  print(c[l[i]], end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = list(map(int, input().split()))

_sum = 0
for i in range(len(As) - 1):
    _sum += As[i+1] * sum(As[0:i+1])

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


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

_sum = 0
x = 0
for i in range(len(As) - 1):
    _sum += As[i+1] * (x + As[i])
    x += As[i]

print(_sum % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

key = set(S)

_dict = {}
for s in key:
    _dict[s] = S.count(s)

sort_dict = sorted(_dict.items(), key=lambda x: -x[1])
c = sort_dict[0][1]
lst = list()
for item in sort_dict:

    if c == item[1]:
        lst += [item[0]]
        c = item[1]
    else:
        break

lst.sort()

for i in lst:
    print(i)


Fixed submission:
from collections import Counter

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

c = Counter(S)
_max = max(c.values())

ans = []
for k, v in c.items():
    if v == _max:
       ans += [k]

for a in sorted(ans):
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    _sum = 0
    N = int(input())
    for i in range(1, N):
        _sum += i

    print(_sum)

if __name__ == '__main__':
    main()

Fixed submission:
N = int(input())
print((N-1)*(N) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
_sum = 0
N = int(input())
for i in range(1, N):
    _sum += i

print(_sum)

Fixed submission:
N = int(input())
print((N-1)*(N) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [float('inf') for _ in range(N + K)]
    h += [float('inf') for _ in range(K)]

    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k]))

    print(dp[N - 1])

main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

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

    for i in range(1, N):
        tmp = [dp[j]+abs(h[i]-h[j]) for j in range(max(0, i-K), i)]

        dp[i] = min(tmp)

    print(dp[-1])

main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a = int(input())
b = int(input())

if a * b % 2:
    print('Odd')
else:
    print('Even')


Fixed submission:
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a * b) % 2:
    print('Odd')
else:
    print('Even')
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a * b) % 2:
    print('Odd')
else:
    print('Even')


Fixed submission:
# -*- coding: utf-8 -*-

r, g, b = map(int, list(input().split()))

num = r * 100 + g * 10 + b

if num % 4:
    print('NO')
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
N = int(input())


def digits(n):
    return len(list(str(n)))


digit_list = []
for a in range(1, int(N**(1/2))):
    b = N // a if N % a == 0 else 0
    if b != 0:
        digit_list += [max(digits(a), digits(b))]

print(min(digit_list))


Fixed submission:
N = int(input())


def digits(n):
    return len(list(str(n)))


digit_list = []
for a in range(1, int(N**(1/2))+1):
    b = N // a if N % a == 0 else 0
    if b != 0:
        digit_list += [max(digits(a), digits(b))]

print(min(digit_list))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            # print(x,y,z)
            count += 1

print(count)


Fixed submission:
# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        for z in range(0, K+1):
            if x + y + z == S:
                count += 1

print(count)


Fixed submission:
# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

S = input()
s = S[::]
T = ['dream', 'dreamer', 'erase', 'eraser']


def saiki(_s):
    if len(_s) == 0:
        return True

    for strng in T:
        if _s.endswith(strng):
            _s = _s[:len(_s)-len(strng):]
            return saiki(_s)

    return False


ret = False
if len(s) > 0:
    ret = saiki(s)

if ret:
    print('YES')
else:
    print('NO')

Fixed submission:
# -*- coding: utf-8 -*-
import re

S = input()

pattern = '^(dream|dreamer|erase|eraser)+$'
result = re.match(pattern, S)
if result:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

S = input()

s = S[::]  # DeepCopyと同じ
T = ['dream', 'dreamer', 'erase', 'eraser']


def saiki(_s):
    if len(_s) == 0:
        return True

    for strng in T:
        if _s.endswith(strng):
            _s = _s[:len(_s)-len(strng):]
            return saiki(_s)

    return False


ret = saiki(s)

if ret:
    print('YES')
else:
    print('NO')

Fixed submission:
# -*- coding: utf-8 -*-
import re

S = input()

pattern = '^(dream|dreamer|erase|eraser)+$'
result = re.match(pattern, S)
if result:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int,input().split()))
ans = 0
for i in range(len(arr)):
    for j in range(i+1,len(arr)):
        ans += (arr[i]*arr[j])%(1000000007)
        ans %= 1000000007
print(ans)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
ans = 0
tmp = 0

for i in range(n-1):
    tmp += arr[i]%1000000007
    ans += tmp*arr[i+1] % 1000000007

print(ans%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
arr = list(map(int,input().split()))

brr = []
prod = 1
for i in range(k):
    prod*=arr[i]

for i in range(k,n):
    prev = prod
    prod = prod//arr[i-k]*arr[i]
    if prod>prev:
        print('Yes')
    else:
        print('No')


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

for i in range(k,n):
    if arr[i-k]<arr[i]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

n = int(input())
arr = list(map(int,input().split()))

dd = defaultdict(int)

for a in arr:
    dd[a]+=1

q = int(input())
for _ in range(q):
    b,c = map(int,input().split())
    if dd[b]>0:
        dd[c]+=dd[b]
        dd[b]=0
    sum = 0
    for key in dd.keys():
        sum+=dd[key]*key
    print(sum)

Fixed submission:
from collections import defaultdict

n = int(input())
arr = list(map(int,input().split()))

dd = defaultdict(int)

for a in arr:
    dd[a]+=1

sum = sum(arr)

q = int(input())
for _ in range(q):
    b,c = map(int,input().split())


    if dd[b]>0:
        sum += dd[b]*(c-b)
        dd[c]+=dd[b]
        dd[b]=0

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

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)

print((m+k)/2.0)

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

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)
else:
    m = prr[0]

print((m+k)/2.0)
Buggy python submission (verdict: Runtime Error):
import re
print(max(list(map(len,re.findall('[ATGC]+',input(),re.S)))))

Fixed submission:
import re
result = re.findall('[ATCG]+',input(),re.S)
if len(result)>0:
  print(max(list(map(len,result))))
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for _ in range(q):
    ans=0
    l,r=map(int,input().split())
    for i in range(l,r):
        if s[i]=='C':
            if s[i-1]=='A':
                ans+=1
    print(ans)

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]
total=0
for i in range(1,len(s)):
    if s[i]=='C':
        if s[i-1]=='A':
            total+=1
    a.append(total)
a.append(total)

for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q=map(int,input().split())
s=input()
for _ in range(q):
    l,r=map(int,input().split())
    print(len(re.findall('AC',s[l-1:r],re.S)))


Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]
total=0
for i in range(1,len(s)):
    if s[i]=='C':
        if s[i-1]=='A':
            total+=1
    a.append(total)
a.append(total)

for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Runtime Error):
import re
n,q=map(int,input().split())
s=input()
for _ in range(q):
	l,r=map(int,input().split())
    print(len(re.findall('AC',s[l-1:r],re.S)))

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]
total=0
for i in range(1,len(s)):
    if s[i]=='C':
        if s[i-1]=='A':
            total+=1
    a.append(total)
a.append(total)

for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif n==m:
    prod=1
    for i in range(1,n+1):
        prod*=i
    print(prod*prod*2%1000000007)
else:
    prod=1
    for i in range(1,min(m,n)+1):
        prod*=i
    print(prod*prod*max(m,n)%1000000007)


Fixed submission:
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif n==m:
    prod=1
    for i in range(1,n+1):
        prod*=i
        prod%=1000000007
    print(prod*prod*2%1000000007)
else:
    prod=1
    for i in range(1,min(m,n)+1):
        prod*=i
        prod%=1000000007
    print(prod*prod*max(m,n)%1000000007)
Buggy python submission (verdict: Runtime Error):
if (a*100+b*10+c)%4==0:
    print('YES')
else:
    print('NO')


Fixed submission:
a,b,c=map(int,input().split())
if (a*100+b*10+c)%4==0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
stack=[]
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    l=0
    r=0
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
print('('*l+s+')'*r)


Fixed submission:
n=int(input())
s=input()
stack=[]
l=0
r=0
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
    print('('*l+s+')'*r)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
nn = int(math.sqrt(n))
for i in range(nn,0,-1):
    if n%i==0:
        print(len(str(n//i)))
        break


Fixed submission:
a,b=map(int,input().split())
print((a+b)%24)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
nn = int(math.sqrt(n))
for i in range(nn,n+1):
    if n%i==0:
        print(len(str(i)))
        break


Fixed submission:
import math
n = int(input())
nn = int(math.sqrt(n))
for i in range(nn,0,-1):
    if n%i==0:
        print(len(str(n//i)))
        break
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
brr=list(map(lambda x: max(x,0),arr))
total=0
for i in range(n-k+1):
    total=max(total,sum(brr[:i])+max(0,sum(arr[i:i+k]))+sum(brr[i+k:]))
print(total)


Fixed submission:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
brr=list(map(lambda x: max(x,0),arr))
crr=[0]
cum=0
for b in brr[:(n-k)]:
    cum+=b
    crr.append(cum)
drr=[0]
cum=0
for b in list(reversed(brr))[:(n-k)]:
    cum+=b
    drr.append(cum)
drr.reverse()
K=sum(arr[:k])
krr=[]
for i in range(n-k):
    krr.append(max(0,K))
    K-=arr[i]
    K+=arr[i+k]
krr.append(max(0,K))

ans=0
for i in range(n-k+1):
    ans=max(ans,crr[i]+drr[i]+krr[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        exit(1)
else:
    print(n*2)


Fixed submission:
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        break
else:
    print(n*2)
Buggy python submission (verdict: Runtime Error):
from pandas import Series
ser1 = Series(list(input()))
for w in range(2,len(ser1)+1):
    for st in range(0,len(ser1)+1-w):
        if ser1[st:st+w].value_counts()[0] > w/2:
            print(st+1,st+w)
            exit()
print(-1,-1)


Fixed submission:
s=input()
for w in range(2,min([3,len(s)])+1):
    for st in range(0,len(s)-w+1):
        if s[st]==s[st+w-1]:
            print(st+1,st+w)
            exit()
print(-1,-1)
Buggy python submission (verdict: Runtime Error):
if sorted(arr) == [5,5,7]:
  print('YES')
else:
  print('NO')

Fixed submission:
arr = map(int, input().split())
if sorted(arr) == [5,5,7]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import math
import functools
import sys

N = int(input())
A = list(map(int, input().split()))
Amax = max(A) + 1
if Amax == 2:
    print('pairwise coprime')
    sys.exit(0)

hurui = [1] * 1001
primes = []

for n in range(2, 1001):
    if hurui[n] != 1:
        continue

    primes.append(n)

    k = 2
    while n * k <= 1000:
        hurui[n * k] = n
        k += 1


#print(len(list(filter(lambda i: i == 0, hurui))))
#print(primes)

#print(primes)

wise = functools.reduce(math.gcd, A)
if wise != 1:
    print('not coprime')
    sys.exit(0)

count = [0] * (Amax+1)

pairwise = True
for i in range(N):
    a = A[i]
    if a == 1:
        continue

    for p in primes:
        if a % p == 0:
            count[p] += 1
            while a % p == 0:
                a = a // p
    if a != 1:
        count[a] += 1

if max(count)==1:
    print('pairwise coprime')
else:
    print('setwise coprime')



Fixed submission:
import math
import functools
import sys

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

wise = functools.reduce(math.gcd, A)
if wise != 1:
    print('not coprime')
    sys.exit(0)

A = list(filter(lambda a: a != 1, A))

if len(A) == 0:
    print('pairwise coprime')
    sys.exit(0)

pcount = 78498
if len(A) > pcount:
    print('setwise coprime')
    sys.exit(0)

Amax = max(A) + 1

hurui = [1] * 1001
primes = []

for n in range(2, 1001):
    if hurui[n] != 1:
        continue

    primes.append(n)

    k = 2
    while n * k <= 1000:
        hurui[n * k] = n
        k += 1




count = [0] * (Amax+1)

pairwise = True
for i in range(len(A)):
    a = A[i]
    if a == 1:
        continue

    for p in primes:
        if a % p == 0:
            count[p] += 1
            while a % p == 0:
                a = a // p
    if a != 1:
        count[a] += 1

if max(count)==1:
    print('pairwise coprime')
else:
    print('setwise coprime')
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math

def solve():
    N, K = map(int, input().split())
    A = list(map(lambda a: (-float(a), -int(a), 1), input().split()))
    heapq.heapify(A)
    for _ in range(K):
        a = heapq.heappop(A)
        heapq.heappush(A, (a[1] / (a[2] + 1.0), a[1], a[2]+1))

    ans = -heapq.heappop(A)[0]
    print(math.ceil(ans))

solve()

Fixed submission:
import heapq
import math

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()), reverse=True)
    l = 0
    r = A[0]
    # (l, r]
    #print(A)
    #print("K=",K)
    while r - l> 1:
        m = (r + l) // 2
        cuts = 0
        for a in A:
            cuts += (a-1) // m
        #print(l, m,r, cuts)
        if cuts <= K:
            r = m
        else:
            l = m
    print(r)

solve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N,M = list(map(int, input().split(' ')))
    K = [-1] * N
    for i in range(M):
        s, c = list(map(int, input().split(' ')))
        if K[s-1] != -1 and K[s-1] != c:
            print('-1')
            return
        K[s-1] = c
    if K[0] == 0:
        print('-1')
        return
    ans = ""
    if N==1:
        X = max(0, K[0])
        print(max(0, K[0]))
        return

    for i in range(N):
        if i==0 and K[i]==-1:
            ans += '1'
        elif K[i] == -1:
            ans += '0'
        else:
            ans += str(K[i])
    print(ans)

resolve()

Fixed submission:
def resolve():
    N = int(input())
    print((N+1)//2)
    
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def root(parents, i):
    depth = 0
    while parents[i] != i:
        i = parents[i]
        depth += 1

    return i, depth

def isSame(parents, a, b):
    return root(parents,a)[0] == root(parents, b)[0]

def union(parents, size, a, b):
    pa, deptha = root(parents, a)
    pb, depthb = root(parents, b)
    if pa == pb: # already same group
        return
    if deptha < depthb:
        parents[pb] = pa
        size[pa] += size[pb]
    else:
        parents[pa] = pb
        size[pb] += size[pa]

def resolve():
    N, M, K = list(map(int, input().split()))
    parents = [i for i in range(N)]
    size = [1] * N
    ans = [0] * N

    for i in range(M):
        A, B = list(map(int, input().split()))
        ans[A-1] += 1
        ans[B-1] += 1
        union(parents, size, A-1, B-1)

    for i in range(N):
        pi = root(parents, i)[0]
        ans[i] = size[pi] - ans[i] -1 # eliminate friend count from candidate

    for i in range(K):
        A, B = list(map(int, input().split()))
        if isSame(parents, A-1, B-1):
            ans[A-1] -= 1
            ans[B-1] -= 1

    print(" ".join(map(str, ans)))

resolve()

Fixed submission:
def root(parents, i):
    depth = 0
    while parents[i] != i:
        i = parents[i]
        depth += 1

    return i, depth

def isSame(parents, a, b):
    return root(parents,a)[0] == root(parents, b)[0]

def union(parents, size, a, b):
    pa, deptha = root(parents, a)
    pb, depthb = root(parents, b)
    if pa == pb: # already same group
        return
    if deptha < depthb:
        parents[pa] = pb
        size[pb] += size[pa]
    else:
        parents[pb] = pa
        size[pa] += size[pb]

def resolve():
    N, M, K = list(map(int, input().split()))
    parents = [i for i in range(N)]
    size = [1] * N
    ans = [0] * N

    for i in range(M):
        A, B = list(map(int, input().split()))
        ans[A-1] += 1
        ans[B-1] += 1
        union(parents, size, A-1, B-1)

    for i in range(N):
        pi = root(parents, i)[0]
        ans[i] = size[pi] - ans[i] -1 # eliminate friend count from candidate

    for i in range(K):
        A, B = list(map(int, input().split()))
        if isSame(parents, A-1, B-1):
            ans[A-1] -= 1
            ans[B-1] -= 1

    print(" ".join(map(str, ans)))

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

N, K = map(int, input().strip().split(' '))

ans = 0
count = int(math.log2(K)-math.log2(N))
if count < 0:
    count = 0
val = 2**count

for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val

print(ans/N)


Fixed submission:
import math
 
N, K = map(int, input().strip().split(' '))
 
ans = 0
count = int(math.log(K,2)-math.log(N,2))
if count < 0:
    count = 0
val = 2**count
 
for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val
 
print(ans/N)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())


class Tree:
    def __init__(self, n):
        self.par = [i for i in range(N+1)]


tree = [list() for _ in range(N)]
color = [-1 for _ in range(N)]
color[0] = 0

for _ in range(N-1):
    u, v, w = map(int, input().strip().split(' '))
    tree[u-1] += [(v-1, w % 2)]
    tree[v-1] += [(u-1, w % 2)]


def dfs(pos):
    for (p, w) in tree[pos]:
        if color[p] != -1:
            continue
        color[p] = color[pos] ^ w
        dfs(p)


dfs(0)
for c in color:
    print(c)


Fixed submission:
N = int(input())

tree = [list() for _ in range(N)]
color = [-1 for _ in range(N)]
color[0] = 0

for _ in range(N-1):
    u, v, w = map(int, input().strip().split(' '))
    tree[u-1] += [(v-1, w % 2)]
    tree[v-1] += [(u-1, w % 2)]


stack = [0]
while len(stack) > 0:
    pos = stack.pop()
    for (p, w) in tree[pos]:
        if color[p] == -1:
            color[p] = color[pos] ^ w
            stack.append(p)

for c in color:
    print(c)