Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n, p = map(int, input().split( ))
s = input()
#n,p = 10000,7
#s = "1"*10000
#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()


accm = [0]
s = s[::-1]
sm = 0
beki_p = 1
for i in range(n):
    sm += int(s[i])*beki_p
    sm %=p
    accm.append(sm)
    beki_p *=10
    beki_p%=p

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)


Fixed submission:
from collections import Counter
n, p = map(int, input().split( ))
s = input()
#n,p = 10000,5
#s = "7"*10000
#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    ans=0###
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()


accm = [0]
s = s[::-1]
#print(s)
sm = 0
beki_p = 1
for i in range(n):
    sm += int(s[i])*beki_p
    sm %=p
    accm.append(sm)
    beki_p *=10
    beki_p%=p

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n, p = map(int, input().split( ))
s = input()

#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()
s = int(s)

accm = [0]

for i in range(n):
    si = s%(10**(i+1))
    sip = si%p
    accm.append(sip)

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)


Fixed submission:
from collections import Counter
n, p = map(int, input().split( ))
s = input()
#n,p = 10000,5
#s = "7"*10000
#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    ans=0###
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()


accm = [0]
s = s[::-1]
#print(s)
sm = 0
beki_p = 1
for i in range(n):
    sm += int(s[i])*beki_p
    sm %=p
    accm.append(sm)
    beki_p *=10
    beki_p%=p

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int, input().split( ))
F = [tuple(map(int, input().split( ))) for _ in range(m)]
B = [tuple(map(int, input().split( ))) for _ in range(k)]
Fx = [0 for i in range(n+1)]
Bx = [0 for i in range(n+1)]
for a,b in F:
    Fx[a]|=(1<<(b-1))
    Fx[b]|=(1<<(a-1))
for a,b in B:
    Bx[a]|=(1<<(b-1))
    Bx[b]|=(1<<(a-1))
#友達関係での連結成分で分解
#連結成分中から2つ選ぶ場合の数から友達関係とブロック関係を引く
#各人ごと
#https://tjkendev.github.io/procon-library/python/union_find/union_find.html
*p, = range(n+1)
rank = [1]*(n+1)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1
for a,b in F:
    unite(a,b)
dic = {}
for i in range(1,n+1):
    if root(i) in dic:
        dic[root(i)] |= 1<<(i-1)
    else:
        dic[root(i)] = 1<<(i-1)
for i in range(1,n+1):
    ans = dic[root(i)]&(-1^ (Fx[i]|Bx[i]))
    print(bin(ans).count("1")-1,end = " ")


Fixed submission:
n,m,k=map(int, input().split( ))
F = [tuple(map(int, input().split( ))) for _ in range(m)]
B = [tuple(map(int, input().split( ))) for _ in range(k)]
Fx = [[] for i in range(n+1)]
Bx = [[] for i in range(n+1)]
for a,b in F:
    Fx[a].append(b)
    Fx[b].append(a)
for a,b in B:
    Bx[a].append(b)
    Bx[b].append(a)
#友達関係での連結成分で分解
#連結成分中から2つ選ぶ場合の数から友達関係とブロック関係を引く
#各人ごと
#https://tjkendev.github.io/procon-library/python/union_find/union_find.html
*p, = range(n+1)
rank = [1]*(n+1)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1
for a,b in F:
    unite(a,b)
dic = {}
for i in range(1,n+1):
    if root(i) in dic:
        dic[root(i)] +=1
    else:
        dic[root(i)] = 1
