Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(0, len(X)):
    sum = 0
    for j in range(0, len(X[i])):
        if i >= (len(X)-1):
            sum += X[i][j] - X[0][j]
        else:
            sum += (X[i][j] - X[i+1][j])**2

    if math.sqrt(sum).is_integer():
        cnt += 1
print(cnt)


Fixed submission:
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        sum = 0
        for k in range(D):
            sum += (X[i][k] - X[j][k])**2
        if math.sqrt(sum).is_integer():
            cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(0, len(X)):
    sum = 0
    for j in range(0, len(X[i])):
        if i >= len(X[i]):
            sum += X[i][j] - X[0][j]
        else:
            sum += (X[i][j] - X[i+1][j])**2

    if math.sqrt(sum).is_integer():
        cnt += 1
print(cnt)


Fixed submission:
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        sum = 0
        for k in range(D):
            sum += (X[i][k] - X[j][k])**2
        if math.sqrt(sum).is_integer():
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())

lcm = (C*D)//math.gcd(C, D)

a = ((A-1)//C+(A-1)//D)-(A-1)//lcm
b = (B//C+B//D)-B//lcm

print((B-A+1)-(b-a))


Fixed submission:
import fractions

A, B, C, D = map(int, input().split())

lcm = (C*D)//fractions.gcd(C, D)

a = ((A-1)//C+(A-1)//D)-(A-1)//lcm
b = (B//C+B//D)-B//lcm

print((B-A+1)-(b-a))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1

for i in range(2, N+1):
    # 壊れた床がなく単純に求める場合
    #dp[i] = dp[i-1]+dp[i-2]

    if not i-1 in a:
        dp[i] += dp[i-1]
    if not i-2 in a:
        dp[i] += dp[i-2]

print(dp[N] % 1000000007)


Fixed submission:
N, M = map(int, input().split())
A = {}
for _ in range(M):
    a = int(input())
    A[a] = True

dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1

for i in range(2, N+1):
    # 壊れた床がなく単純に求める場合
    #dp[i] = dp[i-1]+dp[i-2]

    if not i-1 in A:
        dp[i] += dp[i-1]
    if not i-2 in A:
        dp[i] += dp[i-2]

print(dp[N] % 1000000007)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))


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

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if index >= n:
            break
        elif A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))


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

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if index >= n:
            break
        elif A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for r in range(3001):
    for g in range(3001):
        if (R*r+G*g) > N:
            break

        if (N-(R*r+G*g)) % B == 0 or R*r+G*g == N:
            ans += 1
print(ans)


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

ans = 0
for r in range(3001):
    for g in range(3001):
        tmp = (R*r+G*g)
        if tmp > N:
            break

        if (N-tmp) % B == 0 or tmp == N:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

max_gcd = 0
for i in range(len(li)):
    if li[i] <= max_gcd:
        continue
    tmp = li[i]
    del li[i]
    tmp_gcd = gcd(*li)
    if max_gcd < tmp_gcd:
        max_gcd = tmp_gcd
    li.insert(0,tmp)

print(max_gcd)

Fixed submission:
from fractions import gcd

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

# 入力が2つなら最大値が解となる
if n == 2:
    print(max(A))
    exit()

# A1 A2 A3の最大公約数はA1とA2の最大公約数とA3の最大公約数と同値になるので、
# 左右から順番に最大公約数を求めていく。
# 初期値を代入する（右からは0番目にAの最初の要素を、左からは末尾にAの末尾の要素）
gcdL = [0]*n
gcdR = [0]*n
gcdL[0] = A[0]
gcdR[-1] = A[-1]

for i in range(1, n):
    gcdL[i] = gcd(gcdL[i-1], A[i])
    gcdR[-i-1] = gcd(gcdR[-i], A[-i-1])

# A0～AiとAi+1～Anの最大公約数を求めていく
# 最大値が解となる
ans = gcdR[1]
for i in range(1, n-1):
    tmp = gcd(gcdL[i-1], gcdR[i+1])
    ans = max(ans, tmp)
