Problem p02744 (python)

Fixed submission:
import copy
N=int(input())
ans = [0]

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      
aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==6:
  for i in ans5:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  ans9.sort()
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Buggy submission (verdict: Runtime Error):
import copy
N=int(input())
ans = [0]

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      
ans9.sort()
aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)