TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order.  A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words.  Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()

if len(c) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if not i in s:
            ans = s + i
            break

else:
    tmp = ""
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp += ss.pop()
            continue

        if ss[-1] > tmp[-1]:
            tmp += ss.pop()
        else:
            ss.pop()
            ans = "".join(ss) + min(tmp)
            break
    else:
        ans = -1

print(ans)


s = input()
alp = "abcdefghijklmnopqrstuvwxyz"

if len(s) < 26:
    for i in alp:
        if not i in s:
            ans = s + i
            break

else:
    tmp = []
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp.append(ss.pop())
            continue

        if alp.index(ss[-1]) > alp.index(tmp[-1]):
            tmp.append(ss.pop())
            continue
        else:
            remove = ss.pop()
            tmp.sort()
            for j in tmp:
                if j > remove:
                    renew = j
                    break
            ans = "".join(ss) + renew
            break
    else:
        ans = -1

print(ans)


Verdicts: Runtime Error

Accepted
Problem: Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :    * Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).  Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.

Submission attempts (in order):
n,*a=map(int,open(0).read().split())
a,b=a[:n],a[n:]
for a,b in zip(a,b):
    if a==b:continue
    if b>a:
        print(-1)
        exit()
    if a-b<b:
        print(-1)
        exit()
1/0

from scipy.sparse.csgraph import floyd_warshall
n,*a=map(int,open(0).read().split())
a,b=a[:n],a[n:]
d=[]
M=max(a)
for k in range(M-1,-1,-1):
    s=set(a)
    e=[[0]*(M+1)for _ in range(M+1)]
    for i in range(M+1):e[i][i]=1
    for i in d+list(range(k,0,-1)):
        t=s.copy()
        for x in s:
            e[x][x%i]=1
            t|={x%i}
        s=t
    c=floyd_warshall(e)
    for x,y in zip(a,b):
        if c[x,y]==float('inf'):
            d+=k+1,
            break
print(-(len(d)==M)or sum(2**k for k in d))

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
# ARC093C - Traveling Plan
def main():
    N = int(input())
    A = list(map(int, input().rstrip().split()))
    for i in range(N):
        ans = 0
        cur = 0
        for j in range(N):
            if i == j:
                continue
            ans += max(cur, A[j]) - min(cur, A[j])
            cur = A[j]
    print(ans + abs(cur))


if __name__ == "__main__":
    main()



def main():
    N = int(input())
    A = [0] + list(map(int, input().rstrip().split())) + [0]
    S = 0
    for i in range(1, N + 2):
        S += abs(A[i - 1] - A[i])

    for i in range(1, N + 1):
        ans = S + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]))
        print(ans)


if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n=int(input())
a=[0]+list(map(int,input().split()))+[0]

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

for i in range(1,n+1):
  sa=0
  if a[i+1]<a[i-1]<a[i]:
    sa=(a[i-1]-a[i+1])-(a[i]-a[i-1])-(a[i]-a[i+1])
  elif a[i]<a[i-1]<a[i+1]:
    sa=(a[i+1]-a[i-1])-(a[i-1]-a[i])-(a[i+1]-a[i])
  print(sum+sa)

n=int(input())
a=[0]+list(map(int,input().split()))+[0]

sum_dist=0
for i in range(1,n+2):
  sum_dist+=abs(a[i]-a[i-1])

for i in range(1,n+1):
  t_dist=sum_dist
  t_dist-=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])
  t_dist+=abs(a[i+1]-a[i-1])
  print(t_dist)

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
now = 0
dis = 0
for i in A:
    dis += abs(now-i)
    now = i
ans = dis+abs(now)
B = [0]
B.extend(A)
B.append(0)
print(B)
for i in range(1,N+1):
    if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:
        print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))
    else:
        print(ans)

N = int(input())
A = list(map(int,input().split()))
now = 0
dis = 0
for i in A:
    dis += abs(now-i)
    now = i
ans = dis+abs(now)
B = [0]
B.extend(A)
B.append(0)
for i in range(1,N+1):
    if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:
        print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))
    else:
        print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
    N = int(input())
    A = [int(i) for i in input().split()]
    total, plus = A[0], A[1]
    for i in range(N-1):
        total += abs(A[i+1]-A[i])
    total += abs(A[N-1])
    print(total+A[1]-abs(A[1]-A[0])-A[0])
    for i in range(1,N-1):        
        print(total+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))    
    print(total+A[N-2]-abs(A[N-2]-A[N-1])-abs(A[N-1]))

