Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

n0 = 2**int(np.ceil(np.log2(2*Amax - 1)))#Amax+1以上となる最小の2のべき乗数

Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1)
for i in range(N):
    Afre[A[i]]+=1

#astype(int)は切り捨てなので，rintで四捨五入してから．
S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int)
Scum =S.cumsum()#累積和
bd = N*N-M#上からM個を取り出したい
i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある
#価値iが生み出せる選び方の余分なものを引きたい
remove=((Scum[-1]-Scum[i])-M)*i

ans=0
for j in range(i+1,n0):
    ans+=S[j]*j
print(ans-remove)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)

#幸福度をX以上増やせる手が何通りあるか？を二分探索．
#左手で握る人は線形探索，右手が二分探索で探す
#最後は累積和で計算

inf = 2*10**5+1
X_top = inf
X_bot = 0 #M手以上の組み合わせが作れる最大値

#幸福度をX以上挙げられる手の通り数ががMになる境界を探す
while X_top - X_bot !=1:  
    X=(X_top+X_bot)//2
    num=0
    
    for i in range(N):
        ok=-1
        ng=N
        h1=A[i]
        
        #右手と左手の合計がXになる境界を探す
        while ng-ok!=1:
            med=(ok+ng)//2
            h2=A[med]
            if h1+h2>=X:
                ok=med
            else:
                ng=med
        num+=ok+1
    
    if num>=M:
        X_bot = X
    else:
        X_top = X
        
ok_list=[0]*N
#各左手に対して何個okなくみがあるか探す
for i in range(N):
        ok=-1
        ng=N
        h1=A[i]
        X = X_bot
        #右手と左手の合計がXになる境界を探す
        while ng-ok!=1:
            med=(ok+ng)//2
            h2=A[med]
            if h1+h2>=X:
                ok=med
            else:
                ng=med
        ok_list[i]=ok

S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+A[i]

ans=0
for i in range(N):
    ans += A[i]*(ok_list[i]+1)+S[ok_list[i]+1]

if sum(ok_list)+N>M:
    ans-=(sum(ok_list)+N-M)*X
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


"""
N^2なので素直に計算は無理，部分和を使いたいのでとりあえず累積和
[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同．
移行して，S[j]-jとS[i]-iが合同
基本は個数だけ見れば良い

これだけだと，個数がKより大きい時にダメ
直近Kこの情報だけ持つ，今見てる数字が直近K個のものと何個組にできるか
"""
def main():

    mod=10**9+7
    N,K=MI()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=(S[i]+A[i])%K
        
    ans=0
    for i in range(K):
        temp=(S[i]-i)%K
        ans+=dd[temp]
        dd[temp]+=1
        
    for i in range(K,N+1):
        temp=(S[i]-i)%K
        temp_m=(S[(i-K)]-(i-K))%K
        dd[temp_m]-=1
        ans+=dd[temp]
        dd[temp]+=1
        
    print(ans)
        
        
    

        

main()


Fixed submission:
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}#最新K件の度数分布の管理

for i in range(N):
    S[i+1]=S[i]+A[i]
    S2[i+1] =(S[i+1]-i-1)%K

ans =0
for i in range(N+1):
    if dict.get(S2[i],0):
        ans += dict[S2[i]]
    dict[S2[i]]=dict.get(S2[i],0)+1
    if i >=K-1:
        dict[S2[i-(K-1)]]-=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    d=[0]*M
    c=[0]*M
    for i in range(M):
        d[i]=I()
    for i in range(M):
        c[i]=I()
        
    ans=0
    
    def make(cc,dd):
        ans+=(cc-1)+(dd*cc)//10
        return (cc*dd)%10
    
    new_cnt=0
    new_d=M
    for i in range(M):
        new_cnt+=make(c[i],d[i])
    make(new_cnt,new_d)
    print(ans)

main()


Fixed submission:
M=int(input())
dig=0
sum=0

for i in range(M):
    d,c=map(int,input().split())
    dig+=c
    sum+=d*c
    
