Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02570 (python)

Fixed submission:
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    d, t, s = mi()

    if s * t >= d:
        print(yes)
    else:
        print(no)


main()

Buggy submission (verdict: Runtime Error):
import collections
n, m = map(int, input().split())
par = [i for i in range(0, n + 1)]
# print(par)
s = list()
"""
# union find(parには0も入れているので、par[1]=1になる)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
"""


def find(x):

    while par[x] != x:
        tmp = par[x]
        par[x] = par[par[x]]
        x = par[x]

    return x


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        par[x] = y


# 各要素をunionする
for j in range(m):
    a, b = map(int, input().split())
    union(a, b)

# 1～nの親を探してsに入れていき、一番多い親を答えにする
for k in range(1, n + 1):
    s.append(find(k))
# print(s)
c = collections.Counter(s)
print(max(c.values()))
Problem p02629 (python)

Fixed submission:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    n = ii()
    tmp = 26
    cnt = 1
    while n > tmp:
        n-=tmp
        tmp*=26
        cnt+=1
    cnt-=1
    tmplist = []
    while cnt > 0:
        tmptmp = 26**cnt

        if n%tmptmp == 0:
            tmplist.append(n//tmptmp-1)

        else:
            tmplist.append(n//tmptmp)
        n%=tmptmp
        cnt-=1
    if n%26 == 0:
        tmplist.append(25)
    else:
        tmplist.append(n-1)

    ans = ''
    for i in tmplist:
        ans+=l[i]

    print(ans)



main()

Buggy submission (verdict: Runtime Error):
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    n = ii()
    tmp = 26
    cnt = 1
    while n > tmp:
        n-=tmp
        tmp*=26
        cnt+=1
    cnt-=1
    tmplist = []
    while cnt > 0:
        tmptmp = 26**cnt
        tmplist.append(n//tmptmp)
        n%=tmptmp
        cnt-=1
    tmplist.append(n-1)

    ans = ''
    for i in tmplist:
        ans+=l[i]

    print(ans)



main()
Problem p02831 (python)

Fixed submission:
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    a,b = mi()

    print(lcm(a, b))

    
main()

Buggy submission (verdict: Runtime Error):
import math

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    a,b = mi()

    print(lcm(a, b))

    
main()
Problem p02990 (python)

Fixed submission:
from math import factorial
from sys import exit

bign = 10**9 + 7


n,k = map(int,input().split())
nk = n-k+1

if n == k:
    print(1)
    for i in range(k-1):
        print(0)
    exit()

ans = nk
print(ans)
if k-1<=nk:
    for i in range(1,k):
        i1 = i+1
        ans = (ans * (nk-i) // i1)
        ans = (ans * (k-i) // i)
        print(ans%bign)
else:
    for i in range(1,nk+1):
        i1 = i+1
        ans = (ans * (nk-i) // i1)
        ans = (ans * (k-i) // i)
        print(ans%bign)
    for i in range(k-1-nk):
        print(0)

Buggy submission (verdict: Runtime Error):
from math import factorial
from sys import exit

bign = 10**9 + 7


n,k = map(int,input().split())
nk = n-k+1

if n == k:
    print(1)
    for i in range(k-1):
        print(0)
    exit()

ans = nk
print(ans)
if k-1<=nk:
    for i in range(1,k):
        i1 = i+1
        ans = (ans * (nk-i) / i1)
        ans = (ans * (k-i) / i)
        print(int(ans)%bign)
else:
    for i in range(1,nk+1):
        i1 = i+1
        ans = (ans * (nk-i) / i1)
        ans = (ans * (k-i) / i)
        print(int(ans)%bign)
    for i in range(k-1-nk):
        print(0)
Problem p02629 (python)

Fixed submission:
n = int(input())

out = ""
while n > 0:
    n -= 1
    out += chr(ord('a') + n % 26)
    n //= 26

print(out[::-1])

Buggy submission (verdict: Runtime Error):
n = int(input())

for d in range(1, n):
    if n <= 26 ** d:
        break
    n -= 26 ** d

n -= 1
out = ""
for i in range(d - 1, -1, -1):
    out += chr(ord('a') + n // (26 ** i))
    n %= 26 ** i
print(out)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = n

for d in range(1, n):
    if m <= 26 ** d:
        break
    m -= 26 ** d

out = ""
for i in range(d - 1, -1, -1):
    out += chr(ord('a') + n // (26 ** i) - 1)
    n %= 26 ** i
print(out)
Problem p02623 (python)

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

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

a, b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans, j=0,m

for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

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

sumA=0
sumB=0
minAB=0

for i in range(n):
    sumA+=A[i]
for i in range(m):
    sumB+=B[i]
for i in range(min(n, m)):
    minAB+=A[i]+B[i]

if sumA+sumB<=k:
    ans=n+m
elif A[0]>k or B[0]>k:
    ans=0
else :
    if minAB>k:
        ans=min(n, m)
        if min(n, m)==n:
            for i in range(min(n, m), max(n, m)):
                if B[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
        else:
            for i in range(min(n, m), max(n, m)):
                if A[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
    else:
        for i in reversed(0, min(n,m)):
            if minAB-A[i]-B[i]>=k:
                minAB-=A[i]+B[i]
                ans-=2
            else:
                if minAB-A[i]<k or minAB-B[i]<k:
                    ans-=1
                else:
                    ans-=2
print(ans)
Problem p02701 (python)

Fixed submission:
n=int(input())
S=[]
for i in range(n):
    S.append(input())
print(len(list(set(S))))

Buggy submission (verdict: Runtime Error):
n=int(input())
S=list(map(int,input().split()))
print(len(list(set(S))))
Problem p02597 (python)

Fixed submission:
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        # print(f"L:{left}  R:{right}  w:{w}  r:{r}  op:{op}")
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left or right == 0 or left == len(CS) - 1:
            break

    change = op
    print(min(wtotal, rtotal, change))


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    upper_bound = min(wtotal, rtotal)

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left:
            break

    change = op + w + r
    print(min(upper_bound, change))


main()
Problem p02659 (python)

Fixed submission:
def main():
    ab = [_x for _x in input().split()]
    n = ab[1]
    bb = (int(n[0])*100 + int(n[2])*10 + int(n[3]))
    aa = int(ab[0])
    if aa == 0:
        print(0)
        return
    if bb == 0:
        print(0)
        return
    result = str(aa*bb)

    if len(result) <= 2:
        print(0)
    else:
        print(str(result)[:-2])


main()

Buggy submission (verdict: Runtime Error):
def main():
    ab = [int(_x) for _x in input().split()]
    print(int(ab[0] * ab[1]))


main()
Problem p02781 (python)

Fixed submission:
import sys
n=list(input())
N=len(n)
k=int(input())
x=int(n[0])
if N<k:
  print(0)
  sys.exit()

def s1(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s1(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=(N-1)*9
    ans+=x
    return ans

def s2(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s2(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=((N-1)*(N-2))*81//2
    ans+=((x-1)*(N-1))*9
    m2=m[1:N+1]
    ans+=s1(m2)
    return ans
  
def s3(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s3(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=((N-1)*(N-2)*(N-3)*729)//6
    ans+=((x-1)*(N-1)*(N-2)*81)//2
    m2=m[1:N+1]
    ans+=s2(m2)
    return ans

if k==1:
  print(s1(n))
  sys.exit()

if k==2:
  print(s2(n))
  sys.exit()

if k==3:
  print(s3(n))
  sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
n=list(input())
N=len(n)
k=int(input())
dp=[[0 for i in range(len(n))] for j in range(k)]
ans=0
x=int(n[0])

if k==1:
  ans+=(N-1)*9
  ans+=x
  print(ans)
  sys.exit()

elif k==2:
  ans+=(N-1)*(N-2)*81//2
  ans+=(x-1)*(N-1)*9
  n2=n[1:N+1]
  N2=len(n2)
  x=int(n2[0])
  ans+=(N2-1)*9
  ans+=x
  print(ans)
  sys.exit()

else:
  ans+=(N-1)*(N-2)*(N-3)*729//6
  ans+=(x-1)*(N-1)*(N-2)*81//2
  n=n[1:N+1]
  N=len(n)
  x=int(n[0])
  ans2=0
  ans2+=(N-1)*(N-2)*81//2
  ans2+=(x-1)*(N-1)*9
  n2=n[1:N+1]
  N2=len(n2)
  x=int(n2[0])
  ans2+=(N2-1)*9
  ans2+=x
  ans+=ans2
  print(ans)
  sys.exit()
Problem p02815 (python)

Fixed submission:
import sys
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
if n==1:
  print(c[0]*2%mod)
  sys.exit()
c.sort()
c.reverse()
ans=0
x=pow(2,n-2,mod)
for i in range(n):
  ans+=c[i]*(i+2)*x
  ans%=mod
ans*=pow(2,n,mod)
ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
c.sort()
c.reverse()
ans=0
x=pow(2,n-2,mod)
for i in range(n):
  ans+=c[i]*(i+2)*x
  ans%=mod
ans*=pow(2,n,mod)
ans%=mod
print(ans)
Problem p02863 (python)

Fixed submission:
import sys
input=sys.stdin.readline
import copy
def knapsack(N,W,weight,value):
  dp=[[999999999999 for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1): dp[0][i]=0
 
  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w:
        if dp[i][w-weight[i]]+value[i]>dp[i][w]:
          dp[i+1][w]=dp[i][w-weight[i]]+value[i]
        else:
          dp[i+1][w]=dp[i][w]
      else:
        dp[i+1][w]=dp[i][w]
  return dp
 
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
a=[];b=[]
for i in range(n):
  a.append(l[i][0])
  b.append(l[i][1])
dp=knapsack(n,t-1,a,b)
ans=[]
for i in range(n):
  if i!=n:
    ans.append(dp[i][t-1]+b[i])
  else:
    ans.append(dp[n][t-i])
print(max(ans))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import copy
def knapsack(N,W,weight,value):
  dp=[[999999999999 for i in range(W+1)] for j in range(N+1)]
  dp2=[[0 for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1): dp[0][i]=0
 
  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w:
        if dp[i][w-weight[i]]+value[i]>dp[i][w]:
          dp[i+1][w]=dp[i][w-weight[i]]+value[i]
          dp2[i+1][w]=w-weight[i]
        else:
          dp[i+1][w]=dp[i][w]
          dp2[i+1][w]=w
        
      else:
        dp[i+1][w]=dp[i][w]
        dp2[i+1][w]=w
  
  l=[]
  x=W
  for i in range(n-1,-1,-1):
    if dp2[i+1][x]==x-weight[i]:
      l.append(i)
    x=dp2[i+1][x]
  return dp[N][W],l
 
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=[];b=[]
for i in range(n):
  a.append(l[i][0])
  b.append(l[i][1])
z=knapsack(n,t-1,a,b)
L=[0]*n
for i in range(len(z[1])):
  L[z[1][i]]=1
M=[]
for i in range(n):
  if L[i]==0:
    M.append(l[i][1])
print(z[0]+max(M))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import copy
def knapsack(N,W,weight,value):
  dp=[[999999999999 for i in range(W+1)] for j in range(N+1)]
  dp2=[[() for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1): dp[0][i]=0

  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w:
        if dp[i][w-weight[i]]+value[i]>dp[i][w]:
          dp[i+1][w]=dp[i][w-weight[i]]+value[i]
          x=copy.copy(dp2[i][w-weight[i]])
          x.append(i)
          dp2[i+1][w]=x
        else:
          dp[i+1][w]=dp[i][w]
          dp2[i+1][w]=dp2[i][w]
        
      else:
        dp[i+1][w]=dp[i][w]
        dp2[i+1][w]=dp2[i][w]
  return [dp[N][W],dp2[N][W]]

n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=[];b=[]
for i in range(n):
  a.append(l[i][0])
  b.append(l[i][1])
z=knapsack(n,t-1,a,b)
x=z[0];y=z[1]
L=[0 for i in range(n)]
m=0
for i in range(len(y)):
  L[y[i]]=1
M=[]
for i in range(n):
  if L[i]==0:
    M.append(b[i])
if len(M)==0:
  print(x)
else:
  print(x+max(M))
Problem p02925 (python)

Fixed submission:
import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ct=[0 for i in range(n)]
fin=0
day=0
count=0
check=[0,0]
while count!=n*(n-1)//2 and day<=10**4:
  L=[0 for i in range(n)]
  f1=0
  for i in range(n):
    if L[i]==0 and ct[i]!=n-1:
      x=l[i][ct[i]]
      if l[x-1][ct[x-1]]-1==i and L[x-1]==0:
        ct[i]+=1
        ct[x-1]+=1
        L[i]=1
        L[x-1]=1
        count+=1
  day+=1
  check[0]=check[1]
  check[1]=count
  if check[0]==check[1]:
    print(-1)
    sys.exit()
if day>10**4:
  print(n*(n-1)//2)
  sys.exit()
print(day)

Buggy submission (verdict: Runtime Error):
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
 L=[0]*n;y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]-1==i+L[x]+L[i]:
    a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
 d*=y
print([k//2,d-1][d<9999])
Problem p03017 (python)

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=list(input())
if c<d:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
  if f==1:print('No')
  else:print('Yes')
else:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
  if f==0:
    if (s[d-2]=='#' or s[d]=='#') and (s[b-2]=='#' or s[b]=='#'):
      ct=0
      for i in range(b-1,d-2):
        if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
          ct+=1
          break
      if ct==0:
        f=1
  if f==1:print('No')
  else:print('Yes')

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=input()
f=0;F=0
for i in range(a,max(c,d)-1):
  if s[i]=='#' and s[i+1]=='#':f=1
for i in range(b-2,d-1):
  if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':F=1
if F==0 and c>d:f=1
print('YNeos'[f::2])

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=list(input())
f=0
for i in range(b,d-1):
  if s[i]=='#' and s[i+1]=='#':
    f=1
    break
for i in range(a,c-1):
  if s[i]=='#' and s[i+1]=='#':
    f=1
    break
if c>d:
  F=0
  for i in range(b-1,d):
    if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
      F=1
      break
  if F==0:
    f=1
if f==1:print('No')
else:print('Yes')

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=list(input())
if c<d:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f==1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
  if f==1:print('No')
  else:print('Yes')
else:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==1:
    print('No')
  else:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
    if f==1:
      print('No')
    else:
      if s[d-2]=='#' or s[d]=='#':
        ct=0
        for i in range(b,d-2):
          if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
            ct=1
            break
        if ct==0:
          if s[b-2]=='#' or s[b]=='#':
          print('No')
        else:
          print('Yes')
      else:
        print('Yes')
Problem p03055 (python)

Fixed submission:
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
 
distance1=[-1 for i in range(n)]
distance1[0]=0
next=connection[0]
next2=[]
check=[-1 for i in range(n)]
check[0]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
  ct+=1
  for i in range(len(next)):
    distance1[next[i]]=ct
    check[next[i]]=1
    checkct+=1
    for j in range(len(connection[next[i]])):
      if check[connection[next[i]][j]]==-1:
        next2.append(connection[next[i]][j])
  next=next2
  next2=[]

x=max(distance1)
x=distance1.index(x)

distance2=[-1 for i in range(n)]
distance2[x]=0
next=connection[x]
next2=[]
check=[-1 for i in range(n)]
check[x]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
  ct+=1
  for i in range(len(next)):
    distance2[next[i]]=ct
    check[next[i]]=1
    checkct+=1
    for j in range(len(connection[next[i]])):
      if check[connection[next[i]][j]]==-1:
        next2.append(connection[next[i]][j])
  next=next2
  next2=[]

if max(distance2)%3==1:
  print('Second')
else:
  print('First')

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[0 for i in range(n)]
L=[list(map(int,input().split())) for i in range(n-1)]
ct=0
for i in range(n-1):
  l[L[i][0]-1]+=1
  l[L[i][1]-1]+=1
for i in range(n):
  if l[i]>=3:ct+=1
if ct%2=0:print('First')
else:print('Second')

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[0 for i in range(n)]
L=[list(map(int,input().split())) for i in range(n-1)]
ct=0
for i in range(n-1):
  l[L[i][0]-1]+=1
  l[L[i][1]-1]+=1
x=1
for i in range(n):
  if l[i]%2==1 and l[i]>x:
    x=l[i]
xn=l.index(x)
ctx=0
for j in range(n-1):
  if L[j][0]==xn+1:
    if l[L[j][1]-1]%2==1:ctx+=1
  elif L[j][1]==xn+1:
    if l[L[j][0]-1]%2==1:ctx+=1

if ctx%2==1 or x<3:print('First')
else:print('Second')
Problem p03209 (python)

Fixed submission:
n,x=map(int,input().split())
l=[]
for i in range(n+1):
  l.append(2**(i+1)-1)
m=[]
for i in range(n+1):
  m.append(2**(i+2)-3)
c=0
for i in range(n,-1,-1):
  if x<2**(i+1)-1:
    x-=1
  elif x==2**(i+1)-1:
    if i!=0:
      c+=l[i-1]+1
    elif i==0:
      c+=1
    x=0
  elif x>2**(i+1)-1:
    if i!=0:
      c+=l[i-1]+1
    elif i==0:
      c+=1
    elif x==m[i]:
      x-=1
    x=x-(2**(i+1)-1)
print(c)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=[0]
for i in range(n+1):
  l.append(2**(i+1)-1)
m=[0]
for i in range(n+1):
  m.append(2**(i+2)-3)
c=0
for i in range(n,-1,-1):
  if x<2**(i+1)-1:
    x-=1
  elif x==2**(i+1)-1:
    c+=l[i]+1
    x=0
  elif x>2**(i+1)-1:
    c+=l[i]+1
    elif x==m[i+1]:
      x-=1
    x=x-(2**(i+1)-1)
print(c)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=[0]
for i in range(n+1):
  l.append(2**(i+1)-1)
m=[0]
for i in range(n+1):
  m.append(2**(i+2)-3)
c=0
for i in range(n,-1,-1):
  if x<2**(i+1)-1:
    x-=1
  elif x==2**(i+1)-1:
    c+=l[i]+1
    x=0
  elif x>2**(i+1)-1:
    c+=l[i]+1
    elif x==m[i+1]:
      x-=1
    x=x-(2**(i+1)-1)
print(c)
Problem p03253 (python)

Fixed submission:
import collections
import sys

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

def fact(n):
  l=primes(int(n**0.5)+1)
  L=[]
  for i in range(len(l)):
    while n%l[i]==0:
      n=n//l[i]
      L.append(l[i])
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n,M=map(int,input().split())
if M==1:
  print(1)
  sys.exit()
m=10**9+7
x=list(collections.Counter(fact(M)).values())

g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,max(x)+n):
  g1.append((g1[-1]*i)%m)
  inverse.append((-inverse[m%i]*(m//i))%m)
  g2.append((g2[-1]*inverse[-1])%m)

ans=1

for i in range(len(x)):
  ans*=cmb(x[i]+n-1,x[i],m)
  ans%=m
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import sys

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

def fact(n):
  l=primes(int(n**0.5)+1)
  L=[]
  for i in range(len(l)):
    while n%l[i]==0:
      n=n//l[i]
      L.append(l[i])
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n,M=map(int,input().split())
if n==1 and M==1:
  print(1)
  sys.exit()
m=10**9+7
x=list(collections.Counter(fact(M)).values())

g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,max(x)+n):
  g1.append((g1[-1]*i)%m)
  inverse.append((-inverse[m%i]*(m//i))%m)
  g2.append((g2[-1]*inverse[-1])%m)

ans=1

for i in range(len(x)):
  ans*=cmb(x[i]+n-1,x[i],m)
  ans%=m
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

def fact(n):
  l=primes(int(n**0.5)+1)
  L=[]
  for i in range(len(l)):
    while n%l[i]==0:
      n=n//l[i]
      L.append(l[i])
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n,M=map(int,input().split())
m=10**9+7
x=list(collections.Counter(fact(M)).values())

g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,max(x)+n):
  g1.append((g1[-1]*i)%m)
  inverse.append((-inverse[m%i]*(m//i))%m)
  g2.append((g2[-1]*inverse[-1])%m)

ans=1

for i in range(len(x)):
  ans*=cmb(x[i]+n-1,x[i],m)
  ans%=m
print(ans)