Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
acgt = []
cnt = 0
for a in s:
    if a == 'A' or a == 'C' or a == 'T' or a == 'G':
        cnt += 1
    else:
        acgt.append(cnt)
        cnt = 0
acgt.appen(cnt)
print(max(acgt))
        

Fixed submission:
s = input()
acgt = []
cnt = 0
for a in s:
    if a == 'A' or a == 'C' or a == 'T' or a == 'G':
        cnt += 1
    else:
        acgt.append(cnt)
        cnt = 0
acgt.append(cnt)
print(max(acgt))

Buggy python submission (verdict: Runtime Error):
s = input()
acgt = []
cnt = 0
for a in s:
    if a == 'A' or a == 'C' or a == 'T' or a == 'G':
        cnt += 1
    else:
        acgt.append(cnt)
        cnt = 0
print(max(acgt))

Fixed submission:
s = input()
acgt = []
cnt = 0
for a in s:
    if a == 'A' or a == 'C' or a == 'T' or a == 'G':
        cnt += 1
    else:
        acgt.append(cnt)
        cnt = 0
acgt.append(cnt)
print(max(acgt))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
 
def cnt():
    n, q = map(int, input().split())
    s = input()
    qs = []
    for i in range(q):
        qs.append(list(map(int, input().split())))
    for l, r in qs:
        que = deque(maxlen = 2)
        cnt = 0
        for a in s[l-1: r]:
            que.append(a)
            if que == deque(['A', 'C']):
                cnt += 1
        print(cnt)
        
cnt()

Fixed submission:
N, Q = map(int, input().split())
S = input()
qs = [list(map(int, input().split())) for i in range(Q)]
t =[0] * N
for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
def ans(l, r):
    return t[r-1] - t[l-1]
for l, r in qs:
    print(ans(l,r))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def cnt():
    n, q = map(int, input().split())
    s = input()
    qs = []
    for i in range(q):
        qs.append(list(map(int, input().split())))
    for l, r in qs:
        que = deque(maxlen = 2)
        cnt = 0
        for a in s[l-1: r]:
            que.append(a)
            if que == deque(['A', 'C']):
                cnt += 1
        print(cnt)
        
cnt()

Fixed submission:
N, Q = map(int, input().split())
S = input()
qs = [list(map(int, input().split())) for i in range(Q)]
t =[0] * N
for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
def ans(l, r):
    return t[r-1] - t[l-1]
for l, r in qs:
    print(ans(l,r))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def cnt():
    n, q = map(int, input().split())
    s = input()
    qs = []
    for i in range(q):
        qs.append(list(map(int, input().split())))
    for i in range(q):
        que = deque(maxlen = 2)
        cnt = 0
        l = qs[i][0]
        r = qs[i][1]
        for a in s[l-1: r]:
            que.append(a)
            if que == deque(['A', 'C']):
                cnt += 1
        print(cnt)
        
cnt()

Fixed submission:
N, Q = map(int, input().split())
S = input()
qs = [list(map(int, input().split())) for i in range(Q)]
t =[0] * N
for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
def ans(l, r):
    return t[r-1] - t[l-1]
for l, r in qs:
    print(ans(l,r))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
qs = []
n, q = map(int, input().split())
s = input()
for i in range(q):
    qs.append(list(map(int, input().split())))
for i in range(q):
    que = deque(maxlen = 2)
    cnt = 0
    l = qs[i][0]
    r = qs[i][1]
    for a in s[l-1: r]:
        que.append(a)
        if que == deque(['A', 'C']):
            cnt += 1
    print(cnt)
        

Fixed submission:
N, Q = map(int, input().split())
S = input()
qs = [list(map(int, input().split())) for i in range(Q)]
t =[0] * N
for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
def ans(l, r):
    return t[r-1] - t[l-1]
for l, r in qs:
    print(ans(l,r))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
shop = []
for i in range(n):
    shop.append(list(map(int, input().split())))
shop.sort()
for i in range(n):
    tot_b = 0
    for j in range(i+1):
        tot_b += shop[j][1]
    if tot_b >= m:
        break
if tot_b == m:
    cost = 0
    for k in range(i+1):
        cost += shop[k][0]*shop[k][1]
    print(cost)
if tot_b > m:
    cost = 0
    for k in range(i):
        cost+= shop[k][0]*shop[k][1]
    cost += shop[i][0]*(shop[i][1]+m-tot_b)
    print(cost)



