Problem p02745 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
A=input()
B=input()
C=input()

a,b,c=len(A),len(B),len(C)

def f(X,Y):
  XY=[True]*(10**4)
  x,y=len(X),len(Y)
  for i in range(5000-y+1,5000+x):
    ret=True
    if i<=5000:
      for j in range(min(x,y+i-5000)):
        if X[j]=="?" or Y[j-i+5000]=="?" or X[j]==Y[j-i+5000]:
          continue
        else:
          ret=False
    else:
      for j in range(min(y,x-i+5000)):
        if Y[j]=="?" or X[j+i-5000]=="?" or Y[j]==X[j+i-5000]:
          continue
        else:
          ret=False
    XY[i]=ret
  return XY
AB=f(A,B)
BC=f(B,C)
AC=f(A,C)
ans=a+b+c
for i in range(5000-b-c,5000+a+c):
  for j in range(5000-b-c,5000+a+b):
    if -4000<=j-i<=4000:
      if AB[i] and AC[j] and BC[j-i+5000]:
        l=min(5000,i,j)
        r=max(i+b,j+c,5000+a)
        ans=min(ans,r-l)
    else:
      if AB[i] and AC[j]:
        l=min(5000,i,j)
        r=max(i+b,j+c,5000+a)
        ans=min(ans,r-l)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
A=input()
B=input()
C=input()

a,b,c=len(A),len(B),len(C)

def f(X,Y):
  XY=[True]*(10**4)
  x,y=len(X),len(Y)
  for i in range(5000-y+1,5000+x):
    ret=True
    if i<=5000:
      for j in range(min(x,y+i-5000)):
        if X[j]=="?" or Y[j-i+5000]=="?" or X[j]==Y[j-i+5000]:
          continue
        else:
          ret=False
    else:
      for j in range(min(y,x-i+5000)):
        if Y[j]=="?" or X[j+i-5000]=="?" or Y[j]==X[j+i-5000]:
          continue
        else:
          ret=False
    XY[i]=ret
  return XY
AB=f(A,B)
BC=f(B,C)
AC=f(A,C)
ans=a+b+c
for i in range(5000-b-c,5000+a+c):
  if AB[i]:
    for j in range(5000-b-c,5000+a+b):
      if -4000<=j-i<=4000:
        if AC[j] and BC[j-i+5000]:
          l=min(5000,i,j)
         r=max(i+b,j+c,5000+a)
          ans=min(ans,r-l)
      else:
        if AC[j]:
          l=min(5000,i,j)
          r=max(i+b,j+c,5000+a)
          ans=min(ans,r-l)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
A=input()
B=input()
C=input()

a,b,c=len(A),len(B),len(C)

def f(X,Y):
  XY=[True]*(10**4)
  x,y=len(X),len(Y)
  for i in range(5000-y+1,5000+x):
    ret=True
    if i<=5000:
      for j in range(min(x,y+i-5000)):
        if X[j]=="?" or Y[j-i+5000]=="?" or X[j]==Y[j-i+5000]:
          continue
        else:
          ret=False
    else:
      for j in range(min(y,x-i+5000)):
        if Y[j]=="?" or X[j+i-5000]=="?" or Y[j]==X[j+i-5000]:
          continue
        else:
          ret=False
    XY[i]=ret
  return XY
AB=f(A,B)
BC=f(B,C)
AC=f(A,C)
ans=a+b+c
for i in range(5000-b-c,5000+a+c):
  for j in range(5000-b-c,5000+a+b):
    if AB[i] and AC[j] and BC[j-i+5000]:
      l=min(5000,i,j)
      r=max(i+b,j+c,5000+a)
      ans=min(ans,r-l)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[chr(97+int(i)) for i in range(n)]

Ans=["a"]
if n>=2:
  for _ in range(n-1):
    Ans2=[]
    for a in Ans:
      s=set()
      for aa in a:
        s.add(aa)
      ss=len(s)
      for i in range(ss+1):
        Ans2.append(a+A[i])
    Ans=Ans2
Ans.sort()
for ans in Ans:
  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=[1]*n
Ans=[C]
cur=n-1
while cur:
  cur=0
  m=1
  for i in range(n-1):
    if C[i+1]<i+2:
      cur=i+1
  for i in range(cur):
    m=max(m,C[i])
  D=[]
  if C[cur]+1>m+1:
    cur-=1
  for i in range(n):
    if i<cur:
      D.append(C[i])
    elif i==cur:
      D.append(C[i]+1)
    else:
      D.append(1) 
  if cur!=0:
    Ans.append(D)
  C=Ans[-1]
for a in Ans:
  ans=""
  for i in range(n):
    ans+=chr(a[i]+96)
  print(ans)