print(dig-1+(sum-1)//9)
Buggy python submission (verdict: Runtime Error):
r = int(iinput())
print(r*r)

Fixed submission:
r = int(input())
print(r*r)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,Y=MI()
    N3=X+Y
    
    if N3%3!=0:
        print(0)
        exit()
        
    N=N3//3
    a=0
    b=0
    for i in range(N3):
        if 2*i + (N-i) == X:
            a=i
            b=N-i
            break

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]

    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
        
    ans=fact[N]*factinv[a]*factinv[b]
    print(ans%mod)
    

main()


Fixed submission:
x,y = map(int,input().split())
mod =10**9+7

a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b

def fact(x,p):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=p
    return ret


if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n,mod) * pow(fact(b,mod),mod-2,mod)*pow(fact(a,mod),mod-2,mod)
    print(ans%mod)
else:
    print("0")

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial as fact

x,y = map(int,input().split())
mod =10**9+7

a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b

if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n)%mod * pow(fact(n-a),mod-2,mod)*pow(fact(a),mod-2,mod)
    print(ans%mod)
else:
    print("0")

Fixed submission:
x,y = map(int,input().split())
mod =10**9+7

a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b

def fact(x,p):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=p
    return ret


if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n,mod) * pow(fact(b,mod),mod-2,mod)*pow(fact(a,mod),mod-2,mod)
    print(ans%mod)
else:
    print("0")
Buggy python submission (verdict: Runtime Error):
#bfs

S=input()
N = len(S)+1

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))

Fixed submission:
#bfs

S=input()
N = len(S)+1

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>=0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))
Buggy python submission (verdict: Runtime Error):
CSS
CSR

Fixed submission:
s=input()
t=input()

ans=0
for i in range(3):
    if s[i]==t[i]:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue
import copy

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

for i in range(N):
    A[i]=list(map(int,input().split()))

NE=[0]*N#i番目の人が，次何番目の試合をするかのリスト
F=[0]*N#i番目の人が，該当する日に試合をしたか記憶しておく

#i+1日目の試合をする人はi日目に試合をした人なので，それを記憶．
q1=queue.Queue()
q2=queue.Queue()

#初日
for i in range(N):
    opp=A[i][0]-1
    if A[opp][0]-1==i:
        NE[i]+=1
        q1.put(i)

ans=1
#d日目
for d in range(N*(N-1)//2):
    F=[0]*N
    while not q2.empty():
        a=q2.get()
        q1.put(a)
    while not q1.empty():
        i=q1.get()
        if NE[i]==N-1:
            continue
        opp=A[i][NE[i]]-1
        if F[i]==1 or F[opp]==1:#その日に試合したことがある人はスルー,oppの重複防止
            continue
        if A[opp][NE[opp]]-1==i:
            NE[i]+=1
            NE[opp]+=1
            F[i]=1
            F[opp]=1
            if NE[i]!=N-1:
                q2.put(i)
            if NE[opp]!=N-1:
                q2.put(opp)
    ans+=1
    if q2.empty() and q2.empty():
        break

for i in range(N):
    if NE[i]!=N-1:
        ans=-1
print(ans)

Fixed submission:
N=int(input())
A=[[] for _ in range(N)]

for i in range(N):
    A[i]=list(map(int,input().split()))

NE=[0]*N#i番目の人が，次何番目の試合をするかのリスト
F=[0]*N#i番目の人が，該当する日に試合をしたか記憶しておく

#i+1日目の試合をする人はi日目に試合をした人なので，それを2つのqueueに記憶．
Q=[[],[]]

#初日
for i in range(N):
    opp=A[i][0]-1
    if A[opp][0]-1==i:
        NE[i]+=1
        Q[0].append(i)

ans=1
#d日目
for d in range(N*(N-1)//2):
    F=[0]*N
    a=d%2
    b=(d+1)%2
    while len(Q[a])!=0:
        i=Q[a].pop()
        if NE[i]==N-1:
            continue
        opp=A[i][NE[i]]-1
        if F[i]==1 or F[opp]==1:#その日に試合したことがある人はスルー,oppの重複防止
            continue
        if A[opp][NE[opp]]-1==i:
            NE[i]+=1
            NE[opp]+=1
            F[i]=1
            F[opp]=1
            if NE[i]!=N-1:
                Q[b].append(i)
            if NE[opp]!=N-1:
                Q[b].append(opp)
    ans+=1
    if len(Q[a])==0 and len(Q[b])==0:
        break

for i in range(N):
    if NE[i]!=N-1:
        ans=-1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue
import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
c=[0]*N#count

to=[[] for i in range(N)]

for i in range(N-1):
    a,b =map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
    
    
for i in range(Q):
    p,x =map(int,input().split())
    p-=1
    c[p]+=x
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))