ans = max(ans, gcdL[-2])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

max_gcd = 0
for i in range(len(li)):
    tmp = li[i]
    del li[i]
    tmp_gcd = gcd(*li)
    if max_gcd < tmp_gcd:
        max_gcd = tmp_gcd
    li.insert(0,tmp)

print(max_gcd)

Fixed submission:
from fractions import gcd

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

# 入力が2つなら最大値が解となる
if n == 2:
    print(max(A))
    exit()

# A1 A2 A3の最大公約数はA1とA2の最大公約数とA3の最大公約数と同値になるので、
# 左右から順番に最大公約数を求めていく。
# 初期値を代入する（右からは0番目にAの最初の要素を、左からは末尾にAの末尾の要素）
gcdL = [0]*n
gcdR = [0]*n
gcdL[0] = A[0]
gcdR[-1] = A[-1]

for i in range(1, n):
    gcdL[i] = gcd(gcdL[i-1], A[i])
    gcdR[-i-1] = gcd(gcdR[-i], A[-i-1])

# A0～AiとAi+1～Anの最大公約数を求めていく
# 最大値が解となる
ans = gcdR[1]
for i in range(1, n-1):
    tmp = gcd(gcdL[i-1], gcdR[i+1])
    ans = max(ans, tmp)
ans = max(ans, gcdL[-2])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

max_gcd = 0
max_gcd_index = -1
for i in range(len(li)):
    tmp = li[:]
    del tmp[i]
    if max_gcd < gcd(*tmp):
        max_gcd = gcd(*tmp)
        max_gcd_index = i

print(max_gcd)

Fixed submission:
from fractions import gcd

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

# 入力が2つなら最大値が解となる
if n == 2:
    print(max(A))
    exit()

# A1 A2 A3の最大公約数はA1とA2の最大公約数とA3の最大公約数と同値になるので、
# 左右から順番に最大公約数を求めていく。
# 初期値を代入する（右からは0番目にAの最初の要素を、左からは末尾にAの末尾の要素）
gcdL = [0]*n
gcdR = [0]*n
gcdL[0] = A[0]
gcdR[-1] = A[-1]

for i in range(1, n):
    gcdL[i] = gcd(gcdL[i-1], A[i])
    gcdR[-i-1] = gcd(gcdR[-i], A[-i-1])

# A0～AiとAi+1～Anの最大公約数を求めていく
# 最大値が解となる
ans = gcdR[1]
for i in range(1, n-1):
    tmp = gcd(gcdL[i-1], gcdR[i+1])
    ans = max(ans, tmp)
ans = max(ans, gcdL[-2])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

csum = [0]
rcsum = [0]
for i in range(n):
    csum.append(s[i:n].count('AC'))
    #rcsum.append(s[n-i:n].count('AC'))


# print(csum)
# print(rcsum)

for _ in range(q):
    l, r = map(int, input().split())
    print(csum[l]-csum[r])
    #print('回答：', csum[l], rcsum[n-r])


Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l, r in lr:
    print(t[r]-t[l])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

csum = [0]
rcsum = [0]
for i in range(n):
    csum.append(s[i:n].count('AC'))
    rcsum.append(s[n-i:n].count('AC'))


# print(csum)
# print(rcsum)

