Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse = True)

if k > n:
    print(0)
else:
    for i in range(k):
        h.pop(i)
        
    print(sum(h))

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))

if k >= n:
    print(0)
else:
    h.sort()
    ans = 0
    for i in range(n - k):
        ans += h[i]
        
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())

dp = [float("inf") for _ in range(h+1)]
dp[0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])


Fixed submission:
h, n = map(int, input().split())

dp = [float("inf") for _ in range(h+1)]
dp[0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = input()
m = int(n)

ans = 0
for i in range(m):
    for j in range(m):
        s = str(i + 1)
        t = str(j + 1)
        if s[0] == t[-1] and s[-1] == t[0]:
            ans += 1
            
            
print(ans)


Fixed submission:
n = int(input())

d = [10 * [0] for _ in range(10)]

ans = 0
for i in range(1, n+1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0": continue
    d[int(s[0])][int(s[-1])] += 1

for i in range(1, 10):
    for j in range(1, 10):
        ans += d[i][j] * d[j][i]
                  
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
PS = {}

for i in range(m):
    res = input()
    res_list = list(res.split())
    if res not in PS:
        PS[res] = 0
        PS[res] += 1
    elif res_list[1] == "WA" and PS[res_list[0]+ " AC"] >= 1:
        pass
    elif res_list[1] == "AC" and PS[res_list[0]+ " AC"] >= 1:
        pass
    else:
        PS[res] += 1


ans = 0
pn = 0
for k, v in PS.items():
    if k[-2:] == "AC":
        ans += 1
    elif k[-2:] == "WA":
        pn += 1

print(ans, pn)


Fixed submission:
n, m = map(int, input().split())
PN = 0
AC_list = [0 for i in range(n)] 
WA_list = [0 for i in range(n)] 

for i in range(m):
    p, s = input().split()
    p = int(p)

    if s == "AC" and AC_list[p-1] == 0:
        PN += WA_list[p-1]
        AC_list[p-1] = 1
    
    else:
        WA_list[p-1] += 1


print(AC_list.count(1), PN)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(input().split(),np.int64)
MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    c = np.count_nonzero((A>>i)&1)
    ans += (2 ** i) * c * (N - c)

print(ans%MOD)

Fixed submission:
import numpy as np

N = int(input())
A = np.array(input().split(),np.int64)
MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    c = np.count_nonzero((A>>i)&1)
    ans += (2 ** i) * c * (N - c)

print(ans%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
s = input()
 
ans = set()
 
for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            ans.add(s[i] + s[j] + s[l])

print(len(ans))

Fixed submission:
n = int(input())
s = input()

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
s = input()

d = {}

for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            r = ""
            r = s[i] + s[j] + s[l]
            if r not in d:
                d[r] = 0
            d[r] += 1

print(len(d))

Fixed submission:
n = int(input())
s = input()

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

d = {}
for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            r = s[i] + s[j] + s[l]
            if r not in d:
                d[r] = 0
            d[r] += 1

print(len(d))

Fixed submission:
n = int(input())
s = input()

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
d = list(map(int, input().split()))

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

c = sorted(c.items(), key=lambda x:x[0])

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    ans %= 998244353
    if ans == 0:
        jug = False
    
if jug == False:
    print(0)
else:
    print(ans)

Fixed submission:
n = int(input())

if n % 2 == 0:
  ans = n / 2 - 1
else:
  ans = n / 2
  
print(int(ans))
Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
d = list(map(int, input().split()))

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

c = sorted(c.items(), key=lambda x:x[0])

ans = 1

if c[0][0] != 0:
    jug = False
else:
    for i in range(max(d)):
        if c[i][0] < 0:
            jug == False
        else:
            m = c[i][1]
            r = c[i+1][1]
            ans *= m ** r
            ans %= 998244353
            if ans == 0:
                jug = False
  
if jug == False:
    print(0)
else:
    print(ans)

Fixed submission:
import collections

n = int(input())
d = list(map(int, input().split()))

c = collections.Counter(d)

ans = 1

if c[0] != 1 or d[0] !=0:
    ans = 0

for i in range(max(d) + 1):
    if i == 0:
        continue
    ans *= c[i-1] ** c[i]

print(ans%998244353)
Buggy python submission (verdict: Runtime Error):
def sum_triangle(x):
    if x > 0:
        return x + sum_triangle(x - 1)
    else:
        return 0
    

s = input().replace("><", "> <")
new_s = s.split(" ")

a = [0] * len(new_s)

for i in range(len(new_s)):
    if new_s[i].count("<") >= new_s[i].count(">"):
        a[i] = sum_triangle(new_s[i].count("<"))
        a[i] += sum_triangle(new_s[i].count(">") - 1)
    else:
        a[i] = sum_triangle(new_s[i].count(">"))
        a[i] += sum_triangle(new_s[i].count("<") - 1)

print(sum(a))

Fixed submission:
def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

s = input().replace("><", "> <")
new_s = s.split(" ")

a = [0] * len(new_s)

for i in range(len(new_s)):
    if new_s[i].count("<") >= new_s[i].count(">"):
        a[i] = gauss(new_s[i].count("<"))
        a[i] += gauss(new_s[i].count(">") - 1)
    else:
        a[i] = gauss(new_s[i].count(">"))
        a[i] += gauss(new_s[i].count("<") - 1)

print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))
 
d.sort()

ans = 0
 
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if i == j or j == k or i == k:
                continue
            elif d[i] + d[j] <= d[k]:
                break
            else:
                ans += 1
print(ans)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
 
d.sort()

ans = 0

for b in range(n):
    for a in range(b):
        ab = d[a] + d[b]
        r = bisect.bisect_left(d, ab)
        l = b+1
        ans += max(0, r-l)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = list(map(int, input().split()))

b = [0] * n
for i in range(n):
    b[i] = i + 1

d = dict(zip(a, b))

d_sorted = sorted(d.items(), key=lambda x:x[0])
ans = ""
for i in range(n):
    ans += str(d_sorted[i][1]) + " "

print(ans)

Fixed submission:
n = int(input())

a = list(map(int, input().split()))

ans = [0] * n
for i in range(n):
    ans[a[i]-1] = i+1

for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math

a, b = map(int, input().split())

l = max(a, b)
s = min(a, b)

if s == 1:
    print(1)
else:
    while l % s > 0:
        n = s 
        s = l % s
        l = n
    
    a = [i for i in range(2, s+1) ]
    p =[]

    while True:
        prime = min(a)

        if prime > math.sqrt(s):
            break

        p.append(prime)

        i = 0
        while i < len(a):
            if a[i] % prime == 0:
                a.pop(i)
                continue
            i += 1

    for i in a:
        p.append(i)

    ans = 1
    for i in range(len(p)):
        if s % p[i] == 0:
            ans += 1

    print(ans)

Fixed submission:
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x%y)