N = int(input())
A = [int(i) for i in input().split()]
total = abs(A[0])
for i in range(N-1):
    total += abs(A[i+1]-A[i])
total += abs(A[N-1])
print(total+abs(A[1])-abs(A[1]-A[0])-abs(A[0]))
for i in range(1,N-1):        
    print(total+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))    
print(total+abs(A[N-2])-abs(A[N-2]-A[N-1])-abs(A[N-1]))

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[a[0]]
    ans=abs(a[0])
    for i in range(n-1):
        b.append(a[i+1]-a[i])
        ans+=abs(a[i+1]-a[i])
    b.append(-1*a[n-1])
    ans+=abs(a[n-1])
    for i in range(n):
        if b[i]*b[i+1]>=0:
            print(ans)
        else:
            print(ans-b[i]-b[i+1]+abs(b[i]+b[i+1]))
if __name__=="__main__":
    main()

def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[a[0]]
    ans=abs(a[0])
    for i in range(n-1):
        b.append(a[i+1]-a[i])
        ans+=abs(a[i+1]-a[i])
    b.append(-1*a[n-1])
    ans+=abs(a[n-1])
    for i in range(n):
        if b[i]*b[i+1]>=0:
            print(ans)
        else:
            print(ans-abs(b[i])-abs(b[i+1])+abs(b[i]+b[i+1]))
if __name__=="__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = [0]+list(map(int, input().split()))+[0]

money = [0]
for i in range(n+1):
    money.append(abs(a[i]-a[i+1]))
print(money)
ans = sum(money)
for i in range(n):
    print(ans - sum(money[i+1:i+3]) + abs(a[i]-a[i+2]))

import numpy as np
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
x = [0]
for i in range(len(A)-1):
    x.append(abs(A[i]-A[i+1]))
ans = sum(x)
for i in range(1, n+1):
    print(ans - (x[i]+x[i+1]) + abs(A[i-1]-A[i+1]))

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
import copy

n = int(input())
natural = [int(i) for i in input().split()]
sortedlist = natural.sorted()

sum = 0

for i in range(n):
  removed = copy.deepcopy(sortedlist).remove(natural[i])
  for j in range(n-1):
    if j == 0:
      sum += abs(removed[j])
    else:
      sum += abs(removed[j]-removed[j-1])
  print(sum)

n = int(input())
sortedlist = [int(i) for i in input().split()]
anslist = []

longest = 0
ans = 0

for i in range(n+1):
  if i==0:
    longest += abs(sortedlist[0]-0)
  elif i==n:
    longest += abs(0-sortedlist[n-1])
  else:
    longest += abs(sortedlist[i]-sortedlist[i-1])

    
for i in range(n):
  if i==0:
    ans = longest - abs(sortedlist[0]) - abs(sortedlist[1]-sortedlist[0]) + abs(sortedlist[1])
  elif i==n-1:
    ans = longest - abs(sortedlist[n-1]) - abs(sortedlist[n-1]-sortedlist[n-2]) + abs(sortedlist[n-2])
  else:
    ans = longest - abs(sortedlist[i]-sortedlist[i-1])-abs(sortedlist[i+1]-sortedlist[i]) + abs(sortedlist[i+1]-sortedlist[i-1])
  print(ans)
  

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
# ARC093c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = [0]
    a.extend(list(map(int, input().split())))
    a.append(0)
    print(a)

    total = 0
    for i in range(1, n+2):
        total += abs(a[i]-a[i-1])
    # print(total)

    for j in range(1, n+1):
        if a[j-1] <= a[j] <= a[j+1] or a[j-1] >= a[j] >= a[j+1]:
            print(total)
            continue
        print(total-abs(a[j]-a[j-1])-abs(a[j+1]-a[j])+abs(a[j+1]-a[j-1]))


if __name__ == '__main__':
    main()


# ARC093c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = [0]
    a.extend(list(map(int, input().split())))
    a.append(0)
    # print(a)

    total = 0
    for i in range(1, n+2):
        total += abs(a[i]-a[i-1])
    # print(total)

    for j in range(1, n+1):
        if a[j-1] <= a[j] <= a[j+1] or a[j-1] >= a[j] >= a[j+1]:
            print(total)
            continue
        print(total-abs(a[j]-a[j-1])-abs(a[j+1]-a[j])+abs(a[j+1]-a[j-1]))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
        
