Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

from itertools import combinations

n,x,y=map(int,readline().split())
dis=[0]*n
lst=list(range(1,n+1))
for a,b in combinations(lst,2):
  if b<=x or a>=y:
    dist=b-a
  else:
    dist=min(b-a, abs(x-a)+abs(y-b)+1,abs(y-a)+abs(x-b)+1)
  dis[dist]+=1
print(*dis[1:],sep='\n')


Fixed submission:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

from itertools import combinations

n,x,y=map(int,readline().split())
dis=[0]*n
lst=list(range(1,n+1))
for a,b in combinations(lst,2):
  if b<=x or a>=y:
    dist=b-a
  else:
    dist=min(b-a, abs(x-a)+abs(y-b)+1)
  dis[dist]+=1
print(*dis[1:],sep='\n')

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

from itertools import combinations

n,x,y=map(int,readline().split())
dis=[0]*n
lst=list(range(1,n+1))
for a,b in combinations(lst,2):
  dist=min(b-a, abs(x-a)+abs(y-b)+1,abs(y-a)+abs(x-b)+1)
  dis[dist]+=1
print(*dis[1:],sep='\n')


Fixed submission:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

from itertools import combinations

n,x,y=map(int,readline().split())
dis=[0]*n
lst=list(range(1,n+1))
for a,b in combinations(lst,2):
  if b<=x or a>=y:
    dist=b-a
  else:
    dist=min(b-a, abs(x-a)+abs(y-b)+1)
  dis[dist]+=1
print(*dis[1:],sep='\n')
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  for i in nc:
    tr=red[0]
    tg=green[0]
    if tr<tg:
      if i>tr:
        red.popleft()
        res+=i
    else:
      if i>tg:
        green.popleft()
        res+=i
  print(res+sum(red)+sum(green))

main()

Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  
  def ppl(lst,i,t):
    if i>t:
      lst.popleft()
      return i
    else:
      return 0
    
  for i in nc:
    if (not red) and (not green):
      break
    if not red:
      tg=green[0]
      res+=ppl(green,i,tg)
    elif not green:
      tr=red[0]
      res+=ppl(red,i,tr)
    else:
      tr=red[0]
      tg=green[0]
      if tr<tg:
        res+=ppl(red,i,tr)
      else:
        res+=ppl(green,i,tg)
    
  print(res+sum(red)+sum(green))

main()

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline

x,y,a,b,c=map(int,readline().split())
lst=[]
red=deque(sorted(int(i) for i in readline().split())[-x:])
green=deque(sorted(int(i) for i in readline().split())[-y:])
nc=sorted([int(i) for i in readline().split()], reverse=1)

res=0
for i in nc:
  if i>red[0]:
    red.popleft()
    res+=i
  elif i > green[0]:
    green.popleft()
    res+=i
res+=sum(red)+sum(green)
print(res)

Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  
  def ppl(lst,i,t):
    if i>t:
      lst.popleft()
      return i
    else:
      return 0
    
  for i in nc:
    if (not red) and (not green):
      break
    if not red:
      tg=green[0]
      res+=ppl(green,i,tg)
    elif not green:
      tr=red[0]
      res+=ppl(red,i,tr)
    else:
      tr=red[0]
      tg=green[0]
      if tr<tg:
        res+=ppl(red,i,tr)
      else:
        res+=ppl(green,i,tg)
    
  print(res+sum(red)+sum(green))

main()
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc157/submissions/10475457

import sys
readline = sys.stdin.readine

N, M, K = map(int, readline().split())

F = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, readline().split())
    F[a].append(b)
    F[b].append(a)

B = [[] for _ in range(N + 1)]
for _ in range(K):
    c, d = map(int, readline().split())
    B[c].append(d)
    B[d].append(c)

seen = [-1] * (N + 1)
group = 0


def dfs(graph, s):
    stack = [s]
    seen[s] = group
    n_connection = 1

    while stack:
        u = stack.pop()
        for v in graph[u]:
            if seen[v] == -1:
                n_connection += 1
                seen[v] = group
                stack.append(v)

    return n_connection


union = {}
for i in range(1, N + 1):
    if seen[i] == -1:
        n = dfs(F, i)
        union[group] = n
        group += 1

ans = []
for i in range(1, N + 1):
    tmp = 0
    tmp += union[seen[i]] - 1
    tmp -= len(F[i])
    for j in B[i]:
        if seen[j] == seen[i]:
            tmp -= 1
    ans.append(tmp)

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


Fixed submission:
# https://atcoder.jp/contests/abc157/submissions/10475457

import sys
readline = sys.stdin.readline