def factorize(n):
    i = 2
    factors = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            factors.append(i)
        i += 1
    if n > 1:
        factors.append(n)
    return factors


a, b = map(int, input().split())

g = gcd(a, b)
ans = set(factorize(g))

print(len(ans)+1)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
INF = 1001001001
key = []

for i in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    s = 0
    for j in range(b):
        c[j] -= 1
        s |= 1 << c[j]
    key.append([s, a])

dp = [INF] * (1<<N)
dp[0] = 0
for s in range(1<<N):
    for i in range(M):
        print(dp)
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)
ans = dp[-1]
print(ans)

Fixed submission:
N, M = map(int, input().split())
INF = 1001001001
key = []

for i in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    s = 0
    for j in range(b):
        c[j] -= 1
        s |= 1 << c[j]
    key.append([s, a])

dp = [INF] * (1<<N)
dp[0] = 0
for s in range(1<<N):
    for i in range(M):
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)

if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
m = list(range(1, n+1))

print(sum(m)-m[-1])

Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)] 
 
graph = [[] for _ in range(N+1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p, x in PX:
    value[p] +=x
 
def dfs(v, parent, add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x, v, value[v])
 
dfs(1, 0, 0)
ans = ' '.join(map(str,value[1:]))
print(ans)

Fixed submission:
n = int(input())
s = input()

if n >= 3200:
    print(s)
else:
    print("red")

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)] 
 