def main():
    plan=[0]
    n = int(input())
    plan+=list(map(int,input().split()))
    plan.append(0)
    pay_sum = 0
    for i in range(1,n+2):
        pay_sum += abs(plan[i] - plan[i-1])
    
    for i in range(1,n+1):
        result = abs(plan[i-1] - plan[i+1])
        result -= abs(plan[i-1] - plan[i])
        result -= abs(plan[i+1] - plan[i])
        print(pay_sum - result)

if __name__=="__main__":
    main()

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
        
def main():
    plan=[0]
    n = int(input())
    plan+=list(map(int,input().split()))
    plan.append(0)
    pay_sum = 0
    for i in range(1,n+2):
        pay_sum += abs(plan[i] - plan[i-1])
    
    for i in range(1,n+1):
        result = abs(plan[i-1] - plan[i+1])
        result -= abs(plan[i-1] - plan[i])
        result -= abs(plan[i+1] - plan[i])
        print(pay_sum + result)

if __name__=="__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
lis = list(map(int, input().split()))
def abs(m):
  if m>0:
    return m
  return(-m)
def mysum(data):
  ans = 0
  data = [0] + data+[0]
  for j in range(len(data)-1):
    ans += abs(data[j] - data[j+1])
for i in range(len(lis)):
  tmp = lis[:i-1] + lis[i:]
  print(mysum(tmp))

n = int(input())
lis = [0] + list(map(int, input().split())) + [0]
tmp = []
for j in range(len(lis)-1):
    tmp.append(lis[j+1] - lis[j])
lis = list(map(abs,tmp))
preans = sum(lis)
for i in range(len(tmp)-1):
    print(preans - lis[i] - lis[i+1] + abs(tmp[i] + tmp[i+1]))


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

A = map(lambda x: int(x), sys.stdin.readline().split(' '))

total = 0
A.insert(0, 0)
A.append(0)

for i in range(N + 1):
	total += abs(A[i] - A[i+1])

for i in range(1, N + 1):
	print(str(total - abs(A[i] - A[i + 1]) - abs(A[i] - A[i - 1]) + abs(A[i -1] - A[i + 1])))


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

A = sys.stdin.readline().split(' ')


for rem in range(len(A)):
	pay = 0
	B = A.copy()
	del(B[rem])

	for i in range(len(B)):

		a = B[i]
		s = B[i - 1] if i > 0 else 0

		l = a - s
		pay += l if l > 0 else -l

	lastPoint = B[len(B) - 1]
	pay += lastPoint if lastPoint > 0 else -lastPoint

	print(pay)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

A = sys.stdin.readline().split(' ')

A = [int(x) for x in A]

A.insert(0, 0)
A.append(0)

total = 0

for i in range(N + 1):
	total += abs(A[i] - A[i+1])

for i in range(1, N + 1):
	print(str(total - abs(A[i] - A[i + 1]) - abs(A[i] - A[i - 1]) + abs(A[i -1] - A[i + 1])))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j=0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-abs(B[0]))
        else:
            print(S-abs(B[1]-B[0]))
    elif j=len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-abs(B[-1]))
        else:
            print(S-abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-abs(B[j-1]-B[j]))
        else:
            print(S-abs(B[j+1]-B[j]))

A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j==0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-2*abs(B[0]))
        else:
            print(S-2*abs(B[1]-B[0]))
    elif j==len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-2*abs(B[-1]))
        else:
            print(S-2*abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-2*abs(B[j-1]-B[j]))
        else:
            print(S-2*abs(B[j+1]-B[j]))


Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
al = [0] * n
for i in range(n):
  al[i] = abs(a[i+1] - a[i])
s = sum(al)
for i in range(n):
  print(s-al[i-1]-al[i]+abs(a[i+1]-a[i-1]))

n = int(input())
ai = list(map(int,input().split()))
a = [0]
for i in ai:
  a.append(i)
al = [0] * (n+1)
for i in range(n+1):
  al[i] = abs(a[(i+1)%(n+1)] - a[i])
s = sum(al)
for i in range(1,n+1):
  print(s-al[i-1]-al[i]+abs(a[(i+1)%(n+1)]-a[i-1]))

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
print(A)

F = [0]
for i in range(1, N+1):
    F.append(abs(A[i] - A[i-1]) + F[i-1])

B = [0]
for i in range(1, N+1):
    B.append(abs(A[N+1-i] - A[N+2-i]) + B[i-1])