for i in range(1,n+1):
    ans = dic[root(i)]-1
    for b in Fx[i]:
        if root(b)==root(i):
            ans-=1
    for b in Bx[i]:
        if root(b)==root(i):
            ans-=1
    print(ans,end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
#https://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
# N: 処理する区間の長さ

# 中身は追えてない
#bit管理,26個作るより速いだろう
#演算はor

N = int(input())
s = input()


N0 = 2**(N-1).bit_length()
INF = 0
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = 1<<x
    while k >= 0:
        k = (k - 1) // 2
        data[k] =data[2*k+1]|data[2*k+2]
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = s|data[R-1]

        if L & 1:
            s = s|data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s

for i in range(N):
    update(i,ord(s[i])-ord("a"))
q = int(input())
for j in range(q):
    t,l,r = input().split( )
    if t=="1":
        update(int(l)-1,ord(r)-ord("a"))
        
    else:
        bit = bin(query(int(l)-1,int(r)))[2:]
        ans = 0
        for i in bit:
            ans += int(i)
        print(ans)
        

Fixed submission:
#https://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
# N: 処理する区間の長さ

#bit管理
#演算はor
N = int(input())
s = input()


N0 = 1
while N0<=N:
    N0*=2
INF = 0
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = 1<<x
    while k >= 0:
        k = (k - 1) // 2
        data[k] =data[2*k+1]|data[2*k+2]
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = s|data[R-1]

        if L & 1:
            s = s|data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s

for i in range(N):
    update(i,ord(s[i])-ord("a"))
q = int(input())

for j in range(q):
    t,l,r = input().split( )
    if t=="1":
        update(int(l)-1,ord(r)-ord("a"))
        
    else:
        bit = bin(query(int(l)-1,int(r)))[2:]
        ans = 0
        for i in bit:
            ans += int(i)
        print(ans)
Buggy python submission (verdict: Runtime Error):
n,d,a= map(int, input().split( ))
ms = []
for i in range(n):
    xi,hi = map(int, input().split( ))
    tmp = 0
    if hi%a:
        tmp+=1
    ms.append([xi,hi//a+tmp])

ms.sort()
ans = ms[0][1]
tmp = ms[0][1]
from collections import deque

Q = deque()
Q.append(0)

for i in range(1,n):

    while Q:###ifから変更
        tmp2 = Q.popleft();
        if ms[tmp2][0]+2*d<ms[i][0]:###tmpじゃないわms[tmp2][0]だわ
            tmp -= ms[tmp2][1]
        else:
            Q.appendleft(tmp2)
            break###
    ms[i][1]-=tmp###
    ms[i][1] = max(ms[i][1],0)###

    if ms[i][1]>0:　
        ##ms[i][1]-=tmp　二回引いてるわ
        ans += ms[i][1]
        Q.append(i)
        tmp += ms[i][1]
print(ans)


Fixed submission:
n,d,a= map(int, input().split( ))
ms = []
for i in range(n):
    xi,hi = map(int, input().split( ))
    tmp = 0
    if hi%a:
        tmp+=1
    ms.append([xi,hi//a+tmp])

ms.sort()
ans = ms[0][1]
tmp = ms[0][1]
from collections import deque

Q = deque()
Q.append(0)

for i in range(1,n):

    while Q:###ifから変更
        tmp2 = Q.popleft();
        if ms[tmp2][0]+2*d<ms[i][0]:###tmpじゃないわms[tmp2][0]だわ
            tmp -= ms[tmp2][1]
        else:
            Q.appendleft(tmp2)
            break###
    ms[i][1]-=tmp###
    ms[i][1] = max(ms[i][1],0)###

    if ms[i][1]>0:
        #ms[i][1]-=tmp　二回引いてるわ
        ans += ms[i][1]
        Q.append(i)
        tmp += ms[i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split( )))
ans = 0
tmp = 0
for i in range(n):
    if tmp>=a[i]:
        tmp = a[i]
        ans += 1
    tmp = max(a[i],tmp)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split( )))
ans = 0
tmp = a[0]
for i in range(n):
    if tmp>=a[i]:
        tmp = a[i]
        ans += 1
    tmp = min(a[i],tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
#小さいCから変更
n = int(input())
c = list(map(int, input().split( )))

c.sort()

#i　bit目が違うようなs,tは 2**(2*n-2)*2通り
sm = 0
for i in range(n):
    sm += (n-i)*c[i]

sm *= pow(2,2*n-2,10**9+7)

print(sm)

k,x = map(int, input().split( ))

if 500*k>=x:
    print("Yes")
else:
    print("No")

Fixed submission:

k,x = map(int, input().split( ))

if 500*k>=x:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    #if a[i]%k==1:
    #    ans+=1
    a[i] -= 1
sm= 0
a_sm = [0]
for i in range(n):
    sm += a[i]
    sm%=k
    a_sm.append(sm)
#print(a_sm)
dic = {i:[] for i in range(n)}
for i in range(n+1):
    dic[a_sm[i]].append(i)
#print(dic)
for i in range(n):
    for j in range(len(dic[i])-1):
        dm = bisect_left(dic[i],dic[i][j]+k)
        #print(ans)
        #print(i,j,dm)
        ans += dm - j-1
        #print("test",ans)
       
print(ans)

Fixed submission:
from bisect import bisect_left
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    a[i] -= 1
sm= 0
a_sm = [0]
for i in range(n):
    sm += a[i]
    sm%=k
    a_sm.append(sm)

dic = {}
for i in range(n+1):
    if a_sm[i] in dic:
        dic[a_sm[i]].append(i)
    else:
        dic[a_sm[i]]=[i]

for t in dic:
    for j in range(len(dic[t])-1):
        dm = bisect_left(dic[t],dic[t][j]+k)
        ans += dm - j - 1

       
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

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

if d[0]!=0:
    print(0)
    sys.exit()

d.sort()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

for i in range(1,n):
    cnt[d[i]] += 1

mod = 998244353
 
ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod 

print(ans)

Fixed submission:
import sys

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

if d[0]!= 0:
    print(0)
    sys.exit()

d.sort()
if n >=2:
    if d[1] == 0:
        print(0)
        sys.exit()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

for i in range(1,n):
    cnt[d[i]] += 1
mod = 998244353

ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
mod=998244353

ans=pow(3,n,mod)
rmv=0
f = [1, 1]  
inv = [1, 1]  
finv=[1,1]
for i in range(2, n+1):
    f.append((f[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    finv.append(finv[-1]*inv[-1]%mod)

k=n//2
if k*2<=n:
    k+=1
tmp=pow(2,n-k+1,mod)
inv2=pow(2,mod-2,mod)
for i in range(k,n+1):
    ans -= f[n]*finv[n-i]*finv[i]*tmp
    tmp*=inv2
    tmp%=mod
print(ans%mod)
    



Fixed submission:
n=int(input())
mod=998244353

ans=pow(3,n,mod)
rmv=0
f = [1, 1]  
inv = [1, 1]  
finv=[1,1]
for i in range(2, n+1):
    f.append((f[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    finv.append(finv[-1]*inv[-1]%mod)

k=n//2
if k*2<=n:
    k+=1
tmp=pow(2,n-k+1,mod)
inv2=pow(2,mod-2,mod)
for i in range(k,n+1):
    ans -= f[n]*finv[n-i]*finv[i]*tmp
    tmp*=inv2
    tmp%=mod
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
#解説参照
#言い換えが困難

n=int(input())
mod=998244353

ans=pow(3,n,mod)
rmv=0
f = [1, 1]  
inv = [1, 1]  
finv=[1,1]
for i in range(2, n+1):
    f.append((f[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    finv.append(finv[-1]*inv[-1]%mod)

def ch(a,b):
    return f[a]*finv[a-b]*finv[b]
k=n//2
if k*2<=n:
    k+=1

for i in range(k,n+1):
    ans -= ch(n,i)*pow(2,n-i+1,mod)
print(ans%mod)
    



Fixed submission:
n=int(input())
mod=998244353

ans=pow(3,n,mod)
rmv=0
f = [1, 1]  
inv = [1, 1]  
finv=[1,1]
for i in range(2, n+1):
    f.append((f[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    finv.append(finv[-1]*inv[-1]%mod)

k=n//2
if k*2<=n:
    k+=1
tmp=pow(2,n-k+1,mod)
inv2=pow(2,mod-2,mod)
for i in range(k,n+1):
    ans -= f[n]*finv[n-i]*finv[i]*tmp
    tmp*=inv2
    tmp%=mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
#s<t!
#一番期待値が悪くなる辺だけ考える
n,m = map(int, input().split( ))

E= [[] for _ in range(n)]

for _ in range(m):
    s,t = map(int, input().split( ))
    E[s-1].append(t-1)

dp = [0]*n 

for s in range(n-2,-1,-1):
    for t in E[s]:
        dp[s] += dp[t]
    if E[s]:
        dp[s] /= len(E[s])
    dp[s] += 1

#print("dp",*dp)

ans = dp[0]
for s2 in range(n-1):
    if len(E[s2])-1:
        dp2 = [0]*n
        for s in range(n-2,-1,-1):
            mxi = 0
            for t in E[s]:
                dp2[s] += dp2[t]
                if s ==s2:
                    mxi = max(mxi,dp[t])
            dp2[s] -= mxi
            if s == s2:
                dp2[s] /= len(E[s])-1
            elif E[s]:##el if
                dp2[s] /= len(E[s])
            dp2[s] += 1
        ans = min(ans, dp2[0])
        #print("dp2",*dp2)

print(ans)

Fixed submission:
#s<t!
#一番期待値が悪くなる辺だけ考える
n,m = map(int, input().split( ))

E= [[] for _ in range(n)]

for _ in range(m):
    s,t = map(int, input().split( ))
    E[s-1].append(t-1)

dp = [0]*n 

for s in range(n-2,-1,-1):
    for t in E[s]:
        dp[s] += dp[t]
    if E[s]:
        dp[s] /= len(E[s])
    dp[s] += 1

#print("dp",*dp)

ans = dp[0]
for s2 in range(n-1):
    if len(E[s2])-1:
        dp2 = [0]*n
        mxi = 0
        mxt = -1
        for t in E[s2]:
            if mxt<dp[t]:
                mxi = t 
                mxt = dp[t]
        if mxt<0:
            continue            
        for s in range(n-2,-1,-1):
            for t in E[s]:
                dp2[s] += dp2[t]
            if s ==s2:###ループ深さ
                dp2[s] -= mxt
            if s == s2:
                dp2[s] /= (len(E[s])-1)
            elif E[s]:##el if
                dp2[s] /= len(E[s])
            dp2[s] += 1
        ans = min(ans, dp2[0])
        #print("dp2",*dp2)

print(ans)
Buggy python submission (verdict: Runtime Error):
#何とか法, AOJのgrl1c
#初め満杯
import sys
input = sys.stdin.readline
#print = sys.stdout.write

n,m,l =map(int, input().split( ))
Edge = [[] for _ in range(n)]

for i in range(m):
    a,b,c = map(int, input().split( ))
    Edge[a-1].append([b-1,c])
    Edge[b-1].append([a-1,c])

dp = [[10**10 for _ in range(n)] for __ in range(n)]

for i in range(n):
    for ed in Edge[i]:
        dp[i][ed[0]] = ed[1]

for i in range(n):
    dp[i][i] = 0

for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

"""
以下が要点
"""
dp2 = [[10**8 for _ in range(n)] for __ in range(n)]
for j in range(n):
    for i in range(j+1):###
        if dp[i][j] <=l:
            dp2[i][j] = 1
            dp2[j][i] = 1
for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])
"""
以上
"""
q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split( ))
    if dp[s-1][t-1] >10**10:###
        print(-1)
    else:
        print(dp[s-1][t-1][0])
#print(dp)
#print(*ans)


Fixed submission:
#何とか法, AOJのgrl1c
#初め満杯
import sys
input = sys.stdin.readline
#print = sys.stdout.write

n,m,l =map(int, input().split( ))
Edge = [[] for _ in range(n)]

for i in range(m):
    a,b,c = map(int, input().split( ))
    Edge[a-1].append([b-1,c])
    Edge[b-1].append([a-1,c])

dp = [[10**10 for _ in range(n)] for __ in range(n)]

for i in range(n):
    for ed in Edge[i]:
        dp[i][ed[0]] = ed[1]

for i in range(n):
    dp[i][i] = 0

for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

"""
以下が要点
"""
dp2 = [[10**8 for _ in range(n)] for __ in range(n)]
for j in range(n):
    for i in range(j):
        if dp[i][j] <=l:
            dp2[i][j] = 1
            dp2[j][i] = 1
for i in range(n):
    dp2[i][i] = 1
    
for k in range(n):
    for j in range(n):
        for i in range(n):
            dp2[i][j] = min(dp2[i][j],dp2[i][k] + dp2[k][j])
"""
以上
"""
q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split( ))
    if dp2[s-1][t-1] >10**6:###
        print(-1)
    else:
        print(dp2[s-1][t-1]-1)
#print(dp)
#print(*ans)
Buggy python submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split())

c =fractions.gcd(a,b)
c2 = c
F = []
while c2%2==0:
    c2 //= 2
if c2<c:
    F.append(2)
f = 3
while f*f<=c2:
    while c2 %f ==0:
        c2//=f 
        if F[-1]<f:
            F.append(f)
    f += 2
if c2 !=1:
  F.append(c2)
#print(F)
print(len(F)+1)    


Fixed submission:
import fractions
a, b = map(int, input().split())
 
c =fractions.gcd(a,b)
c2 = c
F = []
while c2%2==0:
    c2 //= 2
if c2<c:
    F.append(2)
f = 3
while f*f<c2:
    while c2 %f ==0:
        c2//=f 
        if F:
            if F[-1]<f:
                F.append(f)
        else:
            F.append(f)
    f += 2
if c2>1:
    F.append(f)
print(len(F)+1)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split( ))

s = input()

if n ==1:
    print(0)
    sys.exit()

ans = n-1
tmp = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        ans -= 1
        
ans += 2*k
print(min(ans,n-1))
        



Fixed submission:
#import sys
n,k = map(int, input().split( ))

s = input()

#if n ==1:
#    print(0)
#    sys.exit()

ans = n-1
tmp = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        ans -= 1
        
ans += 2*k
print(min(ans,n-1))
Buggy python submission (verdict: Runtime Error):
from math import log2
import sys
n = int(input())
s =list(map(int, input().split()))
s.sort()
s.reverse()
flag = 0
if s[0] ==s[1]:
    print("No")
    sys.exit()
for i in range(2,2**n):
    ind = int(log2(i))
    if s[i-2**ind]==s[i]:
        flag =1
        break
if flag == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
import sys
n = int(input())
s = list(map(int, sys.stdin.readline().split()))

s.sort()#popするのでreverseしない
#print(s)
P = [s[-1]]
P_next = []

Rem = s[:-1]
Rem_next = []
for _ in range(n):
    while P:
        p = P.pop()
        P_next.append(p)
        while Rem:
            r = Rem.pop()
            if p>r:
                P_next.append(r)
                break
            Rem_next.append(r)
        """
        while p == Rem[-1]:
            r = Rem.pop()
            Rem_next.append(r)
        if Rem:
            P_next.append(Rem.pop())
        """
    P = P_next
    P_next = []
    Rem += Rem_next
    Rem_next = []
    #不自然な置き換えに見えるがlistからremoveするよりはマシか
    P.sort()
    Rem.sort()
if len(P) == 2**n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
P = []
#very small でWAなので、rで割ってかけ直すのをやめてみる
#atanを使ってみる
#0またいだときがおかしいか
for i in range(n):
    x, y = map(int, input().split( ))
    rad = math.atan2(x, y)
    P.append([rad, x, y])

P.sort()
P = P + P 


x0 = 0
y0 = 0

mx = 0

for i in range(n):
    vx = 0
    vy = 0
    for j in range(n):
        vx += P[i+j][1]
        vy += P[i+j][2]
    	v = vx**2 + vy**2
    	mx = max(v,mx)
print(math.sqrt(mx))


Fixed submission:
import math

n = int(input())
P = []
#very small でWAなので、rで割ってかけ直すのをやめてみる
#atanを使ってみる
#0またいだときがおかしいか
for i in range(n):
    x, y = map(int, input().split( ))
    rad = math.atan2(x, y)
    P.append([rad, x, y])

P.sort()
P = P + P 


x0 = 0
y0 = 0

mx = 0

for i in range(n):
    vx = 0
    vy = 0
    for j in range(n):
        vx += P[i+j][1]
        vy += P[i+j][2]
        v = vx**2 + vy**2
        mx = max(v,mx)
print(math.sqrt(mx))
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]

for i in range(n-1):
    a, b = map(int, input().split( ))
    Edg[a].append(b)
Ans=[0 for i in range(n+1)]
P = [0 for i in range(n+1)]
for i in range(q):
    p, x = map(int, input().split( ))
    P[p]+=x
#print(*P)
Chld=[[] for i in range(n+1)]
for p in range(n+1):
    Task=deque()
    Task.append(p)
    while True:
        try:
            p_=Task.popleft()
            for child in Edg[p_]:
                Chld[p].append(child)
                Task.append(child)
        except:
            break
#print(Chld)
for p in range(n+1):
    tmp = P[p]
    Ans[p]+=tmp
    for c in Chld[p]:
            Ans[c]+=tmp

print(*Ans[1:])


Fixed submission:
a=int(input())
s=input()
if a>=3200:
    print(s)
else:
    print("red")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]

for i in range(n-1):
    a, b = map(int, input().split( ))
    Edg[a].append(b)
Ans=[0 for i in range(n+1)]
P = [0 for i in range(n+1)]
for i in range(q):
    p, x = map(int, input().split( ))
    P[p]+=x
#print(*P)
Chld=[[] for i in range(n+1)]
for p in range(n+1):
    Task=deque()
    Task.append(p)
    while True:
        try:
            p_=Task.popleft()
            for child in Edg[p_]:
                Chld[p].append(child)
                Task.append(child)
        except:
            break
#print(Chld)
for p in range(n+1):
    tmp = P[p]
    Ans[p]+=tmp
    for c in Chld[p]:
            Ans[c]+=tmp

print(*Ans[1:])


Fixed submission:
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]
Done = [0 for _ in range(n+1)]

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


Ans=[0 for i in range(n+1)]
Pls = [0 for i in range(n+1)]


for i in range(q):
    p, x = map(int, input().split( ))
    Pls[p]+=x

root=1

Task=deque()

Task.append(root)

while len(Task)>0:
    p_=Task.popleft()
    tmp = Pls[p_]
    Ans[p_]+=tmp
    Done[p_] = 1
    for child in Edg[p_]:
        if not Done[child]:
            Task.append(child)
            Pls[child]+=tmp


print(*Ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]
##
for i in range(n-1):
    a, b = map(int, input().split( ))
    Edg[a].append(b)
Ans=[0 for i in range(n+1)]
P = [0 for i in range(n+1)]
for i in range(q):
    p, x = map(int, input().split( ))
    P[p]+=x
#print(*P)
Chld=[[] for i in range(n+1)]
for p in range(n+1):
    Task=deque()
    Task.append(p)
    while True:
        try:
            p_=Task.popleft()
            for child in Edg[p_]:
                Chld[p].append(child)
                Task.append(child)
        except:
            break
#print(Chld)
for p in range(n+1):
    tmp = P[p]
    Ans[p]+=tmp
    for c in Chld[p]:
            Ans[c]+=tmp

print(*Ans[1:])


Fixed submission:
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]
Done = [0 for _ in range(n+1)]

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


Ans=[0 for i in range(n+1)]
Pls = [0 for i in range(n+1)]


for i in range(q):
    p, x = map(int, input().split( ))
    Pls[p]+=x

root=1

Task=deque()

Task.append(root)

while len(Task)>0:
    p_=Task.popleft()
    tmp = Pls[p_]
    Ans[p_]+=tmp
    Done[p_] = 1
    for child in Edg[p_]:
        if not Done[child]:
            Task.append(child)
            Pls[child]+=tmp


print(*Ans[1:])