Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())

p = []
s = []
ans_a = np.zeros(n+1)
ans_p = np.zeros(n+1)

for i in range(m):
    pi ,si = map(str,input().split())
    p.append(int(pi))
    s.append(si)

for i in range(m):
    if s[i] == "AC":
        ans_a[p[i]] = 1
    if s[i] == "WA" and ans_a[p[i]] == 0:
        ans_p[p[i]] += 1

print(int(np.sum(ans_a)), int(np.sum(ans_p))s)


Fixed submission:
import numpy as np
n,m = map(int,input().split())

p = []
s = []
ans_a = np.zeros(n)
ans_p = np.zeros(n)

for i in range(m):
    pi ,si = map(str,input().split())
    p.append(int(pi))
    s.append(si)

for i in range(m):
    if s[i] == "AC":
        ans_a[p[i]-1] = 1
    elif ans_a[p[i]-1] == 0:
        ans_p[p[i]-1] += 1

for i in range(n):
    if ans_a[i] == 0:
        ans_p[i] = 0

print(int(np.sum(ans_a)),int(np.sum(ans_p)))
Buggy python submission (verdict: Runtime Error):
k, x = map(int,input().split())

if k*500 < X:
    print("No")
else:
    print("Yes")


Fixed submission:
k, x = map(int,input().split())

if k*500 < x:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
from fractions import gcd
n,m = map(int,input().split())
a = np.array(input().split(),dtype=int)
a /= 2
a.sort()

def t_per2(k):
    num = 0
    while k%2 == 0:
        k = k//2
        num += 1
    return num

f = False
dcm = a[0]
t_2 = t_per2(a[0])
for i in a:
    dcm = (dcm*i)//gcd(dcm,i)
    if dcm > m or not t_per2(i) == t_2:
        f = True
        break

count = 0
if not f:
    count = math.ceil(int(m/dcm)/2)

print(count)


Fixed submission:
import numpy as np
import math
from fractions import gcd
n,m = map(int,input().split())
a = np.array(input().split(),dtype=int)
a /= 2

def t_per2(k):
    return format(k,'b')[::-1].find('1')

f = False
dcm = a[0]
t_2 = t_per2(a[0])
for i in a:
    dcm = (dcm*i)//gcd(dcm,i)
    if dcm > m or not t_per2(i) == t_2:
        f = True
        break

count = 0
if not f:
    count = math.ceil(int(m/dcm)/2)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
from fractions import gcd
n,m = map(int,input().split())
a = np.array(input().split(),dtype=int)
a /= 2

def t_per2(k):
    num = 0
    while k%2 == 0:
        k = k//2
        num += 1
    return num

f = False
dcm = a[0]
t_2 = t_per2(a[0])
for i in a:
    dcm = (dcm*i)//gcd(dcm,i)
    if dcm > m or not t_per2(i) == t_2:
        f = True
        break

count = 0
if not f:
    count = math.ceil(int(m/dcm)/2)

print(count)


Fixed submission:
import numpy as np
import math
from fractions import gcd
n,m = map(int,input().split())
a = np.array(input().split(),dtype=int)
a /= 2

def t_per2(k):
    return format(k,'b')[::-1].find('1')

f = False
dcm = a[0]
t_2 = t_per2(a[0])
for i in a:
    dcm = (dcm*i)//gcd(dcm,i)
    if dcm > m or not t_per2(i) == t_2:
        f = True
        break

count = 0
if not f:
    count = math.ceil(int(m/dcm)/2)

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())

for i in range(k):
    if a >= 1:
        a -= 1
    elif b >= 1:
        b -= 1

print(a,b)


Fixed submission:
a,b,k = map(int,input().split())

if k < a:
    print(a-k,b)
else:
    if a+b > k:
        print(0,a+b-k)
    else:
        print(0,0)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = t.count('r')*p+t.count('s')*r+t.count('p')*s
lose = []

for i in range(n-k):
    if t[i] == t[i+k] and not i in lose:
        ten -= point(t[i])
        lose.append(i+k)

print(ten)