B.reverse()

for i in range(1, N+1):
    print(abs(A[i+1]-A[i-1]) + F[i-1] + B[i])

N = int(input())
A = [0] + list(map(int,input().split())) + [0]

F = [0]
for i in range(1, N+1):
    F.append(abs(A[i] - A[i-1]) + F[i-1])

B = [0]
for i in range(1, N+1):
    B.append(abs(A[N+1-i] - A[N+2-i]) + B[i-1])
B.reverse()

for i in range(1, N+1):
    print(abs(A[i+1]-A[i-1]) + F[i-1] + B[i])

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split))
ans = [0] * n
for i in range(n):
    ac = a
    del ac[i]
    for j in range(0, n):
        if j == 0:
            ans[i] += abs(ac[0])
        else:
            ans[i] += abs(ac[j]-ac[j - 1])

for k in ans:
    print(str(k))

import copy

n = int(input())
a = list(map(int,input().split()))
ans = [0] * n
print(ans)
for i in range(n):
    ac = copy.copy(a)
    del ac[i]
    for j in range(n):
        if j == 0:
            ans[i] += abs(ac[0])
        elif j == n - 1:
            ans[i] += abs(ac[n - 2])
        else:
            ans[i] += abs(ac[j]-ac[j - 1])

for k in ans:
    print(str(k))

n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
anslist = [0] * n
for j in range(n + 1):
    if j == 0:
        ans += abs(a[0])
    elif j == n:
        ans += abs(a[n - 1])
    else:
        ans += abs(a[j]-a[j - 1])

for i in range(1, n + 1):
    anslist[i - 1] = ans - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])
            
for k in anslist:
    print(k)


n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
anslist = [0] * n
for j in range(1, n + 2):
    if j == 1:
        ans += abs(a[j])
    elif j == n + 1:
        ans += abs(a[n])
    else:
        ans += abs(a[j]-a[j - 1])

for i in range(1, n + 1):
    anslist[i - 1] = ans - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])
            
for k in anslist:
    print(k)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
from itertools import accumulate
N = int(input())
A = tuple([0,] + list(map(int, input().split())) + [0,])
D = []
sum = 0
for i, a in enumarate(A[1:-1]):
  i += 1
  pre = A[i - 1]
  tem = A[i]
  nex = A[i + 1]
  x = abs(pre - tem) + abs(tem - nex)
  sum += x
  D.append(abs(pre - nex) - x)
for d in D:
  print(sum + d)

from itertools import accumulate
N = int(input())
A = tuple([0,] + list(map(int, input().split())) + [0,])
D = []
sum = 0
for i, a in enumerate(A[1:-1]):
  i += 1
  pre = A[i - 1]
  tem = A[i]
  nex = A[i + 1]
  x = abs(pre - tem)
  y = abs(tem - nex)
  sum += x
  D.append(abs(pre - nex) - x - y)
sum += y
for d in D:
  print(sum + d)

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.append(a)
    A.append(0)
    
    sum = 0
    for i in range(n):
        root = list(A[:])
        del root[i+1]
        for j in range(1, n+1):
            sum += abs(root[j]-root[j-1])
        print(sum)
        sum = 0


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.append(a)
    A.append(0)
    
    sum = 0
    for i in range(n):
        root = list(A[:])
        del root[i+1]
        for j in range(1, n+1):
            sum += abs(root[j]-root[j-1])
        print(sum)
        sum = 0


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)

    sum = 0
    for i in range(1, n+2):
        sum += abs(A[i]-A[i-1])
    for i in range(1, n+1):
        print(sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
import itertools

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

acc = []
prev = 0
for a in A:
  t = abs(a - prev)
  acc.append(t)
  prev = a
  

ans = []
for i in range(N):
  t = 0
  if 0 < i:
    t += acc[i-1]
  
  if i < N-1:
    t += acc[N-1] - acc[i]
    
  ans.append(t)
  
print("\n".join(map(str,ans)))

import itertools

N = int(input())
A = [0] + list(map(int,input().split())) + [0]

acc = []
prev = 0
t = 0
for i in range(N+2):
  if i == 0:
    continue
  a = A[i]
  t += abs(a - prev)
  acc.append(t)
  prev = a
  
ans = []
for i in range(N+1):
  if i == 0:
    continue
  t = 0

  if 1 < i:
    t += acc[i-2]
  if i < N:
    t += acc[N] - acc[i]
  t += abs(A[i+1] - A[i-1])
    
  ans.append(t)
  
print("\n".join(map(str,ans)))


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]

    sum = 0
    for i in range(1, N+2): sum += abs(A[i] - A[i-1])

    for i in range(1, N+1):
        if (A[i-1] <= A[i] <= A[i+1]): print(sum)
        elif (A[i-1] >= A[i] >= A[i+1]): print(sum)
        else: print(sum - abs(A[i] - A[i-1]) * 2)