Fixed submission:
n, m = map(int, input().split())
shop = []
for i in range(n):
    shop.append(list(map(int, input().split())))
shop.sort()
i = 0
tot_b = 0
while tot_b < m:
    tot_b += shop[i][1]
    i += 1
i -= 1
if tot_b == m:
    cost = 0
    for k in range(i+1):
        cost += shop[k][0]*shop[k][1]
    print(cost)
if tot_b > m:
    cost = 0
    for k in range(i):
        cost+= shop[k][0]*shop[k][1]
    cost += shop[i][0]*(shop[i][1]+m-tot_b)
    print(cost)
Buggy python submission (verdict: Runtime Error):
def f(n):
    if n+1 % 4 == 0:
        return 0
    if n+1 % 4 == 1:
        return n
    if n+1 % 4 == 2:
        return 1
    if n+1 % 4 == 3:
        return 1^n
a, b = map(int, input().split())
ans = f(a-1) ^ f(b)
print(ans)

Fixed submission:
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1):
    ans = ans ^ i
print(ans)

Fixed submission:
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) >0 else inf
    ret0 = dfs(cur+1, a,b,c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) +10
    ret3 = dfs(cur+1, a,b,c+l[cur]) +10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) >0 else inf
    ret0 = dfs(cur+1, a,b,c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) +10
    ret3 = dfs(cur+1, a,b,c+l[cur]) +10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) >0 else inf
    ret0 = dfs(cur+1, a,b,c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) +10
    ret3 = dfs(cur+1, a,b,c+l[cur]) +10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) >0 else inf
    ret0 = dfs(cur+1, a,b,c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) +10
    ret3 = dfs(cur+1, a,b,c+l[cur]) +10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Time Limit Exceeded):
N, K =map(int, input().split())
hs = [10**6]*K + list(map(int, input().split()))
dp = [0]*(N+K+1)
for i in range(K+1, N+K):
    ans = dp[i-1]+abs(hs[i]-hs[i-1])
    for k in range(2, K+1):
        ans = min(ans, dp[i-k]+abs(hs[i]-hs[i-k]))
    dp[i] = ans
print(dp[N+K-1])

Fixed submission:
N, K =map(int, input().split())
hs = [10**6]*K + list(map(int, input().split()))
dp = [0]*(N+K+1)
for i in range(K+1, N+K):
    ans = dp[i-1]+abs(hs[i]-hs[i-1])
    for k in range(2, K+1):
        ans = min(ans, dp[i-k]+abs(hs[i]-hs[i-k]))
    dp[i] = ans
