Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
#途中

N=int(input())

C=[0]*2*10**5

ans=1
pre=-1

#ansの数にも影響を受ける
for _ in range(N):
    c=int(input())
    if pre!=c:
        ans+=C[c]
        C[c]+=1*ans
    pre=c
    print(ans,C[:10])
#print(ans)
    


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

l=[0]*2*10**5#ペアを作れるか診断
k=[0]*2*10**5#ansを記録

ans=1
pre=-1
for _ in range(N):
    c=int(input())-1
    if pre==c:
        continue
    l[c]+=1
    ans+=k[c]*min(l[c]-1,1)
    k[c]=ans
    pre=c
    """
    print(c+1)
    print(l[:5],k[:5])
    print(ans)
    """
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math
from functools import reduce

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

a=min(A)
ans=0


def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))
#きれた

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0
l=[]

def gcd(lis,num):
    temp=[]
    for item in lis:
        if num%item!=0:
            pass
        else:
            temp.append(item)
    return temp

for i in range(1,int(a**0.5)//1+1):
    if a%i==0:
        l.append(i)
        l.append(a//i)

for item in A:
    l=gcd(l,item)

print(max(l))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0

for i in range(1,int(a**0.5)//1+1):
    judge=True
    for item in A:
        if item%i!=0:
            judge=False
    if judge:
        ans=max(ans,i)

    judge=True
    for item in A:
        if item%(a//i)!=0:

            judge=False
    if judge:
        ans=max(ans,(a//i))
        
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0
l=[]

def gcd(lis,num):
    temp=[]
    for item in lis:
        if num%item!=0:
            pass
        else:
            temp.append(item)
    return temp

for i in range(1,int(a**0.5)//1+1):
    if a%i==0:
        l.append(i)
        l.append(a//i)

for item in A:
    l=gcd(l,item)

print(max(l))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()

count=0
num=0
#print(C)

if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        print(C)
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
    print(count)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()
 
count=0
num=0
#print(C)
 
if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
        if len(C)==0:
            break
    print(count)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()

count=0
num=0
print(C)
if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
    print(count)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()
 
count=0
num=0
#print(C)
 
if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
        if len(C)==0:
            break
    print(count)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def dfs(h,w,start):
    if S[h][w]=="#":
        black[start[0]][start[1]]+=1
    else:
        white[start[0]][start[1]]+=1
    
    visited[h][w]=1
    if h!=0:
        if visited[h-1][w]==-1 and S[h-1][w]!=S[h][w]:
            dfs(h-1,w,start)
    if w!=0:
        if visited[h][w-1]==-1 and S[h][w-1]!=S[h][w]:
            dfs(h,w-1,start)        
    if h!=H-1:
        if visited[h+1][w]==-1 and S[h+1][w]!=S[h][w]:
            dfs(h+1,w,start)        
    if w!=W-1:
        if visited[h][w+1]==-1 and S[h][w+1]!=S[h][w]:
            dfs(h,w+1,start)    
    return 

H,W=map(int,input().split())

S=[]

for _ in range(H):
    S.append(list(input()))

visited=[[-1 for j in range(W)] for i in range(H)]
black=[[0 for j in range(W)] for i in range(H)]
white=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if visited[i][j]==-1:
            dfs(i,j,[i,j])
        #print(visited)

ans=0
for i in range(H):
    for j in range(W):
        ans+=black[i][j]*white[i][j]
"""
print(S)
print(black)
print(white)
"""
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**9)

def dfs(h,w,start):
    if S[h][w]=="#":
        black[start[0]][start[1]]+=1
    else:
        white[start[0]][start[1]]+=1
    
    visited[h][w]=1
    if h!=0:
        if visited[h-1][w]==-1 and S[h-1][w]!=S[h][w]:
            dfs(h-1,w,start)
    if w!=0:
        if visited[h][w-1]==-1 and S[h][w-1]!=S[h][w]:
            dfs(h,w-1,start)        
    if h!=H-1:
        if visited[h+1][w]==-1 and S[h+1][w]!=S[h][w]:
            dfs(h+1,w,start)        
    if w!=W-1:
        if visited[h][w+1]==-1 and S[h][w+1]!=S[h][w]:
            dfs(h,w+1,start)    
    return 

H,W=map(int,input().split())

S=[]

for _ in range(H):
    S.append(list(input()))

visited=[[-1 for j in range(W)] for i in range(H)]
black=[[0 for j in range(W)] for i in range(H)]
white=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if visited[i][j]==-1:
            dfs(i,j,[i,j])
        #print(visited)

ans=0
for i in range(H):
    for j in range(W):
        ans+=black[i][j]*white[i][j]
"""
print(S)
print(black)
print(white)
"""
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

H=list(map(int,input().split()))

dp=[10**9]*(N)
dp[0]=0

for i in range(N):
    for j in range(i+1,min(i+1+K,N)):
        dp[j]=min(dp[i]+abs(H[j]-H[i]),dp[j])

print(dp[-1])


Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

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

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
H=list(map(int,input().split()))

dp=[10**9]*N
dp[0]=0

for i in range(N):
    for k in range(1,K+1):
        if i+k<N:
            dp[i+k]=min(dp[i+k],dp[i]+abs(H[i+k]-H[i]))
    
    
print(dp[-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

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

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

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

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])
    


Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

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

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
l=list(map(int,input().split()))

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])
    


Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

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

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,W=map(int,input().split())

l=[-1]*(W+1)
l[0]=0
dp=l[:]

for i in range(N):
    w,v=map(int,input().split())
    for index,item in enumerate(l):
        if item!=-1 and W>=index+w:
            dp[index+w]=max(item+v,l[index+w])
    l=dp[:]
print(max(l))


Fixed submission:
# coding: utf-8
# Your code here!
N,W=map(int,input().split())

l=[-1]*(W+1)
l[0]=0
dp=l[:]

for i in range(N):
    w,v=map(int,input().split())
    for index,item in enumerate(l):
        if item!=-1 and W>=index+w:
            dp[index+w]=max(item+v,l[index+w])
    l=dp[:]
print(max(l))
Buggy python submission (verdict: Time Limit Exceeded):
def dfs(num,count,ans):
    #print(num,count)
    ans=max(ans,count)
    for index,item in enumerate(l[num-1]):
        if item==1:
            dp[index+1]=max(dp[index+1],count)
            ans=dfs(index+1,count+1,ans)
    return ans
    
N,M=map(int,input().split())

l=[[0]*N for _ in range(N)]

start=[i+1 for i in range(N)]

for _ in range(M):
    x,y=map(int,input().split())
    l[x-1][y-1]=1
    try:
        start.remove(y)
    except:
        pass
#print(l)

dp=[0]*(N+1)
ans=0
for i in start:
    ans=max(dfs(i,0,0),ans)

#print(dp)
print(ans)
    

Fixed submission:
# coding: utf-8
# Your code here!
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

N,M=map(int,input().split())

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

for _ in range(M):
    x,y=map(int,input().split())
    linked[x-1].append(y-1)



def saiki(num):
    if visited[num]==1:
        return dp[num]
    
    visited[num]=1
    value=0
    if linked[num]:
        for item in linked[num]:
            value=max(value,saiki(item)+1)
    dp[num]=value
    return value

dp=[0]*N
visited=[0]*N
ans=0
for i in range(N):
    ans=max(ans,saiki(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
def bfs(h,w):
    if l[h][w]!=".":
        return 
    if h+1<H:
        if l[h+1][w]=="." and h+1<H:
            dp[h+1][w]+=dp[h][w]
            dp[h+1][w]%=(10**9+7)
            que.append([h+1,w])
    if w+1<W:
        if l[h][w+1]==".":
            dp[h][w+1]+=dp[w][h]
            dp[h][w+1]%=(10**9+7)
            que.append([h,w+1])
    l[h][w]="!"
    return

H,W=map(int,input().split())
l=[]
dp=[[0]*W for i in range(H)]

for _ in range(H):
    l.append(list(input()))

que=[[0,0]]
dp[0][0]=1
while True:
    
    if len(que)==0:
        break
    temp=que.pop(0)
    bfs(temp[0],temp[1])
    """
    for item in dp:
        print(item)
    print(temp)
    print("===================================")
    """
#print(l)
#print(dp)
print(dp[-1][-1]%(10**9+7))

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

A=[]
for _ in range(H):
    A.append(list(input()))

dp=[[0 for j in range(W+1)] for i in range(H+1)]
dp[1][1]=1

for h in range(H):
    for w in range(W):
        if A[h][w]==".":
            dp[h+1][w+1]+=dp[h][w+1]+dp[h+1][w]
            dp[h+1][w+1]%=(10**9+7)

print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
def bfs(h,w):
    if l[h][w]!=".":
        return 
    if h+1<H:
        if l[h+1][w]=="." and h+1<H:
            dp[h+1][w]+=dp[h][w]
            dp[h+1][w]%=(10**9+7)
            que.append([h+1,w])
    if w+1<W:
        if l[h][w+1]==".":
            dp[h][w+1]+=dp[w][h]
            dp[h][w+1]%=(10**9+7)
            que.append([h,w+1])
    l[h][w]="!"
    return

H,W=map(int,input().split())
l=[]
dp=[[0]*W for i in range(H)]

for _ in range(H):
    l.append(list(input()))

que=[[0,0]]
dp[0][0]=1
while True:
    
    if len(que)==0:
        break
    temp=que.pop(0)
    bfs(temp[0],temp[1])
    """
    for item in dp:
        print(item)
    print(temp)
    print("===================================")
    """
#print(l)
#print(dp)
print(dp[-1][-1]%(10**9+7))

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

A=[]
for _ in range(H):
    A.append(list(input()))

dp=[[0 for j in range(W+1)] for i in range(H+1)]
dp[1][1]=1

for h in range(H):
    for w in range(W):
        if A[h][w]==".":
            dp[h+1][w+1]+=dp[h][w+1]+dp[h+1][w]
            dp[h+1][w+1]%=(10**9+7)

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())

P=list(map(float,input().split()))

dp=[0]*(N+1)
dp[0]=1

for p in P:
    temp=[0]*(N+1)
    for i in range(N):
        temp[i+1]+=dp[i]*p
        temp[i]+=dp[i]*(1-p)
    temp[N]+=dp[N]
    dp=temp[:]

print(sum(dp[N//2+1:]))



Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(float,input().split()))

dp=[[0]*(N+1) for i in range(N+1)]

dp[0][0]=1
for n in range(N):
    for i in range(n+1):
        j=n-i
        dp[j][i+1]+=dp[j][i]*P[n]
        dp[j+1][i]+=dp[j][i]*(1-P[n])

ans=0
for i in range((N+1)//2):
    ans+=dp[i][-i-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())

P=list(map(float,input().split()))

dp=[[0 for i in range(N+1)] for j in range(N+1)]
dp[0][0]=1

for i in range(N):
    for j in range(N-i):
        dp[i+1][j]+=dp[i][j]*P[i+j]
        dp[i][j+1]+=dp[i][j]*(1-P[i+j])        

ans=0
start=(N+1)//2
j=0
for i in range(start,N+1)[::-1]:
    ans+=dp[i][j]
    j+=1
print(ans)
#print(dp)




Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(float,input().split()))

dp=[[0]*(N+1) for i in range(N+1)]

dp[0][0]=1
for n in range(N):
    for i in range(n+1):
        j=n-i
        dp[j][i+1]+=dp[j][i]*P[n]
        dp[j+1][i]+=dp[j][i]*(1-P[n])

ans=0
for i in range((N+1)//2):
    ans+=dp[i][-i-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(float,input().split()))

dp=[[0]*(N+1) for i in range(N+1)]

dp[0][0]=1
for n in range(N):
    for i in range(n+1):
        j=n-i
        dp[j][i+1]+=dp[j][i]*P[n]
        dp[j+1][i]+=dp[j][i]*(1-P[n])

ans=0
for i in range((N+1)//2):
    ans+=dp[i][-i-1]

print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(float,input().split()))

dp=[[0]*(N+1) for i in range(N+1)]

dp[0][0]=1
for n in range(N):
    for i in range(n+1):
        j=n-i
        dp[j][i+1]+=dp[j][i]*P[n]
        dp[j+1][i]+=dp[j][i]*(1-P[n])

ans=0
for i in range((N+1)//2):
    ans+=dp[i][-i-1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,P=map(int,input().split())

i=1
ans=1

if N==1:
    print(P)
else:
    while i**N<=P:
        if P%(i**N)==0:
            ans=i
        i+=1
    print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,P=map(int,input().split())

i=1
ans=1

if N==1:
    print(P)
else:
    while i**N<=P:
        if P%(i**N)==0:
            ans=i
        i+=1
    print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,P=map(int,input().split())

i=1
ans=1

if N==1:
    print(P)
else:
    try:
        while i**N<=P:#最大値適当
            if P%(i**N)==0:
                ans=i
            i+=1
        print(ans)
    except:
        print(ans)
        
#うんち

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,P=map(int,input().split())

i=1
ans=1

if N==1:
    print(P)
else:
    while i**N<=P:
        if P%(i**N)==0:
            ans=i
        i+=1
    print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,P=map(int,input().split())

i=1
ans=1

while i**N<=P:
    if P%(i**N)==0:
        ans=i
    i+=1
print(ans)

#むりやろ

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
S=input()
 
sum=0
judge=True

i=0
while i<len(S)-1:
    if S[i:i+2]=="BW":
        S=S[:i]+"WB"+S[i+2:]
        sum+=1
        i-=2
    i=max(0,i+1)
    
print(sum)



Fixed submission:
# coding: utf-8
# Your code here!
S=input()
N=len(S)

sum=0
k=0

for i in range(N):
    if S[i]=="W":
        sum+=(i-k)
        k+=1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
S=input()
 
sum=0
judge=True

i=0
while i<len(S)-1:
    if S[i:i+2]=="BW":
        S=S[:i]+"WB"+S[i+2:]
        sum+=1
        i-=2
    i=max(0,i+1)
    
print(sum)


Fixed submission:
# coding: utf-8
# Your code here!
S=input()
N=len(S)

sum=0
k=0

for i in range(N):
    if S[i]=="W":
        sum+=(i-k)
        k+=1

print(sum)

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

sum=0
judge=True

while judge:
    judge=False
    num=S.count("BW")
    sum+=num
    S=S.replace("BW","WB")
    if num!=0:
        judge=True

print(sum)


Fixed submission:
# coding: utf-8
# Your code here!
S=input()
N=len(S)

sum=0
k=0

for i in range(N):
    if S[i]=="W":
        sum+=(i-k)
        k+=1

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
l=[]
ans=10**9

for _ in range(N):
    l.append(int(input()))
    
l.sort()

for i in range(N-K+1):
    temp=max(l[i:i+K])-min(l[i:i+K])
    ans=min(ans,temp)

print(ans)

Fixed submission:
N,K=map(int,input().split())
l=[]
ans=10**9

for _ in range(N):
    l.append(int(input()))
    
l.sort()
temp=l[0:K]
ans=min(ans,temp[-1]-temp[0])

for i in range(N-K):
    temp.pop(0)
    temp.append(l[K+i])
    ans=min(ans,temp[-1]-temp[0])

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,X=map(int,input().split())

def dfs(count,object):
    count+=1
    object="B"+object+"P"+object+"B"
    if count<N:
        dfs(count,object)
    else:
        print(object)
        exit()

n=0
burger="P"

(dfs(n,burger))


Fixed submission:
# coding: utf-8
# Your code here!
N,X=map(int,input().split())

X-=1
def saiki(i,x,count):
    if i==-1:
        print(int(count)+1)
        exit()
    all=2**(i+2)-3
    paty=2**(i+1)-1
    if x==all-1:
        print(count+paty)
        exit()
    elif x==0:
        print(count)
    elif x==(all-1)//2:
        print(int(count+(paty-1)//2+1))
        exit()
    elif x>(all-1)//2:
        count+=((paty-1)//2+1)
        x-=(all//2)
        saiki(i-1,x-1,count)
    elif x<(all-1)//2:
        saiki(i-1,x-1,count)
    

ans=0
saiki(N,X,ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
stock=[N-i for i in range(N)]

if N==2:
    print("Yes")
    print(2)
    print(2,1,2)
    print(2,1,2)
    exit()

N*=2
n=-int(-N**0.5//1)
if N/n==N//n:
    yoko=N//n
else:
    print("No")
    exit()

ans=[[0 for j in range(yoko)]for i in range(n)]

for i in range(N-1):
    for j in range(i,yoko):
        temp=stock.pop(-1)
        ans[i][j]=temp
        ans[j+1][i]=temp

print("Yes")
print(len(ans))
for item in ans:
    print(len(item), *item)

Fixed submission:
N=int(input())
stock=[N-i for i in range(N)]

"""
if N==2:
    print("Yes")
    print(2)
    print(2,1,2)
    print(2,1,2)
    exit()
"""

N*=2
n=-int(-N**0.5//1)
if N/n==N//n and (n-N//n)==1:
    yoko=N//n
else:
    print("No")
    exit()

ans=[[0 for j in range(yoko)]for i in range(n)]

for i in range(N-1):
    for j in range(i,yoko):
        temp=stock.pop(-1)
        ans[i][j]=temp
        ans[j+1][i]=temp

print("Yes")
print(len(ans))
for item in ans:
    print(len(item), *item)

Buggy python submission (verdict: Runtime Error):
N=int(input())
stock=[N-i for i in range(N)]

N*=2
n=-int(-N**0.5//1)
if N/n==N//n:
    yoko=N//n
else:
    print("No")
    exit()

ans=[[0 for j in range(yoko)]for i in range(n)]

for i in range(N-1):
    for j in range(i,yoko):
        temp=stock.pop(-1)
        ans[i][j]=temp
        ans[j+1][i]=temp

print("Yes")
print(len(ans))
for item in ans:
    print(len(item), *item)

Fixed submission:
N=int(input())
stock=[N-i for i in range(N)]

"""
if N==2:
    print("Yes")
    print(2)
    print(2,1,2)
    print(2,1,2)
    exit()
"""

N*=2
n=-int(-N**0.5//1)
if N/n==N//n and (n-N//n)==1:
    yoko=N//n
else:
    print("No")
    exit()

ans=[[0 for j in range(yoko)]for i in range(n)]

for i in range(N-1):
    for j in range(i,yoko):
        temp=stock.pop(-1)
        ans[i][j]=temp
        ans[j+1][i]=temp

print("Yes")
print(len(ans))
for item in ans:
    print(len(item), *item)
Buggy python submission (verdict: Runtime Error):
l=raw_input().split()
 
print((l[0]-1)-(l[1]-1))

Fixed submission:

a,b=map(int,input().split())
 
print((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
l=raw_input().split()
 
print((l[0]-1)*(l[1]-1)+1)

Fixed submission:

a,b=map(int,input().split())
 
print((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
l=raw_input().split()
 
print((l[0]-1)-(l[1]-1)+1)

Fixed submission:

a,b=map(int,input().split())
 
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
l=[1]
count=0

def cand(num):
    i=1
    while N>=num**i:
        l.append(num**i)
        i+=1

def sub(target,index):
    i=0
    if target==0:
        
    elif index==0:
        
    while target-l[index]>0:
        sub(target-l[index]**i,l[index-1])
        

cand(6)
cand(9)

l.sort()
print(l)

#メモ　この方針があってるのかもわからん

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

def saiki(tgt,i,count,ans):
    #print(tgt,i,count,ans,temp[i])

    if i==0 or tgt==0:
        ans=min((tgt+count),ans)
        return ans
        
    num=tgt//temp[i]
    while num>=0:
        ans=saiki(tgt-num*temp[i],i-1,count+num,ans)
        if ans<(count+num):
            return ans
        num-=1
    return ans

temp=[1]
n=1
while N>=6**n:
    temp.append(6**n)
    n+=1
    
n=1
while N>=9**n:
    temp.append(9**n)
    n+=1

temp.sort()
#print(temp)

print(saiki(N,len(temp)-1,0,10**9))