N, M, K = map(int, readline().split())

F = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, readline().split())
    F[a].append(b)
    F[b].append(a)

B = [[] for _ in range(N + 1)]
for _ in range(K):
    c, d = map(int, readline().split())
    B[c].append(d)
    B[d].append(c)

seen = [-1] * (N + 1)
group = 0


def dfs(graph, s):
    stack = [s]
    seen[s] = group
    n_connection = 1

    while stack:
        u = stack.pop()
        for v in graph[u]:
            if seen[v] == -1:
                n_connection += 1
                seen[v] = group
                stack.append(v)

    return n_connection


union = {}
for i in range(1, N + 1):
    if seen[i] == -1:
        n = dfs(F, i)
        union[group] = n
        group += 1

ans = []
for i in range(1, N + 1):
    tmp = 0
    tmp += union[seen[i]] - 1
    tmp -= len(F[i])
    for j in B[i]:
        if seen[j] == seen[i]:
            tmp -= 1
    ans.append(tmp)

print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.read
n, k = map(int, read().split())


def count(digit, k):
    elif k == 0:
        return 1
    elif k == 1:
        return digit
    elif k == 2:
        return digit * (digit - 1) // 2
    else:
        return digit * (digit - 1) * (digit - 2) // 6


def solve(n, k):
    if k == 0:
        return 1
    digit = len(str(n))
    res = 0
    if digit > k:
        res += count(digit - 1, k) * (9 ** k)
    pow10 = 10 ** (digit - 1)
    d, mod = n // pow10, n % pow10
    res += count(digit - 1, k - 1) * (9 ** (k - 1)) * (d - 1)
    res += solve(mod, k - 1)
    return res


print(solve(n, k))


Fixed submission:
import sys
read = sys.stdin.read

n, k = map(int, read().split())


def count(d, k):
  if k == 0:
    return 1
  elif k == 1:
    return d
  elif k == 2:
    return d * (d - 1) // 2
  else:
    return d * (d - 1) * (d - 2) // 6


def solve(n, k):
  digit = len(str(n))
  if digit == 0 and k > 0:
    return 0
  if k == 0:
    return 1
  res = 0
  if digit > k:
    res += count(digit - 1, k) * (9 ** k)
  a = 10 ** (digit - 1)
  d, mod = n // a, n % a
  res += count(digit - 1, k - 1) * (9 ** (k - 1)) * (d - 1)
  res += solve(mod, k - 1)
  return res


print(solve(n, k))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
read=sys.stdin.read

h,n,*ab=map(int,read().split())
a=np.array(ab[::2])
b=np.array(ab[1::2])

magic=np.zeros(h+1)
for i in range(1,1+h):
  magic[i]=np.min(dp[np.maximum(i-a, 0)]+b)
print(magic[h])

Fixed submission:
import numpy as np
import sys
read=sys.stdin.read

h,n,*ab=map(int,read().split())
a=np.array(ab[::2])
b=np.array(ab[1::2])

magic=np.zeros(h+1,dtype=np.int64)
for i in range(1,1+h):
  magic[i]=np.min(magic[np.maximum(i-a, 0)]+b)
print(magic[h])
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import deque
    read=sys.stdin.read
    readline=sys.stdin.readline
    
    n, d, a = map(int, readline().split())
    m = map(int, read().split())
    monsters = sorted(zip(m, m), key=itemgetter(0))
    
    bomb_area = deque([])
    bomb_power = deque([])
    total_damage = 0
    ans = 0
    for pos, hp in monsters:
        while bomb_area:
            area = bomb_area[0]
            if area < pos:
                bomb_area.popleft()
                power = bomb_power.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            rest = hp - total_damage
            count = rest // a + (rest % a != 0)
            ans += count
            power = a * count
            total_damage += power
            bomb_area.append(pos + 2 * d)
            bomb_power.append(power)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    from collections import deque
    read=sys.stdin.read
    readline=sys.stdin.readline
    
    n, d, a = map(int, readline().split())
    m = map(int, read().split())
    monsters = sorted(zip(m, m), key=lambda x:x[0])
    
    bomb_area = deque([])
    bomb_power = deque([])
    total_damage = 0
    ans = 0
    for pos, hp in monsters:
        while bomb_area:
            area = bomb_area[0]
            if area < pos:
                bomb_area.popleft()
                power = bomb_power.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            rest = hp - total_damage
            count = rest // a + (rest % a != 0)
            ans += count
            power = a * count
            total_damage += power
            bomb_area.append(pos + 2 * d)
            bomb_power.append(power)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=input()
