Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import gcd
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Fixed submission:
from fractions import*
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Buggy python submission (verdict: Runtime Error):
from math import gcd
n=int(input())
a=[int(i) for i in input().split()]
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Fixed submission:
from fractions import*
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
As=[int(i) for i in input().split()]

def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
          return z

As.sort()
gcd1=[gcd(As[0], As[i]) for i in range(N)]
gcd2=[gcd(As[1], As[i]) for i in range(N)]
gcd1.sort()
gcd2.sort()
if gcd1.count(min(gcd1))>=2:
    print(gcd2[2])
else:
    print(gcd1[1])

Fixed submission:
from fractions import*
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
As=[int(i) for i in input().split()]

def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z

gcd1.sort()
gcd2.sort()
if gcd1.count(min(gcd1))>=2:
    print(gcd2[2])
else:
    print(gcd1[1])

Fixed submission:
from fractions import*
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
from itertools import combinations
import copy
b=[i for i in range(n-1)]
c=[v for i in range(1,n) for v in combinations(b, i)]
sum_temp=sum(a)
for v in c:
    a_temp=copy.copy(a)
    for i in v:
        a_temp[i]*=-1
        a_temp[i+1]*=-1
    if sum_temp<sum(a_temp):
        sum_temp=sum(a_temp)
print(sum_temp)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
a_neg=sum([1 if i<0 else 0 for i in a])
if a_neg%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()
allblack=n-sum(S)
allwhite=sum(S)
bw=10**6
from itertools import accumulate
accS=list(accumulate(S))
for i in range(n):
    bw=min(bw,accS[i]+(n-(i+1))-(sum(S)-accS[i]))
print(min(bw,allblack,allwhite))

Fixed submission:
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()
sS=sum(S)
allblack=n-sum(S)
allwhite=sum(S)
bw=10**6
from itertools import accumulate
accS=list(accumulate(S))
for i in range(n):
    bw=min(bw,accS[i]+(n-(i+1))-(sS-accS[i]))