Fixed submission:
import queue
import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
c=[0]*N#count

to=[[] for i in range(N)]

for i in range(N-1):
    a,b =map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
    
    
for i in range(Q):
    p,x =map(int,input().split())
    p-=1
    c[p]+=x
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))

Buggy python submission (verdict: Time Limit Exceeded):
import queue

N,Q=map(int,input().split())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*N#count
p=[0]*Q
x=[0]*Q

to=[[] for i in range(N)]

for i in range(N-1):
    a[i],b[i] =map(int,input().split())
    a[i]-=1
    b[i]-=1
    to[a[i]].append(b[i])
    to[b[i]].append(a[i])
    
    
for i in range(Q):
    p[i],x[i] =map(int,input().split())
    p[i]-=1
    c[p[i]]+=x[i]
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))

Fixed submission:
import queue
import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
c=[0]*N#count

to=[[] for i in range(N)]

for i in range(N-1):
    a,b =map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
    
    
for i in range(Q):
    p,x =map(int,input().split())
    p-=1
    c[p]+=x
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))
Buggy python submission (verdict: Time Limit Exceeded):
#最終日から見る，残り日数条件を満たす中で最大収入のものを選ぶ

import heapq

N,M=map(int,input().split())
AB=[[0,0] for _ in range(N)]

for i in range(N):
    AB[i][0],AB[i][1] = map(int,input().split())
AB.sort()

ans=0
q=[]
heapq.heapify(q)
ne=0
#dは残り日数
for d in range(1,M+1):
    for i in range(ne,N):
        if AB[i][0]<=d:
            heapq.heappush(q,AB[i][1]*-1)
            ne=i+1
    if len(q)!=0:
        a=heapq.heappop(q)
        ans-=a
    
print(ans)

Fixed submission:
#最終日から見る，残り日数条件を満たす中で最大収入のものを選ぶ

import heapq

N,M=map(int,input().split())
AB=[[0,0] for _ in range(N)]

for i in range(N):
    AB[i][0],AB[i][1] = map(int,input().split())

AB.sort()

ans=0
q=[]
heapq.heapify(q)
ne=0
#dは残り日数
for d in range(1,M+1):
    for i in range(ne,N):
        if AB[i][0]<=d:
            heapq.heappush(q,AB[i][1]*-1)
            ne=i+1
        else:
            break
    if len(q)!=0:
        a=heapq.heappop(q)
        ans-=a
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    S+=["Z"]*3
    N=len(S)
    
    ans=0
    i=0
    while i!=N:
        if S[i:i+3]==["A","B","C"]:
            ans+=1
            S[i]="B"
            S[i+1]="C"
            S[i+2]="A"
            i=max(0,i-1)
        else:
            i+=1

    print(ans)
            

main()


Fixed submission:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    S=S.replace("BC","D")
    S+="Z"
    N=len(S)
    ans=0
    cnta=0

    
    for i in range(N):
        if S[i]=="D":
            ans+=cnta
        elif S[i]=="A":
            cnta+=1
        else:
            cnta=0
                
    print(ans)
            

main()

Buggy python submission (verdict: Time Limit Exceeded):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    S+=["Z"]*3
    N=len(S)
    
    ans=0
    i=0
    while i!=N:
        if S[i:i+3]==["A","B","C"]:
            ans+=1
            S[i]="B"
            S[i+1]="C"
            S[i+2]="A"
            i=max(0,i-1)
        else:
            i+=1

    print(ans)
            

main()


Fixed submission:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    S=S.replace("BC","D")
    S+="Z"
    N=len(S)
    ans=0
    cnta=0

    
    for i in range(N):
        if S[i]=="D":
            ans+=cnta
        elif S[i]=="A":
            cnta+=1
        else:
            cnta=0
                
    print(ans)
            