Fixed submission:
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = 0
kako = ["o"]*k
for i in range(n):
    if kako[i%k] == t[i]:
        kako[i%k] = "o"
    else:
        kako[i%k] = t[i]
        ten += point(t[i])

print(ten)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = 0
lose = []
for i in range(n):
    if i < k:
        ten += point(t[i])
    else:
        if t[i-k] == t[i] and not i-k in lose:
            lose.append(i)
        else:
            ten += point(t[i])

print(ten)


Fixed submission:
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = 0
kako = ["o"]*k
for i in range(n):
    if kako[i%k] == t[i]:
        kako[i%k] = "o"
    else:
        kako[i%k] = t[i]
        ten += point(t[i])

print(ten)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array([[int(j) for j in list(format(i,'b').zfill(60))] for i in a]).T
mod = 10**9+7

"""
#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))


Fixed submission:
import numpy as np
a = np.array(input().split(),dtype=int)
sum  = a[0] + a[1] + a[2]
if sum > 21:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):
import numpy as np
a = np.array(input().split(),dtype=int)
sum  = a[0] + a[1] + a[2]
if sum > 21:
    print(bust)
else:
    print(win)


Fixed submission:
import numpy as np
a = np.array(input().split(),dtype=int)
sum  = a[0] + a[1] + a[2]
if sum > 21:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) # 昇順
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) # 降順で用いる
for i in range(C):
    hq.heappush(pq2, -r[i])
while (pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) # 順序を変えてみた
print(sum(pq1))

Fixed submission:
import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) # 昇順
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) # 降順で用いる
for i in range(C):
    hq.heappush(pq2, -r[i])
while (len(pq2) and pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) # 順序を変えてみた
print(sum(pq1))

Buggy python submission (verdict: Runtime Error):
import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) # 昇順
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) # 降順で用いる
for i in range(C):
    hq.heappush(pq2, -r[i])
while (pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) # 順序を変えてみた
print(sum(pq1))

Fixed submission:
import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) # 昇順
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) # 降順で用いる
for i in range(C):
    hq.heappush(pq2, -r[i])
while (len(pq2) and pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) # 順序を変えてみた
print(sum(pq1))
Buggy python submission (verdict: Time Limit Exceeded):
# 方針
# 頂点uからvに至る際に通る辺のリストをe[u][v]とする。
# M個の制約からl個(l>=1)選んだ際に，いずれの制約も満たさないために白く塗るべき辺の個数を考える。
# これは,uiからviに至る際に通る辺のリストの和集合の要素の数。

from collections import deque

N = int(input())
adj = [[] for i in range(N + 1)] # 1-ind
ve = {} # 両端の頂点の番号⇒辺の番号
for i in range(1, N) : # 1-ind
    a, b = map(int,input().split())
    adj[a].append(b); adj[b].append(a)
    ve[(a, b)] = ve[(b, a)] = i
# print(adj) #DB
# print(ve) #DB

# 頂点iからスタートし，葉に行き着くまでの通過頂点とそれまでに通過した辺を記録
l = [[set() for j in range(N + 1)] for i in range(N + 1)]
q = deque()
for i in range(1, N + 1):
    r = [False] * (N + 1)
    q.append(i); r[i] = True
    while q:
        u = q.popleft()
        for v in adj[u]:
            if r[v]:
                continue
            l[i][v].update(l[i][u])            
            l[i][v].add(ve[(u, v)])
            q.append(v)
            r[v] = True
# print(l) #DB
'''
for i in range(1, N + 1):
    for j in range(i, N + 1):
        print(i, j, l[i][j])
'''
M = int(input())
c = [set()]
for i in range(1, M + 1): # 1-ind
    u, v = map(int,input().split())
    c.append((u, v))

ans = 2 ** (N - 1)
for k in range(1, 1 << M): # 制約0個の場合を除外 ※初期値で考慮することもできそう
    V = set()
    d = 0 # 考慮する制約の個数
    for i in range(1, M + 1):
        if k >> (i - 1) & 1:
            d += 1
            u, v = c[i]
            V |= l[u][v]
    # print(k, V)
    temp = 2 ** (N - 1 - len(V))
    # print(d, temp)
    if d % 2 == 1:
        ans -= temp
    elif d % 2 == 0:
        ans += temp

print(ans)

Fixed submission:
# 方針
# 頂点uからvに至る際に通る辺のリストをe[u][v]とする。
# M個の制約からl個(l>=1)選んだ際に，いずれの制約も満たさないために白く塗るべき辺の個数を考える。
# これは,uiからviに至る際に通る辺のリストの和集合の要素の数。

from collections import deque

N = int(input())
adj = [[] for i in range(N + 1)] # 1-ind
ve = {} # 両端の頂点の番号⇒辺の番号
for i in range(1, N) : # 1-ind
    a, b = map(int,input().split())
    adj[a].append(b); adj[b].append(a)
    ve[(a, b)] = ve[(b, a)] = i
# print(adj) #DB
# print(ve) #DB

# 頂点iからスタートし，葉に行き着くまでの通過頂点とそれまでに通過した辺を記録
l = [[set() for j in range(N + 1)] for i in range(N + 1)]
q = deque()
for i in range(1, N + 1):
    r = [False] * (N + 1)
    q.append(i); r[i] = True
    while q:
        u = q.popleft()
        for v in adj[u]:
            if r[v]:
                continue
            l[i][v].update(l[i][u])            
            l[i][v].add(ve[(u, v)])
            q.append(v)
            r[v] = True
# print(l) #DB
'''
for i in range(1, N + 1):
    for j in range(i, N + 1):
        print(i, j, l[i][j])
'''
M = int(input())
c = [set()]
for i in range(1, M + 1): # 1-ind
    u, v = map(int,input().split())
    c.append((u, v))

ans = 2 ** (N - 1)
for k in range(1, 1 << M): # 制約0個の場合を除外 ※初期値で考慮することもできそう
    V = set()
    d = 0 # 考慮する制約の個数
    for i in range(1, M + 1):
        if k >> (i - 1) & 1:
            d += 1
            u, v = c[i]
            V |= l[u][v]
    # print(k, V)
    temp = 2 ** (N - 1 - len(V))
    # print(d, temp)
    if d % 2 == 1:
        ans -= temp
    elif d % 2 == 0:
        ans += temp

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
A = []

if K == N:
    A.extend([S] * N)
else:
    if S == 1:
        A.extend([1] * K)
        A.extend([2] * (N - K))
    else:
        for i in range((K + 1) // 2):
            A.extend([1, S - 1])
        if N % 2 == 0:
            A.append(1)
        x = S + 1 if S != 10 ** 9 else S - 2
        A.extend([x] * (N - K - 1))

print(A[0], end = "")
for i in range(1,N):
    print(" ", end = "")
    print(A[i], end = "")

Fixed submission:
N, K, S = map(int,input().split())
A = [S] * K
if N > K:
    if S < 10 ** 9:
        A.extend([S + 1] * (N - K))
    else:
        A.extend([S - 1] * (N - K))

print(A[0], end = "")
for i in range(1,N):
    print(" ", end = "")
    print(A[i], end = "")

Buggy python submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
A = []

if K == N:
    A.extend([S] * N)
else:
    if S == 1:
        A.extend([1] * K)
        A.extend([2] * (N - K))
    else:
        for i in range((K + 1) // 2):
            A.extend([1, S - 1])
        if N % 2 == 0:
            A.append(1)
        x = S + 1 if S != 10 ** 9 else S - 2
        A.extend([x] * (N - K - 1))

print(A[0], end = "")
for i in range(1,N):
    print(" " + str(A[i]), end = "")

Fixed submission:
N, K, S = map(int,input().split())
A = [S] * K
if N > K:
    if S < 10 ** 9:
        A.extend([S + 1] * (N - K))
    else:
        A.extend([S - 1] * (N - K))

print(A[0], end = "")
for i in range(1,N):
    print(" ", end = "")
    print(A[i], end = "")
Buggy python submission (verdict: Time Limit Exceeded):
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N,K=map(int,input().split())
A=[-10**10] # 1-ind
A.extend(list(map(int,input().split())))
A.sort()

# print(A)

ans=0
# min
for i in range(1,N-K+2):
    temp=combi(N-i,K-1)%mod
    '''
    print(i,A[i])
    print(N-i,K-1)
    print('min',temp)
    '''
    ans=(ans-temp*A[i])%mod
# max
for j in range(K,N+1):
    temp=combi(j-1,K-1)
    '''
    print(j)
    print(j-1,K-1)
    print('max',temp*A[j])
    '''
    ans=(ans+temp*A[j])%mod

print(ans)



Fixed submission:
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N,K=map(int,input().split())
A=[-10**10] # 1-ind
A.extend(list(map(int,input().split())))
A.sort()

# print(A)

ans=0
# min
p=1
for i in range(N-K+1,0,-1):
    # print(i,A[i],p)
    temp=A[i]*p%mod    
    ans=(ans-temp)%mod
    # print((N-i+1)*inv(N-K-i+2))
    p=p*(N-i+1)*inv(N-K-i+2)%mod
# max
p=1
for j in range(K,N+1):
    # print(j,A[j],p)
    temp=A[j]*p%mod
    ans=(ans+temp)%mod
    p=p*j*inv(j-K+1)%mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N=int(input())
x=[0]
x.extend(list(map(int,input().split())))
invs=[inv(d) for d in range(N)]
# print(invs)
ans=0
for i in range(1,N):
    for j in range(i+1,N):
        temp=(x[j]-x[i])*invs[j-i]*invs[j-i+1]%mod
        ans=(ans+temp)%mod
    temp=(x[N]-x[i])*invs[N-i]%mod
    ans=(ans+temp)%mod
ans=ans*fact(N-1)%mod

print(ans)

Fixed submission:
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N=int(input())
x=[0]
x.extend(list(map(int,input().split())))
invs=[inv(d) for d in range(N)]
# print(invs)
ans=0;s=0
for d in range(1,(N-1)//2+1):
    s=(s+x[N-d]-x[d])%mod
    ans=(ans+s*invs[d]*invs[d+1])%mod
    if d!=N-d-1:
        ans=(ans+s*invs[N-d-1]*invs[N-d])%mod
for i in range(1,N):
    ans=(ans+(x[N]-x[i])*invs[N-i])%mod
ans=ans*fact(N-1)%mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N=int(input())
x=[0]
x.extend(list(map(int,input().split())))

ans=0
for i in range(1,N):
    for j in range(i+1,N):
        temp=(x[j]-x[i])*inv((j-i)*(j-i+1))%mod
        ans=(ans+temp)%mod
    temp=(x[N]-x[i])*inv(N-i)%mod
    ans=(ans+temp)%mod
ans=ans*fact(N-1)%mod

print(ans)

Fixed submission:
# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

mod=10**9+7

N=int(input())
x=[0]
x.extend(list(map(int,input().split())))
invs=[inv(d) for d in range(N)]
# print(invs)
ans=0;s=0
for d in range(1,(N-1)//2+1):
    s=(s+x[N-d]-x[d])%mod
    ans=(ans+s*invs[d]*invs[d+1])%mod
    if d!=N-d-1:
        ans=(ans+s*invs[N-d-1]*invs[N-d])%mod
for i in range(1,N):
    ans=(ans+(x[N]-x[i])*invs[N-i])%mod
ans=ans*fact(N-1)%mod

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools as it

N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

l=[n for n in range(1,N+1)]
for i,t in enumerate(it.permutations(l)):
    if t==P:
        a=i+1
    elif t==Q:
        b=i+1
ans=abs(b-a)

print(ans)

Fixed submission:
import itertools as it

N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

l=[n for n in range(1,N+1)]
for i,t in enumerate(it.permutations(l)):
    if t==P:
        a=i+1
    if t==Q:
        b=i+1
ans=abs(b-a)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# problem D
mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)

for i in range(N):
    for k in range(60):
        b[k][i]=A[i]>>k&1

ans=0
for k in range(60):
    ans+=2**k*b[k].count(0)*b[k].count(1)

print(ans%mod)

Fixed submission:
# problem D
mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)
d0=[0 for k in range(60)]
d1=[0 for k in range(60)]

for i in range(N):
    for k in range(60):
        if A[i]>>k&1:
            d1[k]+=1
        else:
            d0[k]+=1

ans2=0
for k in range(60):
    ans2+=2**k*d0[k]*d1[k]

print(ans2%mod)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D
mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)

for i in range(N):
    for k in range(60):
        b[k][i]=A[i]>>k&1

ans=0
for k in range(60):
    ans+=2**k*b[k].count(0)*b[k].count(1)

print(ans%mod)

Fixed submission:
# problem D
mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)
d0=[0 for k in range(60)]
d1=[0 for k in range(60)]

for i in range(N):
    for k in range(60):
        if A[i]>>k&1:
            d1[k]+=1
        else:
            d0[k]+=1

ans2=0
for k in range(60):
    ans2+=2**k*d0[k]*d1[k]

print(ans2%mod)
Buggy python submission (verdict: Runtime Error):
mod=10**9+7

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

if A.count(0)==1: # 1色のみ
    ans=3
elif A.count(0)==2: # 2色のみ
    ans=1
    c1=c2=0
    for Ai in A:
        if Ai==0:
            if c1==0:
                c1+=1
                ans=ans*3%mod
            elif c2==0:
                c2+=1
                ans=ans*2%mod
        else:
            if c1==c2==Ai:
                c1+=1
                ans=ans*2%mod
            else:
                if c1==Ai:
                    c1+=1
                elif c2==Ai:
                    c2+=1
elif A.count(0)==3: # 3色全部
    ans=1
    c1=c2=c3=0
    for Ai in A:
        if Ai==0:
            if c1==0:
                c1+=1
                ans=ans*3%mod
            elif c2==0:
                c2+=1
                ans=ans*2%mod
            elif c3==0:
                c3+=1
        else:
            if c1==c2==c3==Ai:
                c1+=1
                ans=ans*3%mod
            elif c1==c2==Ai or c1==c3==Ai:
                c1+=1
                ans=ans*2%mod
            elif c2==c3==Ai:
                c2+=1
                ans=ans*2%mod
            else:
                if c1==Ai:
                    c1+=1
                elif c2==Ai:
                    c2+=1
                elif c3==Ai:
                    c3+=1

print(ans)

Fixed submission:
mod=1000000007

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

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1
    else:
        ans=0
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def sub(x):
	global A;	global F;	global K
	s = 0
	for i in range(N):
		s += max(A[i] - x // F[i], 0)
	return s <= K

N, K = map(int,input().split())
A = list(map(int,input().split())); A.sort()
F = list(map(int,input().split())); F.sort(); F.reverse()
# print(A); print(F)

l = -1; r = max(A) * max(F)
while r - l > 1:
	m = (l + r) // 2
	if sub(m):
		r = m
	else:
		l = m

print(r)

Fixed submission:
def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

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

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

if r>1 or p(F,A,0)>K:
    ans=r
else:
    ans=0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))

if N==1:
    ans=max(A[0]-K,0)*F[0]
else:
    F.sort(reverse=True) # 降順で固定
    A.sort()

#    print(f'F={F}')
#    print(A)

    while K>0 and A[-1]>0:
#        print(f'A={A}')
        S=sorted([(A[i]*F[i],i) for i in range(N)],reverse=True)
#        print(f'S={S}') #DB
        xym=S[0][0];xys=S[1][0]
        m=S[0][1];s=S[1][1]
        if xym==xys>0:
            A[m]-=1
            K-=1
        else:
            d=xym-xys
            p=min((d+(F[m]-1))//F[m],K,A[m])
            A[m]-=p # 負にならない
            K-=p
        A.sort()
    S=sorted([(A[i]*F[i],i) for i in range(N)],reverse=True)
    ans=max(S)[0]

print(ans)

Fixed submission:
def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

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

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

if r>1 or p(F,A,0)>K:
    ans=r
else:
    ans=0

print(ans)