intn=int(n)
ln=len(n)

if intn<10:
  print(n)
  quit()

def count(i,j):
  res=0
  if i==j:
    res+=1
  if ln==2:
    if 10*i+j<=n:
      res+=1
  else:
    res+=(10**(ln-2)-1)//9
    if i<int(n[0]):
      res+=10**(ln-2)
    elif i==int(n[0]):
      tn=int(n[1:-1])
      if j<=intn%10:
        res+=tn+1
      else:
        res+=tn
  return res

res=0
for i in range(1,10):
  for j in range(1,10):
    res+=count(i,j)*count(j,i)
print(res)
        

Fixed submission:
n=input()
intn=int(n)
ln=len(n)

if intn<10:
  print(n)
  quit()

def count(i,j):
  res=0
  if i==j:
    res+=1
  if ln==2:
    if 10*i+j<=intn:
      res+=1
  else:
    res+=(10**(ln-2)-1)//9
    if i<int(n[0]):
      res+=10**(ln-2)
    elif i==int(n[0]):
      tn=int(n[1:-1])
      if j<=intn%10:
        res+=tn+1
      else:
        res+=tn
  return res

res=0
for i in range(1,10):
  for j in range(1,10):
    res+=count(i,j)*count(j,i)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
from fractions import gcd
from functools import reduce
 
n,*alst = list(map(int, read().split()))

def lcm(x, y):
    g = gcd(x, y)
    g = x * y // g
    return g

g = reduce(lcm, alst)
mod=10**9+7
res=0
for a in alst:
  res+=pow(a,mod-2,mod)*g
  res%=mod
print(res)

Fixed submission:
# https://atcoder.jp/contests/abc152/submissions/9693323

import sys
read = sys.stdin.read

N, *A = map(int, read().split())
mod = 10 ** 9 + 7


def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)
    for i in range(3, int(n ** 0.5) + 2, 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
    return sieve


def prime_factorize(n):
    a = {}
    while n != 1:
        b = table[n]
        if b in a:
            a[b] += 1
        else:
            a[b] = 1
        n //= b
    return a


table = min_factor(10**6)

dic = {}
for i in A:
    for key, value in prime_factorize(i).items():
        if key in dic:
            dic[key] = max(dic[key], value)
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = sum(lcm * pow(i, mod - 2, mod) for i in A) % mod
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k,*alst = map(int,read().split())
alst.sort()
lst1=alst[k-1:]
lst2=alst[n-k::-1]
mod = 10 ** 9 + 7
res=0
prep=1
for i in range(n-k+1):
  res+=prep*(lst1[i]-lst2[i])
  res%=mod
  prep=prep*(i+k)//(i+1)

print(res)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k,*alst = map(int,read().split())
alst.sort()
lst1=alst[k-1:]
lst2=alst[n-k::-1]
mod = 10 ** 9 + 7
res=0
prep=1
for i in range(n-k+1):
  res+=prep*(lst1[i]-lst2[i])
  res%=mod
  prep=prep*(i+k)*pow(i+1,mod-2,mod)
  prep%=mod

print(res)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)


Fixed submission:
from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    if cen is None:
      continue
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.read


n, m, *alst = list(map(int, read().split()))
mm = 2 * m


def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)
    for i in range(3, int(n ** 0.5) + 2, 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
    return sieve


# 素因数分解
def prime_factorize(n):
    a = {}
    while n != 1:
        b = table[n]
        if b in a:
            a[b] += 1
        else:
            a[b] = 1
        n //= b
    return a

table = min_factor(max(alst))

dic = {}
prep = -1
for i in alst:
    for key, value in prime_factorize(i).items():
        if key == 2:
            if prep == -1:
                prep = value
            elif value != prep:
                print(0)
                quit()
        if key in dic:
            dic[key] = max(dic[key], value)
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j)
    if lcm > mm:
        print(0)
        quit()
