Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

WA = [sum(A[n:])%mod for n in range(N)]

total = 0
for i in range(N-1):
    total += (A[i] * WA[i+1]) % mod

print(total%mod)

Fixed submission:
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

WA = [sum(A[:n+1])%mod for n in range(N)]

total = 0
for i in range(N-1):
    total += (A[i]%mod) * ((WA[N-1]-WA[i])%mod)

print(total%mod)

Fixed submission:
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()][:N]

mod = 10**9 + 7

WA = [sum(A[:n+1])%mod for n in range(N)]

total = 0
for i in range(N-1):
    total += A[i] * (WA[N-1]-WA[i]) % mod

print(total%mod)

Fixed submission:
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()][:N]

mod = 10**9 + 7

total = 0
for i in range(N-1):
    for j in range(N-i-1):
        total += A[i]*A[i+j+1] % mod

print(total%mod)

Fixed submission:
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()][:N]

total = 0
for i in range(N-1):
    for j in range(N-i-1):
        total += A[i]*A[i+j+1]
        total %= 1000000007

print(total)

Fixed submission:
mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
    return
  else:
    for i in nums:
      result *= i
    if result > 1000000000000000000:
      print(-1)
      return
    else:
      print(result)
      return


if __name__ == "__main__":
  main()

Fixed submission:
def main():
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
    return
  else:
    for i in nums:
      result *= i
      if result > 1000000000000000000:
        print(-1)
        return
    print(result)
    return


if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
  else:
    for i in nums:
      result *= i
    if result > 1000000000000000000:
      print(-1)
    else:
      print(result)

Fixed submission:
def main():
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
    return
  else:
    for i in nums:
      result *= i
      if result > 1000000000000000000:
        print(-1)
        return
    print(result)
    return


if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
  else:
    for i in nums:
      result *= i
    print(result if result <= 1000000000000000000 else "-1")

Fixed submission:
def main():
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
    return
  else:
    for i in nums:
      result *= i
      if result > 1000000000000000000:
        print(-1)
        return
    print(result)
    return


if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  for i in nums:
    result *= i
  print(result if result <= 1000000000000000000 else "-1")

Fixed submission:
def main():
  n = int(input())
  nums = list(map(int, input().split()))
  result = 1
  if 0 in nums:
    print(0)
    return
  else:
    for i in nums:
      result *= i
      if result > 1000000000000000000:
        print(-1)
        return
    print(result)
    return


if __name__ == "__main__":
  main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))#might need to remove the -1
def invr():
    return(map(int,input().split()))

if s*d<=t:
	print('Yes')
else:
	print('No')

Fixed submission:
import sys
input = sys.stdin.readline
 
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))#might need to remove the -1
def invr():
    return(map(int,input().split()))

d, t, s = invr()

if d/s<=t:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
for i in range(len(S)-lenT+1):
  compareS = S[i:i+lenT]
  match_len = 0
  for j in range(lenT):
    if compareS[j] == T[j]:
      match_len += 1
  else:
    if max_match_len < match_len:
      max_match_len = match_len
print(lenT - max_match_len)


Fixed submission:
S, T = [input() for x in range(2)]
max_match_len = 0

for i in range(len(S)):
  if len(S) - len(T) < i:
    break
  compare_s = S[i:i+len(T)]
  match_len = 0
  for j in range(len(T)):
    if compare_s[j] == T[j]:
      match_len += 1
  else:
    if max_match_len < match_len:
      max_match_len = match_len
print(len(T) - max_match_len)
Buggy python submission (verdict: Time Limit Exceeded):
times = int(input())
numbers = list(map(int, input().split()))
result = 0
for i in range(times):
  for j in range(i+1, times):
    result += numbers[i] * numbers[j]
print(result % (10 ** 9 + 7))


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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
result = 0
mod = 10 ** 9 +7
for i in range(N):
  result = (result + A[i] * sum(A[i+1:]) % mod) % mod
print(result % mod)

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
result = 0
mod = 10 ** 9 +7
for i in range(N):
  for j in range(i+1, N):
    result = (result + A[i] * A[j] % mod) % mod
print(result)

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
result = 0
mod = 10 ** 9 +7
for i in range(N):
  for j in range(i+1, N):
    calc = result + A[i] * A[j]
    result = calc - calc // mod * mod
print(result)

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
result = 0
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(i+1, N):
    calc = result + A[i] * A[j]
    compare = calc // mod
    result = calc if compare < 1 else calc - compare * mod
print(result)

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
calc = 0
for i in range(N):
  for j in range(i+1, N):
    calc += A[i] * A[j]
print(calc % (10 ** 9 +7))

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)
Buggy python submission (verdict: Runtime Error):
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

ans_list = []
m,n = map(int, input().split())
fct = factorize(n)
for div in divisorize(fct):
    ans_list.append(num(div))
