Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# @author 

import sys

class RWalk:
    def solve(self):

        MOD = 10 ** 9 + 7

        def mult(A, B):
            n, m, p = len(A), len(A[0]), len(B[0])
            assert(len(B) == m)
            C = [[0] * p for _ in range(n)]
            for i in range(n):
                for j in range(p):
                    for k in range(m):
                        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD

            return C

        def pow(A, k):
            n, m = len(A), len(A[0])
            if k == 0:
                return [[1 if i == j else 0 for j in range(m)] for i in range(n)]

            if k % 2 == 0:
                return pow(mult(A, A), k // 2)

            return mult(A, pow(A, k - 1))


        n, k = [int(_) for _ in input().split()]
        a = []
        for i in range(n):
            a.append([int(_) for _ in input().split()])

        print(sum([sum(line) for line in pow(a, k)]) % MOD)

solver = RWalk()
input = sys.stdin.readline

solver.solve()


Fixed submission:
# @author 

import sys

class RWalk:
    def solve(self):

        MOD = 10 ** 9 + 7

        def mult(A, B):
            n, m, p = len(A), len(A[0]), len(B[0])
            assert(len(B) == m)
            C = [[0] * p for _ in range(n)]
            for i in range(n):
                for j in range(p):
                    for k in range(m):
                        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD

            return C

        def pow(A, k):
            n, m = len(A), len(A[0])
            if k == 0:
                return [[1 if i == j else 0 for j in range(m)] for i in range(n)]

            if k % 2 == 0:
                return pow(mult(A, A), k // 2)

            return mult(A, pow(A, k - 1))


        n, k = [int(_) for _ in input().split()]
        a = []
        for i in range(n):
            a.append([int(_) for _ in input().split()])

        print(sum([sum(line) for line in pow(a, k)]) % MOD)

solver = RWalk()
input = sys.stdin.readline

solver.solve()
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
ans = -10**9
for i in range([a,b]):
  for j in range([c,d]):
    ans = max(ans, i*j)

print(ans)


Fixed submission:
a,b,c,d=map(int,input().split())
ans = a*c
for i in [a,b]:
  for j in [c,d]:
    ans = max(ans, i*j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
ans = -10**9
for i in range(a,b+1):
  for j in range(c,d+1):
    ans = max(ans, i*j)

print(ans)


Fixed submission:
a,b,c,d=map(int,input().split())
ans = a*c
for i in [a,b]:
  for j in [c,d]:
    ans = max(ans, i*j)

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

ans = 0
from itertools import combinations_with_replacement
for i in range(1,n+1):
    ans = 0
    for x,y,z in combinations_with_replacement(range(1,int(i**0.5)), 3):
        #print(i, x,y,z, x**2+y**2+z**2+x*y+y*z+z*x, end=' ')
        if x**2+y**2+z**2+x*y+y*z+z*x == i:
            if x==y==z==x:
                ans +=1
            elif x==y or y==z or z==x:
                ans +=3
            else:
                ans +=6
        #print(ans)
    print(ans)


Fixed submission:
n = int(input())
ans = [0]*10**5
for i in range(1,int(n**0.5)):
	for j in range(1,int(n**0.5)):
		for k in range(1,int(n**0.5)):
			res = i**2 + j**2 + k**2 +i*j + j*k + k*i
			ans[res-1] += 1
for i in range(n):
	print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

for i in range(n):
	if i==0:
		conf = [A[i]]
		ans = 0
	else:
		add = max(conf)
		ans+= add
		conf.remove(add)
		conf+=[A[i], A[i]]
	#print(conf, ans)

print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

'''for i in range(n):
	if i==0:
		conf = {A[i]:1}
		ans = 0
	else:
		add=max(conf.keys())
		ans+=add
		conf[A[i]] =2
		if conf[add] >1:
			conf[add] -= 1
		else:
			conf.pop(add)'''

if n%2==0:
	print(sum(A[:n//2]) *2 -A[0])
else:
	print(sum(A[:n//2]) *2 -A[0] +A[n//2])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
A = list(map(int, input().split()))
for i in A:    
    
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
ans = 1
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
for i in sorted(A):
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []

for i in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)


ANS = []

import itertools
for i in itertools.product(range(1,M+1), repeat=N):
    f = 0
    for j in range(len(i)-1):
        if not i[j] < i[j+1]:
            f=1
    if f == 0:
        #print(i)
        ans = 0
        for q in range(Q):
            if i[B[q]-1] - i[A[q]-1] == C[q]:
                ans += D[q]
        ANS.append(ans)
print(max(ANS))


Fixed submission:
N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []

for i in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

listA = list(range(1,N+1))
ANS = 0

import itertools
for i in itertools.combinations_with_replacement(range(1,M+1), N):
    f = 0
    for j in range(len(i)-1):
        if not i[j] <= i[j+1]:
            f=1
    if f == 0:
        #print(i)
        ans = 0
        for q in range(Q):
            if i[B[q]-1] - i[A[q]-1] == C[q]:
                ans += D[q]
        ANS = max([ANS, ans])
print(ANS)
#print(ANS)
Buggy python submission (verdict: Runtime Error):
s,w = map(int, input().split())
if s>f:
    print('safe')
else:
    print('unsafe')

Fixed submission:
s,w = map(int, input().split())
if s>w:
    print('safe')
else:
    print('unsafe')
Buggy python submission (verdict: Runtime Error):
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
if N- sum(A) >= 0:
    print(N- sum(A))
else:
    print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            res = math.gcd(math.gcd(a,b), c)
            ans += res
print(ans)

Fixed submission:
import math
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        res = math.gcd(a,b)
        for c in range(1,k+1):
            ans += math.gcd(res, c)

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

lmt = sum(A) /(4*m)
A.sort(reverse=True)
if A[m] >= lmt:
  print('Yes')
else:
  print('No')

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

lmt = sum(A) /(4*m)
A.sort(reverse=True)
if A[m-1] >= lmt:
  print('Yes')
else:
  print('No')

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

sumA = sum(A)
lmt = sum(A) /(4*m)
#print(sumA, lmt)
A.sort(reverse=True)
if A[m] > lmt:
  print('Yes')
else:
  print('No')

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

lmt = sum(A) /(4*m)
A.sort(reverse=True)
if A[m-1] >= lmt:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)


for i in A:
  ans = 0
  for j in c.keys():
    if c[j] >1:
      k = c[j]
      if j == i:
        if c[j]>2:
          k -= 1
          ans += math.factorial(k) // (math.factorial(k-2) * math.factorial(2))
      else:
        ans += math.factorial(k) // (math.factorial(k-2) * math.factorial(2))
  print(ans)


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

import collections
c = collections.Counter(A)
a = 0

for i,j in c.items():
    a += j *(j-1) //2
#print('===', a)
for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  a = []
  for j in range(N):
    if j != i:
      a.append(A[j])
  #print('=======',a)
  c = collections.Counter(a)
  ans = 0
  for k in c.values():
    #print(k)
    if k > 1:
      ans += math.factorial(k) // (math.factorial(k-2) * math.factorial(2))
  print(ans)

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

import collections
c = collections.Counter(A)
a = 0

for i,j in c.items():
    a += j *(j-1) //2
#print('===', a)
for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'AAA' or S = 'BBB':
  print('No')
else:
  print('Yes')

Fixed submission:
S = input()
if S == 'AAA' or S == 'BBB':
  print('No')
else:
  print('Yes')

Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'AAA' and S = 'BBB':
  print('No')
else:
  print('Yes')

Fixed submission:
S = input()
if S == 'AAA' or S == 'BBB':
  print('No')
else:
  print('Yes')

Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'AAA' and S = 'BBB':
  print('No')
else:
  print('No')

Fixed submission:
S = input()
if S == 'AAA' or S == 'BBB':
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):

S = input()
Q = int(input())

# 逆フラグ
r = 1  # 1==正
for q in range(Q):
  s = input()
  if len(s) == 1:
    r *= -1
  else:
    s, f, c = s.split()
    if f == '1':
      if r == 1:
        S = c + S
      else:
        S = S + c
    else:
      if r == 1:
        S = S + c
      else:
        S = c + S
if r == -1:
  S = S[::-1]
print(S)

Fixed submission:
from collections import deque
d = deque(input())
Q = int(input())

# 逆フラグ
r = 1  # 1==正
for q in range(Q):
  s = input()
  if len(s) == 1:
    r *= -1
  else:
    s, f, c = s.split()
    if (f == '1' and r == -1) or (f == '2' and r == 1):
      d.append(c)
    else:
      d.appendleft(c)
ans = ''.join(d)
if r == -1:
  #d = d[::-1]
  print(ans[::-1])
else:
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for q in range(Q):
  s = input()
  if len(s) == 1:
    S = S[::-1]
  else:
    s, f, c = s.split()
    if f == '1':
      S = c + S
    else:
      S = S + c

print(S)

Fixed submission:
from collections import deque
d = deque(input())
Q = int(input())

# 逆フラグ
r = 1  # 1==正
for q in range(Q):
  s = input()
  if len(s) == 1:
    r *= -1
  else:
    s, f, c = s.split()
    if (f == '1' and r == -1) or (f == '2' and r == 1):
      d.append(c)
    else:
      d.appendleft(c)
ans = ''.join(d)
if r == -1:
  #d = d[::-1]
  print(ans[::-1])
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
X = list(map(int, input().split()))
low = min(X)
high = max(X)
ans = []

for p in range(low, high-low+1):
  dist = 0
  for x in X:
    dist += (x-p)**2
  ans.append(dist)
print(min(ans))

Fixed submission:
n = int(input())
X = list(map(int, input().split()))
low = min(X)
high = max(X)
ans = []

for p in range(low, high-low+1):
  dist = 0
  for x in X:
    dist += (x-p)**2
  ans.append(dist)
if len(ans) != 0:
  print(min(ans))
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
c = 0
for i in range(N):
  a = int(input())
  if a%2 == 0:
    if a%3 == 0 or a%5 == 0:
      pass
    else:
     c += 1 
if c == 0:
  print('APPROVED')
else:
  print('DENIED')

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(N):
  
  if a[i]%2 == 0:
    if a[i]%3 == 0 or a[i]%5 == 0:
      pass
    else:
     c += 1 
if c == 0:
  print('APPROVED')
else:
  print('DENIED')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
P = list(map(int, input().split()))
PP = [(i+1)/2 for i in P]
ans = 0
for i in range(n-k+1):
    ans = max(sum(PP[i:i+k]),ans)
print(ans)

Fixed submission:
n,k = map(int, input().split())
P = list(map(int, input().split()))
PP = [(i+1)/2 for i in P]
ans = 0
ttl = 0
for i,p in enumerate(PP):
    ttl += p
    if i >= k:
        ttl -= PP[i-k]
    ans = max(ttl, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
P =[]
max_l = 0
max_v = 0
P = list(map(int, input().split()))
for i, p in enumerate(P):
  if i <= N-K:
    #print(P[i:K+i])
    if max_v < sum(P[i:K+i]):
      max_v = sum(P[i:K+i])
      
      max_l = P[i:K+i]
#print(max_v)
ans = 0
for l in max_l:
  ans += (l+1)/2
print(ans)

Fixed submission:
n,k = map(int, input().split())
P = list(map(int, input().split()))
PP = [(i+1)/2 for i in P]
ans = 0
ttl = 0
for i,p in enumerate(PP):
    ttl += p
    if i >= k:
        ttl -= PP[i-k]
    ans = max(ttl, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
P =[]
max_l = 0
max_v = 0
P = list(map(int, input().split()))
for i, p in enumerate(P):
  if i <= N-K:
    #print(P[i:K+i])
    if max_v < sum(P[i:K+i]):
      max_v = sum(P[i:K+i])
      
      max_l = P[i:K+i]
#print(max_v)
ans = 0
for l in max_l:
  ans += (l+1)*l/2/l
print(ans)

Fixed submission:
n,k = map(int, input().split())
P = list(map(int, input().split()))
PP = [(i+1)/2 for i in P]
ans = 0
ttl = 0
for i,p in enumerate(PP):
    ttl += p
    if i >= k:
        ttl -= PP[i-k]
    ans = max(ttl, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a=b=1
l=[i for i in range(1,N+1)]
m=[i for i in range(1,N+1)]
for i in range(N):
  #print("===P[i]===", P[i])
  #print(l.index(P[i]), math.factorial(N-i-1))
  a += l.index(P[i])*math.factorial(N-i-1)
  #print("l", l)
  if not i==N-1:
    l.pop(l.index(P[i]))
for i in range(N):
  b += m.index(Q[i])*math.factorial(N-i-1)
  if not i==N-1:
    m.pop(m.index(Q[i]))
print(abs(a-b))


Fixed submission:
import math
N=int(input())
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
a=b=1
l=[i for i in range(1,N+1)]
m=[i for i in range(1,N+1)]
for i in range(N):
  #print("===P[i]===", P[i])
  #print(l.index(P[i]), math.factorial(N-i-1))
  if N-i-1 < 0:
    pass
  else:
    a += l.index(P[i])*math.factorial(N-i-1)
  #print("l", l)
  if not i==N-1:
    l.pop(l.index(P[i]))
for i in range(N):
  if N-i-1 < 0:
    pass
  else:
    b += m.index(Q[i])*math.factorial(N-i-1)
  if not i==N-1:
    m.pop(m.index(Q[i]))
print(abs(a-b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
ans = 0
from itertools import combinations

for i,j,k in combinations(L, 3):
    res = sorted([i,j,k])
    if sum(res[:2]) > res[2]:
        ans += 1

print(ans)


Fixed submission:
from bisect import bisect_left
n = int(input())
L = sorted(list(map(int, input().split())))
#print(L)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
        #print(i,j,bisect_left(L,L[i]+L[j]),(j+1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum([i for i in range(n)]))

Fixed submission:
n = int(input())
print(n *(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s=input()

for i in range(q):
    l,r=map(int, input().split())
    print(s[l-1:r].count('AC'))




Fixed submission:
n,q = map(int, input().split())
s=input()
a=[0]*n
for i in range(1,n):
    a[i]+=a[i-1]
    if s[i-1]=='A' and s[i]=='C':
        a[i]+=1
for i in range(q):
    l,r=map(int, input().split())
    print(a[r-1]-a[l-1])

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

for i in range(n):
    l,r=map(int, input().split())
    print(s[l-1:r].count('AC'))




Fixed submission:
n,q = map(int, input().split())
s=input()
a=[0]*n
for i in range(1,n):
    a[i]+=a[i-1]
    if s[i-1]=='A' and s[i]=='C':
        a[i]+=1
for i in range(q):
    l,r=map(int, input().split())
    print(a[r-1]-a[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

g= A[0]
'''import fractions
for i in range(1,n):
    g = fractions.gcd(g, A[i])'''
import math
for i in range(1,n):
    g = math.gcd(g,A[i])
print(g)

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

g= A[0]
import fractions
for i in range(1,n):
    g = fractions.gcd(g, A[i])
print(g)
Buggy python submission (verdict: Time Limit Exceeded):
S = [i for i in input()]
ans = 0
c = 0
while S[0] == 'W':
    S = S[1:]
for i,s in enumerate(S):
    if s == 'W':
        ans = ans +i -c
        c += 1

print(ans)


Fixed submission:
S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = [1 if i=='W' else 0 for i in input()]
ans = 0
c = 0
while S[0] == 1:
    S = S[1:]
for i,s in enumerate(S):
    if s == 1:
        ans = ans +i -c
        c += 1

print(ans)


Fixed submission:
S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = [i for i in input()]
ans = 0

while 'W' in n:
    #print(n)
    if n[0] =='W':
        n = n[1:]

    for i, s in enumerate(n):
        if s == 'W':
            n[i] = 'B'
            n = n[1:]
            ans += i
            break
print(ans)


Fixed submission:
S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
ans = 0
while 'BW' in n:
    for i, s in enumerate(n):
        if s == 'W':
            n = n[:i] + 'B' + n[i+1:]
            n = n[1:]
            ans += i
            break
print(ans)


Fixed submission:
S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m=map(int,input().split())
s=input()
t=input()
g = n * m // math.gcd(n, m)

snum=[i*g/n+1 for i in range(n)]
tnum=[i*g/m+1 for i in range(m)]
#print(snum,tnum)

if n<m:
    s,t=t,s
    snum,tnum=tnum,snum
for i in range(len(snum)):
    if snum[i] in tnum:
        if s[i]!=t[tnum.index(snum[i])]:
            print(-1)
            exit()
print(g)

Fixed submission:
import math
n,m=map(int,input().split())
s=input()
t=input()
g = n * m // math.gcd(n, m)

'''if n<m:
    s,t=t,s
    snum,tnum=tnum,snum'''

for i in range(math.gcd(n,m)):
    #print(i, i*(g//m), s[i*(g//m)], i*(g//n), t[i*(g//n)])
    if s[i*(g//m)]!=t[i*(g//n)]:
        print(-1)
        exit()
print(g)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())

xlist = list(map(int, input().split()))
import math

ans = xlist[0]
for i in xlist[1:]:
    ans = math.gcd(ans, i)

print(ans)


Fixed submission:
import math
n,x = map(int,input().split())
X = list(map(int,input().split()))
diff = []
for i in range(n):
	diff.append(abs(X[i]-x))
res = diff[0]
for i in range(1,n):
	res = math.gcd(res, diff[i])
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()

abc = ['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 s == ''.join(abc)[::-1]:
    print(-1)
    exit()
if len(s) != 26:
    for a in abc:
        if a not in abc:
            print(s+a)
            exit()
i = 25
while s[i-1] > s[i]:
    i -= 1
    #print(s[i-1], s[i])
#print(s[i-1], s[i])
tt = s[i-1]
ss = list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])


Fixed submission:
#11208467
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
tt=s[i-1]
ss=list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])

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

abc = ['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 s == ''.join(abc)[::-1]:
    print(-1)
    exit()
if len(s) <26:
    for a in abc:
        if a not in abc:
            print(s+a)
            exit()
i = 25
while s[i-1] > s[i]:
    i -= 1
    #print(s[i-1], s[i])
#print(s[i-1], s[i])
tt = s[i-1]
ss = list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])


Fixed submission:
#11208467
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
tt=s[i-1]
ss=list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(1,n+1):
    if i == P[i-1]:
        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 i == n and P[i-1] == n:
        ans +=1
    elif i == P[i-1]:
        P[i] = P[i-1]
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
T = []
ans = 1
for i in range(n):
    t = int(input())
    T.append(t)
    ans = ans * t // math.gcd(ans, t)
print(ans)

Fixed submission:
import fractions
n = int(input())
T = []
ans = 1
for i in range(n):
    t = int(input())
    T.append(t)
    ans = ans * t // fractions.gcd(ans, t)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
A = list(map(int, input().split()))
f2 = 0
f4 = 0
for a in A:
    c = collections.Counter(prime_factorize(a))
    if c[2] == 1:
        f2 += 1
    elif c[2] >= 2:
        f4 += 1
if n -f2//2 *2 -f4 *3 <= 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
f2 = 0
f4 = 0
f_another = 0
for a in A:
    #c = collections.Counter(prime_factorize(a))
    if a%4 == 0:
        f4 += 1
    elif a%2 == 0:
        f2 += 1
    else:
        f_another +=1
if n%2 == 0 and (n -f2//2 *2 -f4 *2 <= 0):
    print('Yes')
elif n%2 == 1 and (n -f2//2 *2 -f4 *2 <= 1):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

total = sum(A)
ans = 10**9
if n > 2:
    for i in range(1,n-1):
        res = abs(total - 2*sum(A[:i]))
        ans = min(ans, res)
else:
    ans = (A[0] - A[1])
print(ans)


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

total = sum(A)
ans = 10**10
res = 0

for i in range(n-1):
    res += A[i]
    ans = min(ans, abs(total -2*res))

print(ans)

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

total = sum(A)
ans = 10**9
if n > 2:
    for i in range(1,n-1):
        res = abs(total - 2*sum(A[:i]))
        ans = min([ans, res])
else:
    ans = (A[0] - A[1])
print(ans)


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

total = sum(A)
ans = 10**10
res = 0

for i in range(n-1):
    res += A[i]
    ans = min(ans, abs(total -2*res))

print(ans)