print(min(bw,allblack,allwhite))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
p=list(map(float, input().split()))
dp=[[0]*(N+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(N):
        dp[i+1][j+1]+=dp[i][j]*p[i]
        dp[i+1][j]+=dp[i][j]*(1-p[i])
print(sum(dp[N][N//2+1:]))

Fixed submission:
N=int(input())
p=list(map(float, input().split()))
dp=[[0]*(N+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(N):
        dp[i+1][j+1]+=dp[i][j]*p[i]
        dp[i+1][j]+=dp[i][j]*(1-p[i])
print(sum(dp[N][N//2+1:]))
Buggy python submission (verdict: Runtime Error):
x=list(map(int,input().split))
x.sort()
print(x[-1]*10+x[-2]+x[-3])

Fixed submission:
x=list(map(int,input().split()))
x.sort()
print(x[-1]*10+x[-2]+x[-3])

Buggy python submission (verdict: Runtime Error):
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N,M=map(int,input().split())
if M==1:
  print(1)
else:
  primes0=prime_factorize(M)
  keys=list(set(primes0))
  primes={}
  for i in range(len(keys)):
    k=keys[i]
    primes[k]=0
    for j in range(len(primes0)):
      if primes0[j]==k:
        primes[k]+=1

  def cmb(n, k, mod, fac, ifac): #calc nCk under mod
      if n < k or n < 0 or k < 0:
          return 0
      else: 
          k = min(k, n-k)
          return fac[n] * ifac[k] * ifac[n-k] % mod

  def make_tables(mod, n): #Make factorial and inverse tables under mod 
      fac = [1, 1] # factorial table
      ifac = [1, 1] #factorial of inverse table
      inverse = [0, 1] #inverse

      for i in range(2, n+1):
          fac.append((fac[-1] * i) % mod)
          inverse.append((-inverse[mod % i] * (mod//i)) % mod)
          ifac.append((ifac[-1] * inverse[-1]) % mod)
      return fac, ifac

  mod=10**9+7
  fac,ifac = make_tables(mod,N*2)
  ans=1
  for i in range(len(keys)):
    ans*=cmb(N+primes[keys[i]]-1, primes[keys[i]], mod, fac, ifac)
    ans%=mod
  print(ans)

Fixed submission:
x=list(map(int,input().split()))
x.sort()
print(x[-1]*10+x[-2]+x[-3])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
x=list(map(int,input().split()))

ans=float('inf')
for i in range(n-k+1):
    nowx=x[i:i+k]
    if nowx[0]>=0 and nowx[-1]>=0:
        ans=min(ans, nowx[-1])
    elif nowx[0]<=0 and nowx[-1]<=0:
        ans=min(ans, abs(nowx[0]))
    elif nowx[0]<0 and nowx[-1]>=0:
        ans=min(ans, 2*abs(nowx[0])+nowx[-1], abs(nowx[0])+2*nowx[-1])
print(ans)

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

ans=float('inf')
for i in range(n-k+1):
    nowx=(x[i],x[i+k-1])
    if nowx[0]>=0 and nowx[-1]>=0:
        ans=min(ans, nowx[-1])
    elif nowx[0]<=0 and nowx[-1]<=0:
        ans=min(ans, abs(nowx[0]))
    elif nowx[0]<0 and nowx[-1]>=0:
        ans=min(ans, 2*abs(nowx[0])+nowx[-1], abs(nowx[0])+2*nowx[-1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
k=int(input())
n=len(s)
subset=set([])
for i in range(n):
    tmp=s[i]
    subset.add(tmp)
    for j in range(i+1, n):
        tmp+=s[j]
        subset.add(tmp)
subset=sorted(list(subset))
print(subset[k-1])

Fixed submission:
s=list(input())
k=int(input())
n=len(s)
subset=[]
from bisect import bisect_left

for i in range(n):
    tmp=s[i]
    for j in range(i,min(n,i+5)):
        if j==i: pass
        else: tmp+=s[j]
        if tmp not in subset:
            l=bisect_left(subset, tmp)
            if 0<=l<5:
                subset=subset[:l]+[tmp]+subset[l:5]
                subset=subset[:5]
            else:
                break
print(subset[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
k=int(input())
n=len(s)
subset=set([])
for i in range(n):
    tmp=[s[i]]
    subset.add(tmp[0])
    for j in range(i+1, n):
        tmp.append(s[j])
        subset.add(''.join(tmp))
subset=sorted(list(subset))
print(subset[k-1])

Fixed submission:
s=list(input())
k=int(input())
n=len(s)
subset=[]
from bisect import bisect_left

for i in range(n):
    tmp=s[i]
    for j in range(i,min(n,i+5)):
        if j==i: pass
        else: tmp+=s[j]
        if tmp not in subset:
            l=bisect_left(subset, tmp)
            if 0<=l<5:
                subset=subset[:l]+[tmp]+subset[l:5]
                subset=subset[:5]
            else:
                break
print(subset[k-1])
Buggy python submission (verdict: Runtime Error):
n,h=map(int, input().split())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int, input().split())
    a.append(ai)
    b.append(bi)
b=sorted(b,reverse=True)
amax=max(a)
newb=[b[i] for i in range(n) if b[i]>amax]
from itertools import accumulate
newb=list(accumulate(newb))
ans=0
for i in range(len(newb)):
    if newb[i]>=h:
        ans=i+1
        break
if ans==0:
    ans+=len(newb)
    ans+=(h-max(newb))//amax
    if (h-max(newb))%amax>0:
        ans+=1
print(ans)

Fixed submission:
n,h=map(int, input().split())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int, input().split())
    a.append(ai)
    b.append(bi)
b=sorted(b,reverse=True)
amax=max(a)
newb=[0]
for i in range(n):
    if b[i]>amax:
        newb.append(b[i])
from itertools import accumulate
newb=list(accumulate(newb))
ans=0
for i in range(len(newb)):
    if newb[i]>=h:
        ans=i
        break
if ans==0:
    ans+=len(newb)-1
    ans+=(h-max(newb))//amax
    if (h-max(newb))%amax>0:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
lr=[]
for i in range(Q):
    lr=list(map(int, input().split()))
    left=bisect_left(primes, lr[0])
    right=bisect_right(primes, lr[1])
    cnt=0
    for p in primes[left:right]:
        if p!=2:
            if primes[bisect_left(primes,(p+1)//2)]==(p+1)//2:
                cnt+=1
    print(cnt)

Fixed submission:
Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
import numpy as np

ls=[]
rs=[]
for i in range(Q):
    l,r=map(int, input().split())
    ls.append(l)
    rs.append(r)
lmin=min(ls)
rmax=max(rs)
bool_prime=np.zeros(rmax+1,dtype=np.int64)
bool_2007=np.zeros(rmax+1,dtype=np.int64)

for p in primes:
    if p>rmax:
        break
    bool_prime[p]=1
    if p!=2 and bool_prime[(p+1)//2]==1:
        bool_2007[p]=1

cum2007=np.cumsum(bool_2007)
for i in range(Q):
    print(cum2007[rs[i]]-cum2007[ls[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
lr=[]
for i in range(Q):
    lr=list(map(int, input().split()))
    left=bisect_left(primes, lr[0])
    right=bisect_right(primes, lr[1])
    cnt=0
    for p in primes[left:right]:
        if p!=2 and (p+1)//2 in primes:
            cnt+=1
    print(cnt)

Fixed submission:
Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
import numpy as np

ls=[]
rs=[]
for i in range(Q):
    l,r=map(int, input().split())
    ls.append(l)
    rs.append(r)
lmin=min(ls)
rmax=max(rs)
bool_prime=np.zeros(rmax+1,dtype=np.int64)
bool_2007=np.zeros(rmax+1,dtype=np.int64)

for p in primes:
    if p>rmax:
        break
    bool_prime[p]=1
    if p!=2 and bool_prime[(p+1)//2]==1:
        bool_2007[p]=1

cum2007=np.cumsum(bool_2007)
for i in range(Q):
    print(cum2007[rs[i]]-cum2007[ls[i]-1])
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
h,w=map(int,input().split())
d=[list(map(int,input().split())) for i in range(10)]

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=warshall_floyd(d)
cost=[d[i][1] for i in range(10)]

from collections import defaultdict
count=defaultdict(int)
for i in range(h):
    A=list(map(int,input().split()))
    for a in A:
        count[a]+=1

ans=0
t=[x for x in range(10) if x!=1]
for i in t:
    ans+=cost[i]*count[i]
print(ans)


Fixed submission:
from itertools import permutations
h,w=map(int,input().split())
C=[list(map(int,input().split())) for i in range(10)]

cost=[C[i][1] for i in range(10)]
for i in range(10):
    if i!=1:
        keiyu=[x for x in range(10) if x!=1 and x!=i]
        for j in range(9):
            perm=permutations(keiyu,r=j)
            for k in perm:
                k=[i]+list(k)+[1]
                tmp=0
                for l in range(len(k)-1):
                    tmp+=C[k[l]][k[l+1]]
                cost[i]=min(tmp, cost[i])

from collections import defaultdict
count=defaultdict(int)
for i in range(h):
    A=list(map(int,input().split()))
    for a in A:
        count[a]+=1

ans=0
t=[x for x in range(10) if x!=1]
for i in t:
    ans+=cost[i]*count[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
n=int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
ans=0
for i in range(n):
  for j in range(bisect_right(b,a[i]),n):
    ans+=n-bisect_right(c,b[j])
print(ans)

Fixed submission:
from bisect import *
n=int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
ans=0
for i in range(n):
    x=bisect_left(a,b[i])
    y=n-bisect_right(c,b[i])
    ans+=x*y
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
n=int(input())
*a, =map(int,input().split())
a=sorted(a)
for i in range(len(a)):
  if i==0: tmp=a[0]
  else:
    tmp=gcd(tmp,a[i])
if n%tmp==0:
  print("POSSIBLE")
else: print("IMPOSSIBLE")

Fixed submission:
from math import gcd
n,k=map(int,input().split())
*a, =map(int,input().split())
a=sorted(a)
for i in range(len(a)):
  if i==0: tmp=a[0]
  else:
    tmp=gcd(tmp,a[i])
if k%tmp!=0 or max(a)<k:
  print("IMPOSSIBLE")
else: print("POSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m=map(int, input().split())
ab=[set(map(int, input().split())) for _ in range(m)]
root=list(itertools.permutations(ab, n-1))
cnt=0
for r in root:
    trace=[i+1 for i in range(n)]
    other=1
    for i in range(0, n-1):
        if other in r[i]:
            try:
                trace.remove(other)
            except ValueError:
                break
            other=list(r[i]-{other})[0]
            continue
        else: break
    try:
        trace.remove(other)
    except ValueError:
        pass
    if trace==[]:
        cnt+=1
print(cnt)

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

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

def dfs(v, used):
    if not False in used:
        return 1
    
    ans = 0
    for i in range(N):
        if not adj_matrix[v][i]:
            continue
        if used[i]:
            continue
        
        used[i] = True
        ans += dfs(i, used)
        used[i] = False
    
    return ans

used = [False] * N
used[0] = True

print(dfs(0, used))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
k1,v1=c.most_common(2)[0]
while v1>1:
    if v1>2:
        c[k1]-=2
    else:
        k2,v2=c.most_common(2)[1]
        if v2>0:
            c[k1]-=1
            c[k2]-=1
    k1,v1=c.most_common(2)[0]
cnt=0
for k in c.keys():
    if c[k]==1:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
import heapq
cou=Counter(a)
c=[]
for k in cou.keys():
    c.append((-cou[k], k))
heapq.heapify(c)
v1,k1=heapq.heappop(c)
while v1<-1:
    if v1<-2:
        v1+=2
        heapq.heappush(c, (v1,k1))
    else:
        v2,k2=heapq.heappop(c)
        if v2<0:
            v1+=1
            v2+=1
            heapq.heappush(c, (v1,k1))
            heapq.heappush(c, (v2,k2))
    v1,k1=heapq.heappop(c)
    #print(v1,k1,c)
c.append((v1,k1))
cnt=0
for v,k in c:
    if v==-1:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect
H,W=map(int,input().split())
S=[input() for i in range(H)]
sec_x=[[-1] for i in range(H)]
sec_y=[[-1] for i in range(W)]
for y in range(H):
  for x in range(W):
    if S[y][x]=="#": 
      sec_x[y].append(x)
  sec_x[y].append(W)
for x in range(W):
  for y in range(H):
    if S[y][x]=="#": 
      sec_y[x].append(y)
  sec_y[x].append(H)

ans=0
#print(sec_x)
#print(sec_y)
for y in range(H):
  for x in range(W):
    if S[y][x]!="#":
      a=bisect(sec_x[y],x)
      b=bisect(sec_y[x],y)
      #print(x,y,a,b,sec_x[y][a]-sec_x[y][a-1]+sec_y[x][b]-sec_y[x][b-1]-3)
      ans=max(ans,sec_x[y][a]-sec_x[y][a-1]+sec_y[x][b]-sec_y[x][b-1]-3)
print(ans)    
          
    

Fixed submission:
from bisect import bisect
H,W=map(int,input().split())
S=[input() for i in range(H)]
sec_x=[[-1] for i in range(H)]
sec_y=[[-1] for i in range(W)]
for y in range(H):
  for x in range(W):
    if S[y][x]=="#": 
      sec_x[y].append(x)
  sec_x[y].append(W)
for x in range(W):
  for y in range(H):
    if S[y][x]=="#": 
      sec_y[x].append(y)
  sec_y[x].append(H)

ans=0
#print(sec_x)
#print(sec_y)
for y in range(H):
  l=1
  for x in range(W):
    if S[y][x]=="#":
      l+=1
    else:
      b=bisect(sec_y[x],y)
      #print(x,y,l,b,sec_x[y][l]-sec_x[y][l-1]+sec_y[x][b]-sec_y[x][b-1]-3)
      ans=max(ans,sec_x[y][l]-sec_x[y][l-1]+sec_y[x][b]-sec_y[x][b-1]-3)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
Graph=[[] for i in range(N)]
for i in range(N-1):
  u,v,w=map(int,input().split())
  w%=2
  Graph[u-1].append((v-1,w))
  Graph[v-1].append((u-1,w))
  
root=0
color=[-1]*N
color[0]=0
def dfs(x):
  for i,w in Graph[x]:
    if color[i]==-1:
      color[i]=(color[x]+w)%2
      dfs(i)
dfs(0)
for i in range(N):
  print(color[i])
    

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10**8)
N=int(input())
Graph=[[] for i in range(N)]
for i in range(N-1):
  u,v,w=map(int,input().split())
  w%=2
  Graph[u-1].append((v-1,w))
  Graph[v-1].append((u-1,w))
  
root=0
color=[-1]*N
color[0]=0
def dfs(x):
  for i,w in Graph[x]:
    if color[i]==-1:
      color[i]=(color[x]+w)%2
      dfs(i)
dfs(0)
for i in range(N):
  print(color[i])
Buggy python submission (verdict: Runtime Error):
M,K=map(int,input().split())
if 2**M<=K:
  print(-1)
  exit()
if K==0:
  ans=[]
  for i in range(2**M):
    ans.append(str(i))
    ans.append(str(i))
  print(" ".join(ans))
  exit()
if N==1:
  print(-1)
  exit()
ans=["0"]
for i in range(1,2**M):
  if i!=K:
    ans.append(str(i))
ans.append("0")
ans.append(str(K))
for i in range(1,2**M)[::-1]:
  if i!=K:
    ans.append(str(i))
ans.append(str(K))
print(" ".join(ans))

Fixed submission:
M,K=map(int,input().split())
if 2**M<=K:
  print(-1)
  exit()
if K==0:
  ans=[]
  for i in range(2**M):
    ans.append(str(i))
    ans.append(str(i))
  print(" ".join(ans))
  exit()
if M==1:
  print(-1)
  exit()
ans=["0"]
for i in range(1,2**M):
  if i!=K:
    ans.append(str(i))
ans.append("0")
ans.append(str(K))
for i in range(1,2**M)[::-1]:
  if i!=K:
    ans.append(str(i))
ans.append(str(K))
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return ((power(x,y//2)**2)*x)%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]+=dp[i+1][x%S[i]]*inv[N-i]
    dp[i][x]%=mod
    dp[i][x]+=(N-i-1)*dp[i+1][x]*inv[N-i]
    dp[i][x]%=mod
print((dp[0][X]*Factorial[N])%mod)

Fixed submission:
mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return ((power(x,y//2)**2)*x)%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]=dp[i+1][x%S[i]]+(N-i-1)*dp[i+1][x]
    dp[i][x]%=mod
print((dp[0][X])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]=dp[i+1][x%S[i]]*inv[N-i]+(N-i-1)*dp[i+1][x]*inv[N-i]
    dp[i][x]%=mod
print((dp[0][X]*Factorial[N])%mod)

Fixed submission:
mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return ((power(x,y//2)**2)*x)%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]=dp[i+1][x%S[i]]+(N-i-1)*dp[i+1][x]
    dp[i][x]%=mod
print((dp[0][X])%mod)