main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    V=LI()
    
    ans=0
    import heapq
    
    #左からa個，右からb個とって，あまり分で負数を捨てる
    for a in range(K+1):
        for b in range(K+1):
            if a+b>K:
                break
            hq=[]
            heapq.heapify(hq)
            for i in range(a):
                heapq.heappush(hq,V[i])
            for j in range(b):
                heapq.heappush(hq,V[N-1-j])
                
            temp=0
            rem=K-(a+b)
            for i in range(a+b):
                v=heapq.heappop(hq)
                if v>=0:
                    temp+=v
                else:
                    if rem>0:
                        rem-=1
                    else:
                        temp+=v
                        
            ans=max(ans,temp)
            
    print(ans)
                
            

main()


Fixed submission:
#import heapq
import copy

N,K=map(int,input().split())
V=list(map(int,input().split()))
V.append(0)#右から取る時用

S=[0]*(N+1)#累積和
for i in range(N):
    S[i+1]=S[i]+V[i]

#左からi番目まで見たときに，持っている負の宝石
left=[[] for _ in range(N+1)]
for i in range(N):
    left[i+1]=copy.deepcopy(left[i])
    if V[i]<0:
        left[i+1].append(V[i])
        left[i+1].sort()
       
        
ans=0
#左からi個，右からj個とったときについて考える
for i in range(N+1):
    temp=S[i]
    rem=copy.deepcopy(left[i])
    #heapq.heapify(rem)
    for j in range(N+1-i):
        if i+j>K:
            break
        temp+=S[-1]-S[N-j]
        if V[N-j]<0:
            #heapq.heappush(rem,V[N-j])
            rem.append(V[N-j])
            rem.sort()
        ret=K-(i+j)#負の宝石を返却できる回数
        if ret>0:
            for k in range(min(ret,len(rem))):
                temp-=rem[k]
        ans=max(ans,temp)
        temp=S[i]
        
print(ans)
Buggy python submission (verdict: Runtime Error):
100000 1
1 100000

Fixed submission:
N,M=map(int,input().split())
Lmax=1
Rmin=N
for i in range(M):
    L,R=map(int,input().split())
    Lmax=max(Lmax,L)
    Rmin=min(Rmin,R)
    
print(max(Rmin-Lmax+1,0))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*N
    C=[0]*N
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans)

main()


Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
CB=[[0,0] for _ in range(M)]

for i in range(M):
    CB[i][1],CB[i][0]=map(int,input().split())
    
A.sort()
CB.sort(reverse=True)

#Aを小さい順に見る，Cが大きい順に変更操作をして確定していく
cc=0
ans=0
for i in range(N):
    if cc<M:
        if A[i]<CB[cc][0]:
            A[i]=CB[cc][0]
            CB[cc][1]-=1
            if CB[cc][1]==0:
                cc+=1
    ans+=A[i]
        
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    CB=[[0,0]for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1],CB[i][0]=MI()
        
    CB.sort(reverse=True)
    now=0
    
    for i in range(N):
        if CB[now][1]<=0:
            now+=1
        ch=CB[now][0]
        if A[i]<ch:
            A[i]=ch
            CB[now][1]-=1
        else:
            break
        
    print(sum(A))
    

main()


Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
CB=[[0,0] for _ in range(M)]

for i in range(M):
    CB[i][1],CB[i][0]=map(int,input().split())
    
A.sort()
CB.sort(reverse=True)

#Aを小さい順に見る，Cが大きい順に変更操作をして確定していく
cc=0
ans=0
for i in range(N):
    if cc<M:
        if A[i]<CB[cc][0]:
            A[i]=CB[cc][0]
            CB[cc][1]-=1
            if CB[cc][1]==0:
                cc+=1
    ans+=A[i]
        
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M,K=MI()
    N=pow(2,M)
    if K>=N:
        print(-1)
        exit()
    elif M==1 and K==0:
        print(0,0,1,1)
    else:
        ans=[]
        temp=0
        for i in range(N):
            if i!=K:
                ans.append(i)
                temp=temp^i
        ans.append(K)
        for i in range(N2-1,-1,-1):
            if i!=K:
                ans.append(i)
        ans.append(K)
        if temp!=K:
            print(-1)
        else:
            print(' '.join(map(str, ans)))        

                