for _ in range(q):
    l, r = map(int, input().split())
    print(csum[l]-csum[r])
    #print('回答：', csum[l], rcsum[n-r])


Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l, r in lr:
    print(t[r]-t[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = []
for _ in range(0, Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for tmp_lr in lr:
    print(S[tmp_lr[0]-1:tmp_lr[1]].count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l, r in lr:
    print(t[r]-t[l])
Buggy python submission (verdict: Runtime Error):
import math

a, b, k = map(int, input().split())
gcd = math.gcd(a, b)
divisor_list = []

if gcd == 1:
    divisor_list = [1]
else:
    divisor_list.append(1)
    for i in range(2, gcd // 2 + 1):
        if gcd % i == 0:
            divisor_list.append(i)
    divisor_list.append(gcd)

print(divisor_list[len(divisor_list)-1-k+1])


Fixed submission:
import fractions

a, b, k = map(int, input().split())
gcd = fractions.gcd(a, b)
divisor_list = []

if gcd == 1:
    divisor_list = [1]
else:
    divisor_list.append(1)
    for i in range(2, gcd // 2 + 1):
        if gcd % i == 0:
            divisor_list.append(i)
    divisor_list.append(gcd)

print(divisor_list[len(divisor_list)-1-k+1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

ans = 0

while True:
    if s.count('01') != 0:
        ans += s.count('01')*2
        s=s.replace('01', '')
    elif s.count('10') != 0:
        ans += s.count('10')*2
        s=s.replace('10', '')
    else:
        break

print(ans)


Fixed submission:
S = input()
print(min(S.count("0"),S.count("1"))*2)

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

ans = 0
i = 0
while i <= len(s)-2:
    if s[i] == '0' and s[i+1] == '1':
        del s[i+1]
        del s[i]
        ans += 2
        i = 0
    elif s[i] == '1' and s[i+1] == '0':
        del s[i+1]
        del s[i]
        ans += 2
        i = 0
    else:
        i += 1
print(ans)


Fixed submission:
S = input()
print(min(S.count("0"),S.count("1"))*2)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
while True:
    if S.count("01") == 0 and S.count("10") == 0:
        break

    if S.count("01") > 0:
        ans += S.count("01")*2
        S = S.replace("01", "")

    if S.count("10") > 0:
        ans += S.count("10")*2
        S = S.replace("10", "")

print(ans)


Fixed submission:
S = input()
print(min(S.count("0"),S.count("1"))*2)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = math.gcd(ans, A[i])
print(ans)


Fixed submission:
import fractions

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


N, K = map(int, input().split())
H = [0]*N
for i in range(N):
    H[i] = int(input())

H.sort()
ans = 10**10
for i in range(N-(K-1)):
    ans = min(ans, max(H[i], H[i+1], H[i+2])-min(H[i], H[i+1], H[i+2]))
print(ans)


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

hl = []
for _ in range(n):
    hl.append(int(input()))

hl.sort()

ans = 10**9+1
for i in range(len(hl)-k+1):
    ans = min(ans, hl[i+k-1]-hl[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

tree = []
for _ in range(n):
    tree.append(int(input()))

tree.sort()
ans = 10**9
for i in range(n-k+1):
    ans = min(ans, max(tree[i:i+k])-min(tree[i:i+k]))
print(ans)


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

hl = []
for _ in range(n):
    hl.append(int(input()))

hl.sort()

ans = 10**9+1
for i in range(len(hl)-k+1):
    ans = min(ans, hl[i+k-1]-hl[i])

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

N, M = map(int, input().split())
S = input()
T = input()

# 最小公倍数を求める
l = (N * M) // math.gcd(N, M)

ans = {1: S[0]}
for i in range(1, N):
    c_num = i*l//N+1
    ans[c_num] = S[i]

for i in range(M):
    if i == 1:
        if ans[1] != T[0]:
            print(-1)
            exit(0)

    c_num = i*l//M+1
    if c_num in ans:
        if ans[c_num] != T[i]:
            print(-1)
            exit(0)
    else:
        ans[c_num] = T[i]
print(l)


Fixed submission:
import fractions

N, M = map(int, input().split())
S = input()
T = input()

# 最小公倍数を求める
l = (N * M) // fractions.gcd(N, M)

ans = {1: S[0]}
for i in range(1, N):
    c_num = i*l//N+1
    ans[c_num] = S[i]

for i in range(M):
    if i == 1:
        if ans[1] != T[0]:
            print(-1)
            exit(0)

    c_num = i*l//M+1
    if c_num in ans:
        if ans[c_num] != T[i]:
            print(-1)
            exit(0)
    else:
        ans[c_num] = T[i]
print(l)
Buggy python submission (verdict: Runtime Error):
N = int(input())
W = []
for i in range(N):
    tmp = input()
    if tmp in W and i != 0:
        print("No")
        exit()
    W.append(tmp)

last_word = W[0][-1]
for i in range(1, len(N)):
    if last_word != W[i][0]:
        print("No")
        exit()
print("Yes")


Fixed submission:
N = int(input())
W = []
ans = True
for i in range(N):
    tmp = input()
    if tmp in W and i != 0:
        ans = False
    W.append(tmp)

if ans:
    last_word = W[0][-1]
    for i in range(1, N):
        if last_word != W[i][0]:
            ans = False
        last_word = W[i][-1]

print("Yes" if ans else "No")
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N, X = map(int, input().split())
xl = list(map(int, input().split()))

if N == 1:
    print(abs(X-xl[0]))
    exit(0)

xl.append(X)
xl.sort()

k = []
for i in range(1, N):
    tmp = xl[i]-xl[i-1]
    if not(tmp in k):
        k.append(tmp)

if len(k) <= 1:
    print(k[0])
else:
    print(gcd_list(k))


Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


N, X = map(int, input().split())
xl = list(map(int, input().split()))

if N == 1:
    print(abs(X-xl[0]))
    exit(0)

xl.append(X)
xl.sort()

k = []
for i in range(1, N+1):
    tmp = xl[i]-xl[i-1]
    if not(tmp in k):
        k.append(tmp)

if len(k) == 1:
    print(k[0])
elif len(k) == 2:
    ans = gcd(k[0], k[1])
    print(ans)
else:
    ans = gcd(k[0], k[1])
    for i in range(2, len(k)):
        ans = gcd(ans, k[i])
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
cumlr = [[0] * n for i in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    cumlr[l-1][r-1] += 1

for i in range(n):
    for j in reversed(range(1, n)):
        cumlr[i][j-1] += cumlr[i][j]
for i in range(n):
    for j in range(n-1):
        cumlr[j+1][i] += cumlr[j][i]

for _ in range(q):
    l, r = map(int, input().split())
    print(cumlr[r-1][q-1])

Fixed submission:
n, m, Q = map(int, input().split())
M = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    M[r-1][l-1] += 1

for q in range(n):
    for p in reversed(range(1, n)):
        M[q][p-1] += M[q][p]
for p in range(n):
    for q in range(n-1):
        M[q+1][p] += M[q][p]

for i in range(Q):
    p, q = map(int, input().split())
    print(M[q-1][p-1])

Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())

cumlr = [[0] * n for i in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    cumlr[l-1][r-1] += 1

for i in range(n):
    for j in reversed(range(1, n)):
        cumlr[i][j-1] += cumlr[i][j]

for i in range(n):
    for j in range(n-1):
        cumlr[j+1][i] += cumlr[j][i]


for _ in range(q):
    l, r = map(int, input().split())
    print(cumlr[r-1][q-1])

Fixed submission:
n, m, Q = map(int, input().split())
M = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    M[r-1][l-1] += 1

for q in range(n):
    for p in reversed(range(1, n)):
        M[q][p-1] += M[q][p]
for p in range(n):
    for q in range(n-1):
        M[q+1][p] += M[q][p]

for i in range(Q):
    p, q = map(int, input().split())
    print(M[q-1][p-1])

Buggy python submission (verdict: Runtime Error):
2 3 1
1 1
1 2
2 2
1 2

Fixed submission:
n, m, Q = map(int, input().split())
M = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    M[r-1][l-1] += 1

for q in range(n):
    for p in reversed(range(1, n)):
        M[q][p-1] += M[q][p]
for p in range(n):
    for q in range(n-1):
        M[q+1][p] += M[q][p]

for i in range(Q):
    p, q = map(int, input().split())
    print(M[q-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())

cumlr = [[0] * n for i in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    cumlr[l-1][r-1] += 1

# print(cumlr)
for _ in range(q):
    l, r = map(int, input().split())
    ans = 0
    for i in range(l-1, r):
        for j in range(l-1, r):
            ans += cumlr[i][j]
    print(ans)


Fixed submission:
n, m, Q = map(int, input().split())
M = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    M[r-1][l-1] += 1

for q in range(n):
    for p in reversed(range(1, n)):
        M[q][p-1] += M[q][p]
for p in range(n):
    for q in range(n-1):
        M[q+1][p] += M[q][p]

for i in range(Q):
    p, q = map(int, input().split())
    print(M[q-1][p-1])
Buggy python submission (verdict: Runtime Error):
n = input().split()
if n[0] == 1 and sum(n):
    print(10)
else:
    print(sum(n))


Fixed submission:
n = int(input())
if n%10==0:
    print(10)
    exit(0)
ans = pow(10,10)
for a in range(n+1):
    b = n-a
    tmp_ans = 0

    for sa in str(a):
        tmp_ans += int(sa)

    for sb in str(b):
        tmp_ans += int(sb)

    ans = min(ans, tmp_ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
l = [i for i in range(a, b+1)]

ans = []
for i in l[:k]:
    ans.append(i)

for i in l[len(l)-k:]:
    if not(i in ans):
        ans.append(i)

for i in ans:
    print(i)


Fixed submission:
a, b, k = map(int, input().split())

ans = []
for i in range(a, a+k):
    if i > b:
        break
    ans.append(i)

for i in range(b-k+1, b+1):
    if i < a:
        break
    if not(i in ans):
        ans.append(i)

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
S = list(input())
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if alp.index(S[i]) > alp.index(S[i+1]):
        #S[i] = S[i+1]
        print(''.join(S[:i-1])+alp[i])
        exit(0)


Fixed submission:
import string

S = input()
abc = string.ascii_lowercase

if len(S) == 26:
    for i in range(24, -1, -1):
        cand = list(S[i+1:])
        cand.sort()
        for c in cand:
            if ord(c) > ord(S[i]):
                print(S[:i]+c)
                exit(0)
    print(-1)
else:
    for l in abc:
        if l not in S:
            print(S+l)
            exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
n0 = 2
n1 = 1

if n == 1:
    print(1)
else:
    for _ in range(1, n):
        n0, n1 = n1, n0+n1
    print(n2)


Fixed submission:
n = int(input())
n0 = 2
n1 = 1

if n == 1:
    print(1)
else:
    for _ in range(1, n):
        n2 = n0+n1
        n0, n1 = n1, n2
    print(n2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
n0 = 2
n1 = 1

for _ in range(1, n):
    n2 = n0+n1
    n0, n1 = n1, n2
print(n2)


Fixed submission:
n = int(input())
n0 = 2
n1 = 1

if n == 1:
    print(1)
else:
    for _ in range(1, n):
        n2 = n0+n1
        n0, n1 = n1, n2
    print(n2)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

B.sort()
C.sort()
ans = 0
for a in A:
    b_index = bisect_right(B, a)
    if b_index == len(B):
        continue
    b_cnt = len(B)-b_index

    for b in B[b_index:]:
        c_index = bisect_right(C, b)
        if c_index == len(C):
            continue
        c_cnt = len(C)-c_index

        ans += c_cnt
print(ans)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
ans = 0
for i in range(N):
    a_cnt = bisect.bisect_left(A, B[i])
    c_cnt = N-bisect.bisect_right(C, B[i])
    ans += a_cnt*c_cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import fractions


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
ans = 0
for _ in range(N):
    if ans == 0:
        ans = int(input())
    else:
        t = int(input())
        ans = (ans * t) // math.gcd(ans, t)
print(ans)


Fixed submission:
import sys
import fractions


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
ans = 0
for _ in range(N):
    if ans == 0:
        ans = int(input())
    else:
        t = int(input())
        ans = (ans * t) // fractions.gcd(ans, t)
print(ans)