res = mm // lcm
print(res // 2 + res % 2)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
from fractions import gcd
from functools import reduce

n,m = map(int,readline().split())
alst = list(map(int,readline().split()))

def lcm(x,y):
  g=gcd(x,y)
  if x//g %2==0 or y//g%2==0:
    return 0
  return x*y//g
g=reduce(lcm,alst)
if g==0:
  print(0)
  quit()
else:
  res=(2*m//g)
  print(res//2+res%2)
Buggy python submission (verdict: Runtime Error):
s,t=input(),input()
print(t+s)

Fixed submission:
s,t = input().split()
print(t+s)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x=int(readline())
def a(n):
  for i in range(2, int(n ** 0.5 + 1)):
    if n % i == 0:
      return False
  return True
  
  
n=x+1
while True:
  if a(n):
    pint(n)
    quit()
  n+=1

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x=int(readline())
def a(n):
  for i in range(2, int(n ** 0.5 + 1)):
    if n % i == 0:
      return False
  return True
  

while True:
  if a(x):
    print(x)
    quit()
  x+=1
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
readline = sys.stdin.buffer.readline
import itertools
n,m=map(int,readline().split())
alst=[int(i) for i in readline().split()]
alst.sort(reverse=True)
a=0
c=[0]*m
heapq.heapify(c)

for x,y in itertools.product(alst, repeat = 2):
  ta = x+y
  if ta > c[0]:
    heapq.heappushpop(c, ta)
print(sum(c))

Fixed submission:
# https://atcoder.jp/contests/abc149/submissions/9219994
  
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 価値 x 以上の握手を全て行うとする
# 握手回数が決まる。左手ごとに集計できる。

import numpy as np

N,M = map(int,readline().split())
A = np.array(read().split(),np.int64)

A.sort()

def shake_cnt(x):
    # x 以上の握手を全て行うとして、握手の回数を数える
    # 行わない握手を数える
    X = np.searchsorted(A,x-A)
    return N * N - X.sum()

left = 0 # 握手の回数がM以上
right = 10 ** 6 # 握手の回数がM未満
while left + 1 < right:
    x = (left + right) // 2
    if shake_cnt(x) >= M:
        left = x
    else:
        right = x

left,right

# right 以上の握手を全て行ったとして、回数と総和を計算

X = np.searchsorted(A,right-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)

shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()

happy += (M - shake) *left
print(happy)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
readline = sys.stdin.readline

N = int(readline())

adj = [[] for i in range(N)]
for i in range(N - 1):
    A, B = map(int, readline().split())
    A -= 1
    B -= 1
    adj[A].append(B)
    adj[B].append(A)

mod = 10 ** 9 + 7
pow2 = [1] * (N + 1)
for i, j in zip(range(N), range(1, N + 1)):
    pow2[j] = pow2[i] * 2 % mod

ans = 0


@lru_cache(maxsize=None)
def dfs(node, parent):
    global ans
    cnt = 1
    
    for child in adj[node]:
        if child != parent:
            cnt += dfs(child, node)
    
    ans += (pow2[cnt] - 1) * (pow2[N-cnt] - 1)
    ans %= mod
    
    return cnt

dfs(0, None)

ans = (ans - N * pow2[N-1] + pow2[N] - 1) % mod
ans = ans * pow(pow2[N], mod - 2, mod) % mod

print(ans)


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

N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, readline().split())
    lb = 1 << i
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

MOD = 10**9 + 7
x = (MOD + 1) // 2
power_inv = [1] * (N + 100)
for i in range(1, N + 100):
    power_inv[i] = power_inv[i - 1] * x % MOD

size = [1] * (N + 1)
p_size = [N - 1] * (N + 1)
prod = [1] * (N + 1)
coef = [1] * (N + 1)
for v in order[::-1]:
    p = parent[v]
    x = size[v]
    size[p] += x

ans = 0
for i in size[2:]:
    ans += 1 - power_inv[i] - power_inv[N - i] + power_inv[N]
    ans %= MOD
ans = ans - N * power_inv[1] + 1 - power_inv[N]
ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline
 
n = int(readline())
num = 1
res = 0
for i in readline().split():
  if num != int(i):
    res += 1
  else:
    i += 1

if res == n:
  print(-1)
else:
  print(res)

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

n = int(readline())
c = 1
r = 0
p = 0
a = True
for i, j in enumerate(readline().split()):
  if c != int(j):
    continue
  else:
    a = False
    c += 1
    r += i - p
    p = i + 1
if a:
  print(-1)
else:
  print(r + n - p)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
lst = []
for _ in range(n):
    a = int(sys.stdin.readline())
    lst.append([[i for i in sys.stdin.readline().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
    a = True
    d = 0
    for j in range(n):
        if i >> j & 1:
            d += 1
            for x, y in lst[j]:
                if bin(i)[- int(x)] != y:
                    a = False
                    break
    if a:
        m = max(m, d)
print(m)

Fixed submission:
n = int(input())
lst = []
for _ in range(n):
    a = int(input())
    lst.append([[int(i) for i in input().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
    a = True
    for j in range(n):
        if i >> j & 1:
            for x, y in lst[j]:
                if (i >> (x - 1) & 1) != y:
                    a = False
                    break
    if a:
        m = max(m, sum(map(int, bin(i)[2:])))
print(m)