main()


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M,K=MI()
    N=pow(2,M)
    
    if K>=N or (M==1 and K==1):
        print(-1)
    elif M==1 and K==0:
        print(0,0,1,1)
    else:
        from collections import deque
        dq=deque()
        dq.append(K)
        for i in range(N):
            if i!=K:
                dq.append(i)
                dq.appendleft(i)
        dq.append(K)
        
        ans=[]
        while len(dq)!=0:
            ans.append(dq.pop())
        print(' '.join(map(str, ans)))
    

                

main()
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)
a=""
b=""
c="01"
for i in range(N):
    a+=str(c[i%2])
    b+=str(c[(i+1)%2])

ans_a=0
ans_b=0


for i in range(N):
    if a[i]!=S[i]:
        ans_a+=1
    if b[i]!=S[i]:
        ans_b+=1
        
print(min(ans_a,ans_b))

Fixed submission:
S=input()
N=len(S)
a=[]
b=[]
c=[0,1]
for i in range(N):
    a.append(c[i%2])
    b.append(c[(i+1)%2])

ans_a=0
ans_b=0


for i in range(N):
    s=int(S[i])
    if a[i]!=s:
        ans_a+=1
    if b[i]!=s:
        ans_b+=1
        
print(min(ans_a,ans_b))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[2,5,5,4,5,6,3,7,6]


dp=[0]*(N+1)
for j in range(M):
    need=B[A[j]-1]
    dp[need]=max(dp[need],A[j])

for i in range(1,N+1):
    for j in range(M):
        need=B[A[j]-1]
        if i-need>=0:
            if dp[i-need]:
                dp[i]=max(dp[i], dp[i-need]*10+dp[need])
            
print(dp[-1])



Fixed submission:
import queue
from collections import defaultdict
import copy

N,M=map(int,input().split())
A=list(map(int,input().split()))
ma=[2,5,5,4,5,6,3,7,6]
BA=[[0,0] for _ in range(M)] #(必要本数，-1*数字)
for i in range(M):
    BA[i][1]=-1*A[i]
    BA[i][0]=ma[A[i]-1]
    
BA.sort()

#同じ本数使うものを消去
can=[]
ii=0
while ii <len(BA):
    if BA[ii][0] in can:
        BA.pop(ii)
    else:
        can.append(BA[ii][0])
        ii+=1
M=len(BA)#Mの書き換え

diff=[0]*M#数字変更の際に追加で必要な本数
for i in range(M):
    diff[i]=BA[i][0]-BA[0][0]
    BA[i][1]=BA[i][1]*-1#(必要本数，数字)に直しておく

fi=BA[0]###
#BA.sort(key=lambda x: x[1]*-1)#数字の大きいもの順


    
p=[1]*(N+1)
for i in range(N):
    p[i+1]=p[i]*10

#数字のセットL(sort済み)から作れる最大の数値を出力
def set_to_num(L):
    ans=0
    for i in range(len(L)):
        ans+=L[i]*p[i]
    return ans

#2つの配列を合わせる
def make_set(temp,L):
    ori=copy.deepcopy(temp)
    for i in range(len(L)):
        ori[i]=L[i]
    ori.sort()
    return ori
    

#dd用hash
def make_h(L):
    h=0
    for i in range(len(L)):
        h+=p[i]*L[i]
    return h
    
    
ans=-1
Max_dig=N//fi[0]

for d in range(Max_dig):#減らす桁数
    dig=Max_dig-d
    rem=N-fi[0]*dig
    temp=[fi[1]]*dig
    dd = defaultdict(int)
    q=queue.Queue()
    q.put((rem,[]))#残り本数，入れ替える数字
    
    while not q.empty():
        rem2,L=q.get()
        if rem2==0:
            #print(temp,L)
            LLL=make_set(temp,L)
            #print(LLL)
            ans=max(ans,set_to_num(LLL))
        else:
            for i in range(1,M):#変更候補の数字を見ていく.0番は自身のためのぞく
                if rem2>=diff[i]:
                    LL=copy.deepcopy(L)
                    LL.append(BA[i][1])
                    if len(LL)<=len(temp):
                        LL.sort()
                        h=make_h(LL)
                        if dd[h]==0:
                            q.put((rem2-diff[i],LL))
                            dd[h]=1
    if ans!=-1:
        break
        
print(ans)