graph = [[] for _ in range(N+1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p, x in PX:
    value[p] +=x
 
def dfs(v, parent, add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x, v, value[v])
 
dfs(1, 0, 0)
ans = ' '.join(map(str,value[1:]))
print(ans)

Fixed submission:
n = int(input())
s = input()

if n >= 3200:
    print(s)
else:
    print("red")
Buggy python submission (verdict: Runtime Error):
n =int(input())
a = list()
 
for _ in range(n):
    a.append(int(input()))
 
b = sorted(a)
 
for i in range(n):
    if a[i] == max(a):
        print(b[-2]) 
    else:
        print(max(a))

Fixed submission:
r = int(input())

print(3 * r ** 2)
Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
a = list()
 
for _ in range(n):
    a.append(int(input()))
 
b = sorted(a)
 
for i in range(n):
    if a[i] == max(a):
        print(b[-2]) 
    else:
        print(max(a))

Fixed submission:
n =int(input())
a = list()
 
for _ in range(n):
    a.append(int(input()))
 
b = sorted(a)

 
for i in range(n):
    if a[i] == b[-1]:
        print(b[-2]) 
    else:
        print(b[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
a = list()

for _ in range(n):
    a.append(int(input()))

b = sorted(a)

for i in range(n):
    if a[i] == max(a):
        print(b[-2]) 
    else:
        print(max(a))


Fixed submission:
n =int(input())
a = list()
 
for _ in range(n):
    a.append(int(input()))
 
b = sorted(a)

 
for i in range(n):
    if a[i] == b[-1]:
        print(b[-2]) 
    else:
        print(b[-1])
Buggy python submission (verdict: Runtime Error):
import sympy
n, d = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]


ans = 0
for i in range(n):
    for j in range(i+1, n):
        l = 0
        for k in range(d):
            l += (a[i][k] - a[j][k]) ** 2
        l = sympy.sqrt(l)
        if l.is_Integer: ans += 1

print(ans)


Fixed submission:
n, d = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]


ans = 0
for i in range(n):
    for j in range(i+1, n):
        l = 0
        for k in range(d):
            l += (a[i][k] - a[j][k]) ** 2
        if (l ** .5).is_integer(): ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
MOD = 2019

A = set()

for i in range(L, R):
    for j in range(i+1, R+1):
        A.add(i*j % MOD)
        if i * j % MOD == 0:
            break

print(min(A))


Fixed submission:
L, R = map(int, input().split())
MOD = 2019

ans = 0

if R - L >= 2019:
    pass
else:
    A = set()

    for i in range(L, R):
        for j in range(i+1, R+1):
            A.add(i*j % MOD)
            if i * j % MOD == 0:
                break

    ans = min(A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
MOD = 2019

A = set()

for i in range(L, R):
    for j in range(i+1, R+1):
        A.add(i*j % MOD)
        if i * j % MOD == 0:
            break

print(min(A))


Fixed submission:
L, R = map(int, input().split())
MOD = 2019

ans = 0

if R - L >= 2019:
    pass
else:
    A = set()

    for i in range(L, R):
        for j in range(i+1, R+1):
            A.add(i*j % MOD)
            if i * j % MOD == 0:
                break

    ans = min(A)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n):
	if p[i-1] < p[i] and p[i] < p[i+1]:
		ans += 1
		
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
	if p[i-1] < p[i] and p[i] < p[i+1]:
		ans += 1
	elif p[i-1] > p[i] and p[i] > p[i+1]:
		ans += 1
	
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N//R + 1):
    for j in range(N//G + 1):
        V = i * R + j * G
        if N >= V and (N - V) % B == 0:
            ans += 1

print(ans)

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N//R + 1):
    for j in range(N//G + 1):
        V = i * R + j * G
        if N >= V and (N - V) % B == 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = {}

for _ in range(N):
    a, b = map(int, input().split())
    AB.setdefault(a, b)

AB = sorted(AB.items(), key=lambda x:x[0])

sum = 0
ans = 0
for i in range(N):
    sum += AB[i][1]
    ans += AB[i][1] * AB[i][0]
    if sum > M:
        ans -= (sum - M) * AB[i][0]
        break

print(ans)

Fixed submission:
N, M = map(int, input().split())
AB = []

for _ in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB = sorted(AB)


sum = 0
ans = 0
for i in range(N):
    sum += AB[i][1]
    ans += AB[i][1] * AB[i][0]
    if sum >= M:
        ans -= (sum - M) * AB[i][0]
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A = list(input())
N = len(A)

ans = 0

flg = True
while flg:
    flg = False
    for i in range(N-1):
        if A[i] != A[i+1]:
            ans += 2
            N -= 2
            flg = True
            for j in range(i, N):
                A[j] = A[j+2] 
            break

print(ans)


Fixed submission:
A = list(input())
N = len(A)

C0 = A.count("0")
C1 = A.count("1")

print(2 * min(C0, C1))
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

b = []

for i in range(len(s)):
    c1 = s[i]
    c2 = t[i]
    if c1 == c2:
        for i in range(len(b)):
            if b[j][0] == c1:
                print("No")
                exit()
    if c1 != c2:
        for j in range(len(b)):
            if b[j][0] == c1 and b[j][1] != c2:
                print("No")
                exit()
            if b[j][0] != c1 and b[j][1] == c2:
                print("No")
                exit()
            if b[j][0] == c1 and b[j][1] == c2:
                break
        else:
            b.append([c1, c2])
else:
    print("Yes")


Fixed submission:
S = input()
T = input()

converter = dict()

for s, t in zip(S, T):
    if converter.get(s) is not None:
        if converter[s] != t:
            print("No")
            break
    else:
        converter[s] = t
else:
    if len(converter.values()) != len(set(converter.values())):
        print("No")
    else:
        print("Yes")

Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

b = []

for i in range(len(s)):
    c1 = s[i]
    c2 = t[i]
    if c1 == c2:
        if b[j][0] == c1:
            print("No")
            exit()
    if c1 != c2:
        for j in range(len(b)):
            if b[j][0] == c1 and b[j][1] != c2:
                print("No")
                exit()
            if b[j][0] != c1 and b[j][1] == c2:
                print("No")
                exit()
            if b[j][0] == c1 and b[j][1] == c2:
                break
        b.append([c1, c2])
else:
    print("Yes")


Fixed submission:
S = input()
T = input()

converter = dict()

for s, t in zip(S, T):
    if converter.get(s) is not None:
        if converter[s] != t:
            print("No")
            break
    else:
        converter[s] = t
else:
    if len(converter.values()) != len(set(converter.values())):
        print("No")
    else:
        print("Yes")

Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

a = [chr(i + ord("a")) for i in range(26)]
b = []

for i in range(len(s)):
    if s[i] != t[i]:
        c1 = s[i]
        c2 = t[i]
        if c2 not in a:
            for j in range(len(b)):
                if b[j][1] == c2 and b[j][0] != c1:
                    print("No")
                    exit()
        a.remove(c2)
        b.append([c1, c2])
else:
    print("Yes")

Fixed submission:
S = input()
T = input()

converter = dict()

for s, t in zip(S, T):
    if converter.get(s) is not None:
        if converter[s] != t:
            print("No")
            break
    else:
        converter[s] = t
else:
    if len(converter.values()) != len(set(converter.values())):
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
INF = 5 * 10 ** 16

if S[0] == "1":
    if K <= int(S[1]) * 5 * 10 ** 15 + 1:
        print(S[1])
    else:
        print(S[2])
else:
    if K <= int(S[0]) * 5 * 10 ** 15:
        print(S[0])
    else:
        print(S[1])

Fixed submission:
S = input()
K = int(input())

ans = "1"
for i in range(K):
    if S[i] != "1":
        ans = S[i]
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
INF = 5 * 10 ** 16

if S[0] == "1":
    if K <= int(S[1]) * 5 * 10 ** 16 + 1:
        print(S[1])
    else:
        print(S[2])
else:
    if K <= int(S[0]) * 5 * 10 ** 16 + 1:
        print(S[0])
    else:
        print(S[1])

Fixed submission:
S = input()
K = int(input())

ans = "1"
for i in range(K):
    if S[i] != "1":
        ans = S[i]
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
N,X = map(int, input().split())
M = []
S = 0
mini = X
for i in range(N):
    M.append(int(input()))
    S += M[i]
    if mini > M[i]:
        mini = M[i]

ans = 0
ans = N + int((X - S) / mini)

print(ans)

Fixed submission:
S = input()

price = 700

if S[0] == "o": price += 100
if S[1] == "o": price += 100
if S[2] == "o": price += 100

print(price)
Buggy python submission (verdict: Runtime Error):
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Fixed submission:
s = input()

if len(s) < 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Buggy python submission (verdict: Runtime Error):
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans) 


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Fixed submission:
s = input()

if len(s) < 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

b = [0] + a + [0]
c = []
for i in range(n+1):
    c.append(abs(b[i] - b[i+1]))

for i in range(n):
    ans = l - c[i] - c[i+1]
    ans += abs(b[i] - b[i+2])
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = [0] + a + [0]
c = []
for i in range(n+1):
    c.append(abs(b[i] - b[i+1]))

l = sum(c)

for i in range(n):
    ans = l - c[i] - c[i+1]
    ans += abs(b[i] - b[i+2])
    print(ans)