Problem p03629 (python)

Fixed submission:
abc="abcdefghijklmnopqrstuvwxyz"

A=str(input())
n=len(A)
#make matrix (a-z)*(n characters)
#次にchrが出てくるindex
word_pos=[]
ct=[n]*26
orda=ord("a")

for i in range(n-1,-1,-1):
    ct[ord(A[i])-orda]=i
    word_pos.append(ct.copy())

word_pos.reverse()

dp=[0]*n+[1,0]
j=n
sep=[]
#区切れめをマーク
for i in range(n-1,-1,-1):
    ct=word_pos[i]
    if(max(ct)<j):
        #remove last chunk
        sep.append(i)
        j=min(ct)
        
if(j==n):
    for i in abc:
        if(i not in A):
            print(i+"\n")
            break

else:
    sep.reverse()
    ans=""
    for i in abc:
        if(i not in A[:sep[0]]):
            ans+=i
            break

    for i in range(0,len(sep)):
        start=sep[i]
        try:
            end=sep[i+1]
        except:
            end=n
        #ans[-1]が出現するタイミング
        next=word_pos[start][ord(ans[-1])-orda]
        for i in range(0,26):
            if(word_pos[next+1][i]>end-1):
                ans+=chr(orda+i)
                break
    ans+="\n"
    print(ans)

Buggy submission (verdict: Runtime Error):
abc="abcdefghijklmnopqrstuvwxyz"

A=str(input())
n=len(A)
#make matrix (a-z)*(n characters)
#次にchrが出てくるindex
word_pos=[]
ct=[n]*26
orda=ord("a")

for i in range(n-1,-1,-1):
    ct[ord(A[i])-orda]=i
    word_pos.append(ct.copy())

word_pos.reverse()

dp=[0]*n+[1,0]
j=n
sep=[]
#区切れめをマーク
for i in range(n-1,-1,-1):
    ct=word_pos[i]
    if(max(ct)<j):
        #remove last chunk
        sep.append(i+"\n")
        j=min(ct)
        
if(j==n):
    for i in abc:
        if(i not in A):
            print(i+"\n")
            break

else:
    sep.reverse()
    ans=""
    for i in abc:
        if(i not in A[:sep[0]]):
            ans+=i
            break

    for i in range(0,len(sep)):
        start=sep[i]
        try:
            end=sep[i+1]
        except:
            end=n
        #ans[-1]が出現するタイミング
        next=word_pos[start][ord(ans[-1])-orda]
        for i in range(0,26):
            if(word_pos[next+1][i]>end-1):
                ans+=chr(orda+i)
                break
    ans+="\n"
    print(ans)

Buggy submission (verdict: Runtime Error):
abc="abcdefghijklmnopqrstuvwxyz"

A=str(input())
n=len(A)
#make matrix (a-z)*(n characters)
#次にchrが出てくるindex
word_pos=[]
ct=[n]*26
orda=ord("a")

for i in range(n-1,-1,-1):
    ct[ord(A[i])-orda]=i
    word_pos.append(ct.copy())

word_pos.reverse()

dp=[0]*n+[1,0]
j=n
sep=[]
#区切れめをマーク
for i in range(n-1,-1,-1):
    ct=word_pos[i]
    if(max(ct)<j):
        #remove last chunk
        sep.append(i)
        j=min(ct)
        
if(j==n):
    for i in abc:
        if(i not in A):
            print(i)
            break

sep.reverse()
ans=""
for i in abc:
    if(i not in A[:sep[0]]):
        ans+=i
        break

for i in range(0,len(sep)):
    start=sep[i]
    try:
        end=sep[i+1]
    except:
        end=n
    #ans[-1]が出現するタイミング
    next=word_pos[start][ord(ans[-1])-orda]
    for i in range(0,26):
        if(word_pos[next+1][i]>end-1):
            ans+=chr(orda+i)
            break
ans+="\n"
print(ans)

Buggy submission (verdict: Runtime Error):
abc="abcdefghijklmnopqrstuvwxyz"

A=str(input())
n=len(A)
#make matrix (a-z)*(n characters)
#次にchrが出てくるindex
word_pos=[]
ct=[n]*26
orda=ord("a")

for i in range(n-1,-1,-1):
    ct[ord(A[i])-orda]=i
    word_pos.append(ct.copy())

word_pos.reverse()

dp=[0]*n+[1,0]
j=n
sep=[]
#区切れめをマーク
for i in range(n-1,-1,-1):
    ct=word_pos[i]
    if(max(ct)<j):
        #remove last chunk
        sep.append(i)
        j=min(ct)

sep.reverse()
ans=""
for i in abc:
    if(i not in A[:sep[0]]):
        ans+=i
        break

for i in range(0,len(sep)):
    start=sep[i]
    try:
        end=sep[i+1]
    except:
        end=n
    #ans[-1]が出現するタイミング
    next=word_pos[start][ord(ans[-1])-orda]
    for i in range(0,26):
        if(word_pos[next+1][i]>end-1):
            ans+=chr(orda+i)
            break
ans+="\n"
print(ans)

Buggy submission (verdict: Runtime Error):
A=str(input())
memo=[]
count=0
ans=""
index=[]
for i in range(0,len(A)):
    target=A[len(A)-1-i]
    if(target not in memo):
        memo.append(target)
        count+=1
    if(count==26):
        count=0
        memo=[]
        index.append(len(A)-1-i)
for i in "abcdefghijklmnopqrstuvwxyz":
    if(i not in memo):
        ans+=i
        break
num=0
index=index[::-1]

a=0
b=0
for j in range(0,len(index)-1):
    a=index[j]
    b=index[j+1]
    print(a,b)
    target=A[a:b]
    num=target.find(ans[j])
    for i in "abcdefghijklmnopqrstuvwxyz":
        if(i not in target[num:]):
            ans+=i
            break

target=A[index[len(index)-1]:]
num=target.find(ans[len(index)-1])
for i in "abcdefghijklmnopqrstuvwxyz":
    if(i not in target[num:]):
        ans+=i
        break
ans+="\n"
print(ans)