ans_list.sort()
for number in ans_list:
    if number <= (n//m):
        ans = number
print(ans)


Fixed submission:

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

ans_list = []
m,n = map(int, input().split())
if m == 1 and n == 1:
    print(1)
else:
    fct = factorize(n)
    for div in divisorize(fct):
        ans_list.append(num(div))
    ans_list.sort()
    for number in ans_list:
        if number <= (n//m):
            ans = number
    print(ans)
Buggy python submission (verdict: Runtime Error):
def factorial(n):
	fact = 1
	while n > 0:
		fact *= n
		n -= 1
	return fact
	
def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

n, m = map(int, input().split())
n_def = n
natural = list(range(2,320))
index = 0
while index < len(natural):
	for number in natural:
		if number % natural[index] == 0 and number / natural[index] != 1:
			natural.remove(number)
	index += 1
prime = natural

prime_division = {}
index = 0
number_prime = 0
while prime[index] <= m:
	if m % prime[index] == 0:
		m /= prime[index]
		number_prime += 1
		continue		
	else:
		prime_division[prime[index]] = number_prime
		number_prime = 0
		index += 1
else:
	prime_division[prime[index]] = number_prime

list_division = list(prime_division.values())
ans = 1
for i in list_division:
	ans *= combination(i+n-1,n-1)
print(int(ans%(10**9 + 7)))

Fixed submission:
a,b,c = map(int, input().split())
print(9 * max(a,b,c) + a+b+c)
Buggy python submission (verdict: Runtime Error):
import math
n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = math.gcd(gcd1, list_dist[i])
print(gcd1)


Fixed submission:
def gcd(x,y):
    if x < y:
        (x,y) = (y,x)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = gcd(gcd1, list_dist[i])
print(gcd1)

Buggy python submission (verdict: Runtime Error):
import math
n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd = list_dist[0]
for i in range(1,n):
    gcd = math.gcd(gcd, list_dist[i])
print(gcd)


Fixed submission:
def gcd(x,y):
    if x < y:
        (x,y) = (y,x)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = gcd(gcd1, list_dist[i])
print(gcd1)

Buggy python submission (verdict: Runtime Error):
import math,functools
n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
print(functools.reduce(math.gcd,list_dist))


Fixed submission:
def gcd(x,y):
    if x < y:
        (x,y) = (y,x)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = gcd(gcd1, list_dist[i])
print(gcd1)

Buggy python submission (verdict: Runtime Error):
import math
import functools
n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
print(functools.reduce(math.gcd,list_dist))


Fixed submission:
def gcd(x,y):
    if x < y:
        (x,y) = (y,x)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = gcd(gcd1, list_dist[i])
print(gcd1)
Buggy python submission (verdict: Runtime Error):
list_s = list(str(input()))
k = int(input())
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])


Fixed submission:
list_s = list(str(input()))
k = int(input())
bord = 10 **9
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main() {
    

    int n;
    cin >> n;
    if (n%2 == 0){
        cout << n << endl;
    }else{
        cout << 2 * n << endl;
    }


}


Fixed submission:
n = int(input())
if n%2==0:
  print(n)
else:
  print(n*2)
Buggy python submission (verdict: Time Limit Exceeded):
def prime(n): # nまでの素数を列挙
    import math
    if n == 1:
        return []
    else:
        num_list = [i + 1 for i in range(2,n,2)]
        list_prime = [2]
        limit = math.sqrt(n)
        if n == 2:
            return list_prime
        else:
            while True:
                p = num_list[0]
                if p >= limit:
                    return list_prime + num_list
                list_prime.append(p)
                num_list = [num for num in num_list if num % p != 0]


def primeFactorization(n):
    import math
    if n == 1:
        return {}
    else:
        list_prime = prime(int(math.sqrt(n)))
        i = 0
        dict_pF = {}
        dict_primeFactorization = {}
        for pri in list_prime:
            dict_pF[pri] = 0
        while True:
            if n == 1:
                for key, value in dict_pF.items():
                    if value != 0:
                        dict_primeFactorization[key] = value
                return dict_primeFactorization
            elif i >= len(list_prime):
                dict_pF[n] = 1
                for key, value in dict_pF.items():
                    if value != 0:
                        dict_primeFactorization[key] = value
                return dict_primeFactorization
            p = list_prime[i]
            if n % p == 0:
                n //= p
                dict_pF[p] += 1
                continue
            else:
                i += 1

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

ans = 0
for number in list_a:
    try:
        ans += primeFactorization(number)[2]
    except:
        pass

print(ans)


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

factor2 = 0
for number in list_a:
    while number % 2 == 0:
        number /= 2
        factor2 += 1

print(factor2)
Buggy python submission (verdict: Runtime Error):
n = str(input())
len = len(n)
list = list(n)
ans = 0
if n.count("0") != len - 1:
  for element in list:
    ans += int(element)
elif len(n) == 1:
  ans = int(n)
else:
  ans = 10
print(ans)

Fixed submission:
n = str(input())
len = len(n)
list = list(n)
ans = 0
if len == 1:
  ans = int(n)
elif n.count("0") != len - 1:
  for element in list:
    ans += int(element)
else:
  ans = 10
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
print(max(a+b,a-b,a*b))