if __name__ == '__main__':
    main()


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]

    sum = 0
    for i in range(1, N+2): sum += abs(A[i] - A[i-1])

    for i in range(1, N+1):
        if A[i-1] <= A[i] <= A[i+1]: print(sum)
        elif A[i-1] >= A[i] >= A[i+1]: print(sum)
        elif A[i-1] < A[i+1] < A[i] or A[i-1] > A[i+1] > A[i]: print(sum - abs(A[i+1] - A[i]) * 2)
        else: print(sum - abs(A[i] - A[i-1]) * 2)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
dd = list(map(int, input().split()))
d = [0]
d.extend(dd)
d.append(0)

diff = [abs(d[i + 1] - d[i]) for i in range(N + 1)]

dd = []
for i in range(N):
    if (d[i + 1] - d[i]) * (d[i + 2] - d[i]) < 0:
        dd.append(2 * abs(d[i + 1] - d[i]))
    else:
        dd.append(0)

s = sum(diff)
for i in range(N):
    print(s - dd[i])

N = int(input())
dd = list(map(int, input().split()))
d = [0]
d.extend(dd)
d.append(0)

diff = [abs(d[i + 1] - d[i]) for i in range(N + 1)]
dd = []
for i in range(N):
    temp = abs(d[i + 1] - d[i]) + abs(d[i + 2] - d[i + 1])
    temp_2 = abs(d[i + 2] - d[i])
    if temp > temp_2:
        dd.append(temp - temp_2)
    else:
        dd.append(0)
s = sum(diff)
for i in range(N):
    print(s - dd[i])

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
diff = [abs(A[i]-A[i+1]) for i in range(n+1)]


sum = 0
for i,(a, dif) in enumerate(zip(A, diff)):
  if i == n+1: break 
  sum += abs(a - dif) #a:A[i]
  

for i in range(1, n+1, 1): 
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


n = int(input
A = [0] + list(map(int, input().split())) + [0]


sum = 0
for i, a in enumerate(A):
  if i == n+1: break 
  sum += abs(a - A[i+1]) #a:A[i]
  

for i in range(1, n+1, 1): 
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


n = int(input)
A = [0] + list(map(int, input().split())) + [0]


sum = 0
for i, a in enumerate(A):
  if i == n+1: break 
  sum += abs(a - A[i+1]) #a:A[i]
  

for i in range(1, n+1, 1): 
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


n = int(input())
A = [0] + list(map(int, input().split())) + [0]
diff = [abs(A[i]-A[i+1]) for i in range(n+1)]


sum = sum(diff)
  

for i in range(1, n+1, 1): 
  nowsum = sum
  nowsum -= diff[i-1]
  nowsum -= diff[i]
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n, *A = map(int, open(0).input().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])

n, *A = map(int, open(0).read().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = [ int(x) for x in input().split() ]

ans = abs(a[0] )

for i in range(1, len(a)):
    ans += abs(a[i] - a[i-1])

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        elif 0 <= a[i+1] <= v or v <= a[i+1] <= 0:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= 0 <= a[i+1] or a[i+1] <= 0 <= v:
            print(ans-abs(v)*2)


        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        else:
            print(ans-2*abs(v))
    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= 0 <= v or v <= 0 <= a[i-1]:
            print(ans-abs(v)*2)
        elif v <= a[i-1] <= 0 or 0 <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)




n = int(input())
a = [ int(x) for x in input().split() ]

ans = abs(a[0] )

for i in range(1, len(a)):
    ans += abs(a[i] - a[i-1])

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        elif 0 <= a[i+1] <= v or v <= a[i+1] <= 0:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= 0 <= a[i+1] or a[i+1] <= 0 <= v:
            print(ans-abs(v)*2)

    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= 0 <= v or v <= 0 <= a[i-1]:
            print(ans-abs(v)*2)
        elif v <= a[i-1] <= 0 or 0 <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)




Verdicts: Wrong Answer

Accepted