Buggy python submission (verdict: Runtime Error):
def f():
 n,c=map(int,input().split())
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+str(c)*(c>=0)+t[::-1])
     for i in range(3,int(x**.5+1),2):
      if x%i==0:break
     else:return a
  else:
   a=int(h+str(c)*(c>=0)+h)
   for i in range(3,int(x**.5+1),2):
    if x%i==0:break
   else:return a
 return'9'*n+str(c)*(c>=0)+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def f():
 n,c=map(int,input().split())
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+str(c)*(c>=0)+t[::-1])
     for i in range(3,int(a**.5+1),2):
      if a%i==0:break
     else:return a
  else:
   a=int(h+str(c)*(c>=0)+h)
   for i in range(3,int(a**.5+1),2):
    if a%i==0:break
   else:return a
 return'9'*n+str(c)*(c>=0)+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def f():
 n,c=map(int,input().split())
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+str(c)*(c>=0)+t[::-1])
     if 2 in[x,pow(2,x,x)]:
      for i in range(3,int(a**.5+1),2):
       if a%i==0:break
      else:return a
  else:
   a=int(h+str(c)*(c>=0)+h)
   if 2 in[x,pow(2,x,x)]:
    for i in range(3,int(a**.5+1),2):
     if a%i==0:break
    else:return a
 return'9'*n+str(c)*(c>=0)+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def f():
 n,c=map(int,input().split())
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+str(c)*(c>=0)+t[::-1])
     if 2 in[a,pow(2,a,a)]:
      for i in range(3,int(a**.5+1),2):
       if a%i==0:break
      else:return a
  else:
   a=int(h+str(c)*(c>=0)+h)
   if 2 in[a,pow(2,a,a)]:
    for i in range(3,int(a**.5+1),2):
     if a%i==0:break
    else:return a
 return'9'*n+str(c)*(c>=0)+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def p(x):
 if 2 in[a,pow(2,a,a)]:
  for i in range(3,int(a**.5+1),2):
   if a%i==0:return 0
  else:return 1
def f():
 n,c=map(int,input().split())
 b=str(c)*(c>=0)
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+b+t[::-1])
     if p(a):return a
  else:
   a=int(h+b+h)
   if p(a):return a
 return'9'*n+b+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def p(x):
 if 2 in[x,pow(2,x,x)]:
  for i in range(3,int(x**.5+1),2):
   if x%i==0:return 0
  else:return 1
def f():
 n,c=map(int,input().split())
 b=str(c)*(c>=0)
 for h in'9731':
  if n>1:
   for m in range(int(10**(n-1)),0,-1):
    if((int(h)+m-1)*2+(c>=0)*c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+b+t[::-1])
     if p(a):return a
  else:
   a=int(h+b+h)
   if p(a):return a
 return'9'*n+b+'9'*n
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())

Buggy python submission (verdict: Runtime Error):
def p(x):
 for i in range(7,int(x**.5+1),2):
  if x%i==0:return 0
 else:return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 c=str(c)
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    if((int(h)+m-1)*2+c)%3:
     t=h+str(m-1).zfill(n-1)
     a=int(t+c+t[::-1])
     if p(a):return a
  else:
   a=int(h+c+h)
   if p(a):return a
 return s+b+s
print(f())


Fixed submission:
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())