Fixed submission:
a,b = map(int, input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open("input.txt", "r")
sys.stdin = f

x = int(input())
p = 2
list_prob = []
ind = 0
i = 1
while p < 11:
    ind = i ** p
    while ind < 1001:
        list_prob.append(int(i ** p))
        i += 1
        ind = i ** p
    i = 1
    p += 1
list_prob.append(1001)
list_prob.sort()
while i < len(list_prob):
    if list_prob[i] <= x and list_prob[i+1] > x:
        print(list_prob[i])
        break
    i += 1


Fixed submission:
x = int(input())
p = 2
list_prob = []
ind = 0
i = 1
while p < 11:
    ind = i ** p
    while ind < 1001:
        list_prob.append(int(i ** p))
        i += 1
        ind = i ** p
    i = 1
    p += 1
list_prob.append(1001)
list_prob.sort()
while i < len(list_prob):
    if list_prob[i] <= x and list_prob[i+1] > x:
        print(list_prob[i])
        break
    i += 1

Buggy python submission (verdict: Runtime Error):
x = int(input())
p = 2
list_prob = []
ind = 0
i = 1
while p < 11:
    ind = i ** p
    while ind < 1001:
        list_prob.append(int(i ** p))
        i += 1
        ind = i ** p
    i = 1
    p += 1
list_prob.sort()
while i < len(list_prob):
    if list_prob[i] <= x and list_prob[i+1] > x:
        print(list_prob[i])
        break
    i += 1

Fixed submission:
x = int(input())
p = 2
list_prob = []
ind = 0
i = 1
while p < 11:
    ind = i ** p
    while ind < 1001:
        list_prob.append(int(i ** p))
        i += 1
        ind = i ** p
    i = 1
    p += 1
list_prob.append(1001)
list_prob.sort()
while i < len(list_prob):
    if list_prob[i] <= x and list_prob[i+1] > x:
        print(list_prob[i])
        break
    i += 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_list = [0]
for i in range(0,n):
    memo += list_a[i]
    memo_list.append(memo)
#print(memo_list)
ans_pre_list = []
for number in set(memo_list):
    if memo_list.count(number) > 1:
        ans_pre_list.append(memo_list.count(number))
#print(ans_pre_list)
ans = 0
for number in ans_pre_list:
    ans += number * (number-1) / 2
print(int(ans))


Fixed submission:
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_dict = {0:1}
for i in range(0,n):
    memo += list_a[i]
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
ans = 0
i = 0
j = 0
while i < n:
    while j < n-i:
        memo += list_a[i+j]
        #print(memo)
        if memo == 0:
            ans += 1
        j += 1
    memo = 0
    i += 1
    j = 0
print(ans)


Fixed submission:
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_dict = {0:1}
for i in range(0,n):
    memo += list_a[i]
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
s = str(input())
list_s = list(s)
alp_list = list("abcdefghijklmnopqrstuvwxyz")
dict_alp = {}
ans = 0
for i in range(26):
    dict_alp[alp_list[i]] = i+1
if len(list_s) == 26:
    i = 25
    while True:
        try:
            if dict_alp[list_s[i]] > dict_alp[list_s[i-1]]:
                list_s = list_s[:i]
                x = list_s.pop()
                break
            else:
                i -= 1
        except IndexError:
            ans = -1
            break
    alp_set = []
    for alp in alp_list:
        if not alp in list_s:
            if dict_alp[alp] > dict_alp[x]:
                alp_set.append(alp)
    alp_set.sort()
    list_s.append(alp_set[0])
else:
    for alp in alp_list:
        if not alp in list_s:
            list_s.append(alp)
            break
if ans == -1:
    print(ans)
else:
    print("".join(list_s))


Fixed submission:
s = str(input())
list_s = list(s)
alp_list = list("abcdefghijklmnopqrstuvwxyz")
dict_alp = {}
ans = 0
for i in range(26):
    dict_alp[alp_list[i]] = i+1
if len(list_s) == 26:
    i = 25
    while True:
        try:
            if dict_alp[list_s[i]] > dict_alp[list_s[i-1]]:
                list_s = list_s[:i]
                x = list_s.pop()
                break
            else:
                i -= 1
        except IndexError:
            ans = -1
            break
    if ans != -1:
        alp_set = []
        for alp in alp_list:
            if not alp in list_s:
                if dict_alp[alp] > dict_alp[x]:
                    alp_set.append(alp)
        alp_set.sort()
        list_s.append(alp_set[0])
else:
    for alp in alp_list:
        if not alp in list_s:
            list_s.append(alp)
            break
if ans == -1:
    print(ans)
else:
    print("".join(list_s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])

for i in range(0,n):
    ans = 0
    for j in range(0,n+1):
        if j != i and j != i + 1:
            ans += abs(list_memo[j])
    ans += abs(list_memo[i+1] + list_memo[i])
    print(ans)


Fixed submission:
n = int(input())
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])
ans_pre = 0
for i in range(0,n+1):
    ans_pre += abs(list_memo[i])
for i in range(0,n):
    ans = ans_pre - abs(list_memo[i]) - abs(list_memo[i+1]) + abs(list_memo[i] + list_memo[i+1])
    print(ans)