Problem p03393 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"
# S = "qpwoeirutyalskdjfhgzmxnvcb"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            c = a[0:i]
            d = a[i:len(a)]
            d = sorted(d)
            # a[i-1]よりも大きくて最も小さいものを探す
            num = c.pop()
            ind = bisect.bisect_left(d, num)
            c.append(d[ind])
            print(func(c))
            break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            c = a[0:i]
            d = a[i:len(a)]
            # a[i-1]よりも大きくて最も小さいものを探す
            d.pop()
            d.append(min(d))
            print(func(d))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
            else:
                continue
        else:
            a = a[0:i]
            # ここから26文字未満の場合とほとんど同じ
            for i in range(len(a)):
                b.remove(a[i])
            a.pop()
            a.append(min(b))
            print(func(a))
            break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    print(a)
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
            else:
                continue
        else:
            a = a[0:i]
            # ここから26文字未満の場合とほとんど同じ
            for i in range(len(a)):
                b.remove(a[i])
            a.pop()
            a.append(min(b))
            print(func(a))
            break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    print(a)
    for i in reversed(range(len(s))):
        print(i)
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
            else:
                continue
        else:
            a = a[0:i]
            print(a)
            # ここから26文字未満の場合とほとんど同じ
            for i in range(len(a)):
                b.remove(a[i])
            a.pop()
            a.append(min(b))
            print(func(a))
            break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = str(input())
# S = "abcdefghijklmnopqrstuvwzyx"

s = list(S)
ss = []
for i in range(len(s)):
    ss.append(ord(s[i]))
a = list(ss)

t = [chr(i) for i in range(97, 97+26)]
tt = [i for i in range(97, 97+26)]
b = list(tt)


def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(ss) < 26):
    for i in range(len(s)):
        b.remove(ss[i])
    a.append(min(b))
    print(func(a))

if (len(ss) == 26):
    if (S == "zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
    else:
        for i in range(len(s)):
            if (a[i] == b[i]):
                continue
            else:
                c = a[0:i] + [b[i]]
                break
        print(func(c))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"

s = list(S)
ss = []
for i in range(len(s)):
    ss.append(ord(s[i]))
a = list(ss)

t = [chr(i) for i in range(97, 97+26)]
tt = [i for i in range(97, 97+26)]
b = list(tt)


def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(ss) < 26):
    for i in range(len(s)):
        b.remove(ss[i])
    a.append(min(b))
    print(func(a))

if (len(ss) == 26):
    if (S == "zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
    else:
        for i in range(len(s)):
            if (a[i] == b[i]):
                continue
            else:
                c = a[0:i] + [b[i]]
                break
        print(func(c))