print(dp[N+K-1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N , W = map(int, input().split())
item =[list(map(int, input().split())) for i in range(N)]
dp = [0] * (W+1)
dp2 = [0] * (W+1)
for i in range(N):
    w = item[i][0]
    v = item[i][1]
    for j in range(1, W+1):
        if j - w >= 0:
            dp2[j] = max(dp[j], dp[j-w] + v)
    dp = copy.copy(dp2)
print(dp[W])

Fixed submission:
import copy
N , W = map(int, input().split())
item =[list(map(int, input().split())) for i in range(N)]
dp = [0] * (W+1)
dp2 = [0] * (W+1)
for i in range(N):
    w = item[i][0]
    v = item[i][1]
    for j in range(1, W+1):
        if j - w >= 0:
            dp2[j] = max(dp[j], dp[j-w] + v)
    dp = copy.copy(dp2)
print(dp[W])
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def c():
    n, k = map(int, input().split())
    h = []
    for i in range(n):
        h.append(int(input()))
    h.sort()
    d = collections.deque(maxlen = k)
    mins = []
    while len(d) < k:
        d.append(h.pop())
    while h:
        mins.append(max(d) - min(d))
        d.append(h.pop())
    mins.append(max(d) - min(d))
    print(min(mins))
c()


Fixed submission:
import collections
def c():
    n, k = map(int, input().split())
    h = []
    for i in range(n):
        h.append(int(input()))
    h.sort()
    d = collections.deque(maxlen = k)
    mins = []
    while len(d) < k:
        d.append(h.pop())
    while h:
        mins.append(d[0] - d[k-1])
        d.append(h.pop())
    mins.append(d[0] - d[k-1])
    print(min(mins))
c()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
x = 0
for i in range(N, 10**9 + 1):
    if M % i == 0:
        x = M // i
        break
print(x)

Fixed submission:
N, M = map(int, input().split())
x = 0
m = 0
for i in range(10**5):
    if i**2 < M <= (i+1)**2:
        m = i+1
        break
if m >N:
    for i in range(N, m):
        if M % i == 0:
            x = M // i
            break
if x == 0:
    for i in reversed(range(1, M //N +1)):
        if M % i == 0:
            x = i
            break
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
x = 0
for i in range(N, 10**9 + 1):
    if M % i == 0:
        x = M // i
        break
print(x)

Fixed submission:
N, M = map(int, input().split())
x = 0
m = 0
for i in range(10**5):
    if i**2 < M <= (i+1)**2:
        m = i+1
        break
if m >N:
    for i in range(N, m):
        if M % i == 0:
            x = M // i
            break
if x == 0:
    for i in reversed(range(1, M //N +1)):
        if M % i == 0:
            x = i
            break
print(x)
Buggy python submission (verdict: Runtime Error):
N, M , X , Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
xs.append(X)
ys.append(Y)
if min(ys) <= max(xs) 
    print('War')
else:
    print('No War')

Fixed submission:
N, M , X , Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
xs.append(X)
ys.append(Y)
if min(ys) <= max(xs):
    print('War')
else:
    print('No War')
Buggy python submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
dif = []
for i in range(N):
    dif.append(xs[i+1] -xs[i])
if len(dif) > 1:
    ans = math.gcd(dif[0], dif[1])
    for i in range(N):
        ans = math.gcd(ans, dif[i])
    print(ans)
else:
    print(dif[0])

Fixed submission:
import fractions
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
dif = []
for i in range(N):
    dif.append(xs[i+1] -xs[i])
if len(dif) > 1:
    ans = fractions.gcd(dif[0], dif[1])
    for i in range(N):
        ans = fractions.gcd(ans, dif[i])
    print(ans)
else:
    print(dif[0])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    ans += b*b
print(ans)
        
    

Fixed submission:
N, K = map(int, input().split())
if K % 2 == 1:
    a = N // K
    print(a**3)
else:
    a = N//K
    a2 = N//(K//2) -a
    print(a**3 +a2**3)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    c = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    for j in range(kmin, k+1):
        if j*K -a > N:
            break
        c += 1
    ans += b*c
print(ans)
        

Fixed submission:
N, K = map(int, input().split())
if K % 2 == 1:
    a = N // K
    print(a**3)
else:
    a = N//K
    a2 = N//(K//2) -a
    print(a**3 +a2**3)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    c = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    for j in range(kmin, k+1):
        if j*K -a > N:
            break
        c += 1
    ans += b*c
print(ans)
        

Fixed submission:
N, K = map(int, input().split())
if K % 2 == 1:
    a = N // K
    print(a**3)
else:
    a = N//K
    a2 = N//(K//2) -a
    print(a**3 +a2**3)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
ans = 0
for i in range(1,N+1):
    if 2*i % K != 0:
        continue
    for j in range(1, N+1):
        if 2*j % K != 0:
            continue
        if (i+j)% K != 0:
            continue
        for k in range(1, N+1):
            if 2*k % K != 0:
                continue
            if (i+k) % K != 0:
                continue
            if (j+k) % K != 0:
                continue
            ans += 1
print(ans)
                

Fixed submission:
N, K = map(int, input().split())
if K % 2 == 1:
    a = N // K
    print(a**3)
else:
    a = N//K
    a2 = N//(K//2) -a
    print(a**3 +a2**3)
Buggy python submission (verdict: Time Limit Exceeded):
N, M ,Q = map(int, input().split())
train = [list(map(int, input().split())) for i in range(M)]
qs = [list(map(int, input().split())) for i in range(Q)]
ns = []
for i in range(N+1):
    ns.append([0]*(N+1))
for l, r in train:
    for i in range(r, N+1):
        ns[l][i] += 1
for p, q in qs:
    ans = 0
    for i in range(p, q+1):
        ans += ns[i][q]
    print(ans)



Fixed submission:
N, M ,Q = map(int, input().split())
train = [list(map(int, input().split())) for i in range(M)]
qs = [list(map(int, input().split())) for i in range(Q)]
ns = []
for i in range(N+1):
    ns.append([0]*(N+1))
for l, r in train:
    for i in range(r, N+1):
        ns[l][i] += 1
for p, q in qs:
    ans = 0
    for i in range(p, q+1):
        ans += ns[i][q]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
As = list(map(int, input().split()))
ans = 0
for l in range(N):
    tmp = 0
    for r in range(l, N):
        tmp += As[r]
        if tmp % M == 0:
            ans += 1
print(ans)

Fixed submission:
import collections
N, M = map(int, input().split())
As = list(map(int, input().split()))
b = [0]*N
b[0] = As[0]
ans = 0
for i in range(1,N):
    b[i] = b[i-1] + As[i]
bmod = [i % M for i in b]
for i in collections.Counter(bmod).values():
    if i >= 2:
        ans += i*(i-1) //2
for i in bmod:
    if i == 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
flag = True
if S[0] != 'A':
    flag = False
elif 'C' in S[2:len(S)-1]:
    s2 = S.replace('C', '', 1)
    if 'C' in s2:
        flag = False
if flag:
    s2 = s2.replace('A', '', 1)
    if s2.islower():
        flag = True
    else:
        flag = False
if flag:
    print('AC')
else:
    print('WA')



Fixed submission:
S = input()
flag = True
if S[0] != 'A':
    flag = False
elif 'C' not in S[2:len(S)-1]:
    flag = False
s2 = S.replace('C', '', 1)
if 'C' in s2:
    flag = False
    
if flag:
    s2 = s2.replace('A', '', 1)
    if s2.islower():
        flag = True
    else:
        flag = False
if flag:
    print('AC')
else:
    print('WA')
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, len(s)+1):
                ans.append(s[i:k])
                cnt += 1
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Fixed submission:
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt <= K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, len(s)+1):
                ans.append(s[i:k])
                cnt += 1
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Fixed submission:
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
ans = []
for i in range(len(s)):
    for k in range(i+1, len(s)+1):
        ans.append(s[i:k])
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Fixed submission:
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())
ans = []
for i in range(len(s)):
    for k in range(i+1, len(s)):
        ans.append(s[i:k])
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])
        

Fixed submission:
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S =['.']*(W+2)+ ['.'+input()+'.' for i in range(H)]+['.']*(W+2)
flag = True
for i in range(1, H+1):
    for k in range(1, W+1):
        if S[i][k] == '#':
            if S[i-1][k] == '.' and S[i+1][k] == '.' and S[i][k+1] == '.' and S[i][k-1] == '.':
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Fixed submission:
H, W = map(int, input().split())
S =['.'*(W+2)]+ ['.'+input()+'.' for i in range(H)]+['.'*(W+2)]
flag = True
for i in range(1, H+1):
    for k in range(1, W+1):
        if S[i][k] == '#':
            if S[i-1][k] == '.' and S[i+1][k] == '.' and S[i][k+1] == '.' and S[i][k-1] == '.':
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import collections
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = collections.defaultdict(int)
ans = -1
if len(S) <= 25:
    for i in S:
        dic[i] += 1
    for i in alp:
        if dic[i] == 0:
            ans = S + i
            break
else:
    dic2 = {}
    dic3 = {}
    lst = []
    tmp = 0
    for i, j in zip(alp, range(1, 27)):
        dic2[i] = j
        dic3[j] = i
    for i in range(1, 27):
        a = S[-i]
        idx = dic2[a]
        if idx < tmp:
            lst.sort()
            for j in lst:
                if j > idx:
                    ans = S[:-i] + dic3[j]
                    flag = True
                    break
        
        else:
            tmp = idx
            lst.append(idx)
        if flag:
            break


print(ans)

Fixed submission:
import collections
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = collections.defaultdict(int)
ans = -1
if len(S) <= 25:
    for i in S:
        dic[i] += 1
    for i in alp:
        if dic[i] == 0:
            ans = S + i
            break
else:
    dic2 = {}
    dic3 = {}
    lst = []
    tmp = 0
    flag = False
    for i, j in zip(alp, range(1, 27)):
        dic2[i] = j
        dic3[j] = i
    for i in range(1, 27):
        a2 = S[-i]
        idx = dic2[a2]
        if idx < tmp:
            lst.sort()
            for j in lst:
                if j > idx:
                    ans = S[:-i] + dic3[j]
                    flag = True
                    break
        
        else:
            tmp = idx
            lst.append(idx)
        if flag:
            break

print(ans)