Problem:


Score : 300 points

Problem Statement

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.

Constraints

2 \leq N \leq 10^5

-5000 \leq A_i \leq 5000 (1 \leq i \leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N lines.
In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled.

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively.
For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:

For i = 1, the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.

For i = 2, the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.

For i = 3, the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

6
-679 -2409 -3258 3095 -3291 -4462

Sample Output 3

21630
21630
19932
8924
21630
19288



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
CUSUM=[0]*(N+2)
if N > 2:
  for i in range(N):
    if i == 0:
      CUSUM[1] = abs(A[0])
    else:
      CUSUM[i+1] = abs(A[i-1] - A[i])
  CUSUM[N+1] = abs(A[N-1])
  M = sum(CUSUM)
  #print(CUSUM)
  for i in range(N):
    if i == 0:
      ANS =  M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i+1])
    elif i == N-1:
      ANS = M - CUSUM[-1] - CUSUM[-2] + abs(A[i-1])
    else:
      ANS = M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i-1] - A[i+1])
    print(ANS)
else:
  #print(abs(A[1]))
  #print(abs(A[0]))
  print(9)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
CUSUM=[0]*(N+2)
if N > 2:
  for i in range(N):
    if i == 0:
      CUSUM[1] = abs(A[0])
    else:
      CUSUM[i+1] = abs(A[i-1] - A[i])
  CUSUM[N+1] = abs(A[N-1])
  M = sum(CUSUM)
  #print(CUSUM)
  for i in range(N):
    if i == 0:
      ANS =  M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i+1])
    elif i == N-1:
      ANS = M - CUSUM[-1] - CUSUM[-2] + abs(A[i-1])
    else:
      ANS = M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i-1] - A[i+1])
    print(ANS)
else:
  print(abs(A[1]))
  print(abs(A[0]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
cost = 0
for i in range(n+1):
    cost += abs(a[i] - a[i+1])
    
for j in range(1, n+1):
    if a[j-1] < a[j] < a[j+1]:
        print(cost)
    elif a[j-1] > a[j] > a[j+1]:
        print(cost)
    else:
        print(cost - abs(a[j] - a[j-1])*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
a.append(0)
d = []
for i in range(1, n+2):
  d.append(abs(a[i - 1] - a[i]))
base = sum(d)
for i in range(1, n):
  print(base - d[i - 1] - d[i]
    + abs(a[i - 1] - a[i + 1]))

Submission status: Wrong Answer

Solution code:
def cost(p, q):
    if p * q >= 0:
        return max(abs(p), abs(q)) * 2
    else:
        return abs(p - q) * 2

n = int(input())
a = list(map(int, input().split()))
b = [0] + a + [0]
print(b)
d = sum([abs(b[i + 1] - b[i]) for i in range(n + 1)])
for i in range(n):
    print(d - abs(b[i + 1] - b[i]) - abs(b[i + 2] - b[i + 1]) + abs(b[i + 2] - b[i]))

Submission status: Wrong Answer

Solution code:
def cost(p, q):
    if p * q >= 0:
        return max(abs(p), abs(q)) * 2
    else:
        return abs(p - q) * 2

n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
for i in range(n):
    if a[i] == b[0]:
        print(cost(b[1], b[-1]))
    elif a[i] == b[-1]:
        print(cost(b[0], b[-2]))
    else:
        print(cost(b[0], b[-1]))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

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

#print(total)

for i in range(N):
	# 終端
	if i == N-1:
		# 終端がi-1と反対側
		if A[i-1] * A[i] <= 0:
			print(total - abs(A[i])*2)
		# 終端がi-1の向こう側
		elif (A[i]>0 and A[i]-1<=A[i]) or (A[i]<0 and A[i-1]>=A[i]):
			print(total - abs(A[i]-A[i-1])*2)
		# 終端がi-1の手前
		else:
			print(total)
	
	# 始端 i==0
	elif i == 0:
		# A[0]とA[1]の正負が反対
		if A[0] * A[1] <= 0:
			print(total - abs(A[0])*2)
		# A[1]がA[0]の向こう側にあるケース
		elif abs(A[1]) >= abs(A[0]):
			print(total)
		# A[1]がA[0]より手前にあるケース
		else:
			print(total- abs(A[1]-A[0])*2)
	
	# i が正負の一定方向の中間地点にあるケース
	elif (A[i]>=A[i-1] and A[i+1]>=A[i]) or (A[i]<=A[i-1] and A[i+1]<=A[i]):
		print(total)
	
	# i が飛び出ているケース i-1 < i and i+1 < i
	elif A[i-1] <= A[i] and A[i+1] <= A[i] or A[i-1] >= A[i] and A[i+1] >= A[i]:
		print(total - abs(A[i]-A[i-1])*2)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

for i in range(N):
	ans = 0
	for j in range(N-1):
		if i==j: continue
		if ans==0:
			ans += abs(A[j])
		if i==j+1 and j+2<N:
			ans += abs(A[j+2]-A[j])
		elif j+1<N and i != j+1:
			ans += abs(A[j+1]-A[j])
	else:
		if i!=N-1:
			ans += abs(A[j+1])
		else:
			ans += abs(A[j])
	print(ans)

Submission status: Wrong Answer

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

sortedA=sorted(A)
L1=sortedA[0]
L2=sortedA[1]
R1=sortedA[-1]
R2=sortedA[-2]

def calcDist(L,R):
  if L*R<0:
    return (abs(L)+abs(R))*2
  else:
    return max(abs(L),abs(R))*2
  
distL1R1=calcDist(L1,R1)
print("distL1R1:",distL1R1)
distL1R2=calcDist(L1,R2)
distL2R1=calcDist(L2,R1)
distL2R1=calcDist(L2,R2)

for i in range(N):
  tar=A[i]
  ans=distL1R1
  if tar==L1:
    ans=distL2R1
  elif tar==R1:
    ans=distL1R2
  print(ans)

Submission status: Wrong Answer

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

for n in range(N):
    X = A[:n] + A[(n+1):] + [0]
    max_x = max(X)
    min_x = min(X)
    ans = abs(max_x)*2 + abs(min_x)*2
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.append(0)
A.insert(0,0)
usualsum=abs(A[0])
for i in range(N+1):
    usualsum+=abs(A[i+1]-A[i])
print(usualsum)

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    plan = []
    from heapq import heapify, heappush
    cur = []
    heapify(cur)
    num_change = set()
    for i in range(N):
        heappush(cur, min(-A[i], A[i]))
        if i == N-1 or A[i] * A[i+1] <= 0:
            plan.append(cur)
            cur = []
            heapify(cur)
            num_change.add(i)
    dist_sum = 0
    for p in plan:
        dist_sum += -2 * p[0]
    p_i = 0
    sigma = 0
    for a in A:
        if a == 0:
            continue
        if a < 0:
            sigma = 1
            break
        else:
            sigma = -1
            break
    for i in range(N):
        if A[i] != sigma*plan[p_i][0]:
            print(dist_sum)
        elif len(plan[p_i]) > 2:
            cur = dist_sum - plan[p_i][0] * \
                (-2) + min(plan[p_i][1], plan[p_i][2]) * (-2)
            if p_i != 0 and p_i != len(plan)-1:
                cur -= abs(max(plan[p_i-1][0], plan[p_i+1][0])*2)
            print(cur)
        elif len(plan[p_i]) == 2:
            cur = dist_sum - plan[p_i][0]*(-2) + plan[p_i][1]*(-2)
            if p_i != 0 and p_i != len(plan)-1:
                cur -= abs(max(plan[p_i-1][0], plan[p_i+1][0])*2)
            print(cur)
        else:
            cur = dist_sum - plan[p_i][0]*(-2)
            if p_i != 0 and p_i != len(plan)-1:
                cur -= abs(max(plan[p_i-1][0], plan[p_i+1][0])*2)
            print(cur)
        if i in num_change:
            p_i += 1
            sigma *= -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

# NOTE: 間に合わない
# for i in range(N):
#     ans = 0
#     now = 0
#     for j, a in enumerate(A):
#         if i == j:
#             continue
#         ans += abs(now - a)
#         now = a
#     ans += abs(0 - now)
#     print(ans)

HEAD = []
TAIL = []
now = 0
tmp = 0
for ai in A + [0]:
    tmp += abs(ai - now)
    now = ai
    HEAD.append(tmp)

now = 0
tmp = 0
for ai in A[::-1] + [0]:
    tmp += abs(ai - now)
    now = ai
    TAIL.append(tmp)

print(HEAD)
print(TAIL)

ans = 0
for i in range(N):
    if i == 0:
        ans = abs(A[1] - 0) + TAIL[N-2]
    elif i == N - 1:
        ans = abs(A[N-2] - 0) + HEAD[N-2]
    else:
        # print(HEAD[i-1], TAIL[N-i-2], abs(A[i+1] - A[i-1]), i, N-i-2)
        ans = HEAD[i-1] + TAIL[N-i-2] + abs(A[i+1] - A[i-1])
    print(ans)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools

    n = int(input())
    as_ = [0] + list(map(int, input().split())) + [0]
    sum_cost = functools.reduce(lambda x, i: x + abs(as_[i] - as_[i - 1]), range(1, n + 2), 0)
    print(sum_cost)
    for i in range(1, n + 1):
        # print(abs(as_[i] - as_[i - 1]) - abs(as_[i + 1] - as_[i]) + abs(as_[i + 1] - as_[i - 1]))
        print(sum_cost - abs(as_[i] - as_[i - 1]) - abs(as_[i + 1] - as_[i]) + abs(as_[i + 1] - as_[i - 1]))

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
root = [abs(array[0])]
final_array = [abs(array[0])]
first  = array[0]
for i in range(1,N):
    if i != N-1:
        final_array.append(abs(first-array[i]))
    root.append(abs(first-array[i]))
    first = array[i]
root.append(abs(array[N-1]))
final_array.append(abs(array[N-2]))
array.append(0)
summ = sum(root)
for i in range(N-1):
    if array[i] >= 0:
        if array[i] <= array[i+1]:
            print(summ)
        else:
            print(summ-root[i]*2)
    else:
        if array[i] >= array[i+1]:
            print(summ)
        else:
            print(summ-root[i]*2)
print(sum(final_array))

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
root = [abs(array[0])]
first  = array[0]
for i in range(1,N):
    root.append(abs(first-array[i]))
    first = array[i]
root.append(abs(array[N-1]))
array.append(0)
sum = sum(root)
# print(root)
for i in range(N-1):
    if array[i] >= 0:
        if array[i] <= array[i+1]:
            print(sum)
        else:
            print(sum-root[i]*2)
    else:
        if array[i] >= array[i+1]:
            print(sum)
        else:
            print(sum-root[i]*2)
if array[N-2] > 0:
    if array[N-2] >= array[N-1]:
        if array[N-1] < 0:
            print(sum-abs(array[N-1])*2)
        else:
            print(sum)
    else:
        print(sum-root[N-1]*2)
else:
    if array[N-2] <= array[N-1]:
        print(sum)
    else:
        print(sum-root[N-1]*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
root = [abs(array[0])]
first  = array[0]
for i in range(1,N):
    root.append(abs(first-array[i]))
    first = array[i]
root.append(abs(array[N-1]))
array.append(0)
sum = sum(root)
print(root)
for i in range(N-1):
    if array[i] >= 0:
        if array[i] <= array[i+1]:
            print(sum)
        else:
            print(sum-root[i]*2)
    else:
        if array[i] >= array[i+1]:
            print(sum)
        else:
            print(sum-root[i]*2)
if array[N-2] > 0:
    if array[N-2] >= array[N-1]:
        if array[N-1] < 0:
            print(sum-abs(array[N-1])*2)
        else:
            print(sum)
    else:
        print(sum-root[N-1]*2)
else:
    if array[N-2] <= array[N-1]:
        print(sum)
    else:
        print(sum-root[N-1]*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
ary = [0]+list(map(int,input().split()))+[0]
total = 0
for i in range(1,n+2):
    total += abs(ary[i] - ary[i-1])
print(total)
for i in range(1,n+1):
    print(total-abs(ary[i]-(ary[i-1])) -abs(ary[i]-(ary[i+1])) +abs((ary[i-1])-(ary[i+1])))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

for i in range(N):
	if A[i]<=A[i+1]<=A[i+2] or A[i+2]<=A[i+1]<=A[i]:  # 消すところが真ん中
		print(ans) 
	else:
		print(ans-2*
			min(
				abs(A[i+2]-A[i+1]), 
				abs(A[i+1]-A[i])
				)
			)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    A_ = [0] + A +[0]
    ans = []
    print(A_)
    p= 0
    for i in range(N+1):
        p += abs(A_[i+1] - A_[i])

    for i in range(1, N+1):
        print(p - (abs(A_[i]-A_[i-1]) + abs(A_[i+1]-A_[i])) + abs(A_[i+1]-A_[i-1]))


if  __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
#print(a)
s_all=abs(a[0])
for i in range(n):
    s_all+=abs(a[i+1]-a[i])
#print(s_all)
#print(a[1])
#print(a[0]+abs(a[1]-a[0]))
s=[s_all-abs(a[0])-abs(a[1]-a[0])+a[1]]
#print(s)
for j in range(1,n):
    c=abs(a[j-1]-a[j])+abs(a[j]-a[j+1])
    d=abs(a[j+1]-a[j-1])
    s.append(s_all-c+d)
for i in s:
    print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
#print(a)
s_all=abs(a[0])
for i in range(n):
    s_all+=abs(a[i+1]-a[i])
#print(s_all)
#print(a[1])
#print(a[0]+abs(a[1]-a[0]))
s=[s_all-a[0]-abs(a[1]-a[0])+a[1]]
#print(s)
for j in range(1,n):
    c=abs(a[j-1]-a[j])+abs(a[j]-a[j+1])
    d=abs(a[j+1]-a[j-1])
    s.append(s_all-c+d)
for i in s:
    print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
lst1=[0]*(n+2)
lst2=[0]*(n+2)
lst1[1]=abs(a[0])
lst2[1]=abs(a[n-1])
for i in range(1,n):
  lst1[i+1]=lst1[i]+abs(a[i]-a[i-1])
  lst2[i+1]=lst2[i]+abs(a[n-i]-a[n-i-1])
lst1[n+1]=lst1[n]+abs(a[n-1])
lst2[n+1]=lst2[n]+abs(a[0])
print(lst2[n-1]+abs(a[1]))
for i in range(1,n-1):
  print(lst1[i]+lst2[n-i]+abs(a[i+1]-a[i-1]))
print(lst1[n-1]+abs(a[n-2]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
lst1=[0]*(n+2)
lst2=[0]*(n+2)
lst1[1]=abs(a[0])
lst2[1]=abs(a[n-1])
for i in range(1,n):
  lst1[i+1]=lst1[i]+abs(a[i]-a[i-1])
  lst2[i+1]=lst2[i]+abs(a[n-i]-a[n-i-1])
lst1[n+1]=lst1[n]+abs(a[n-1])
lst2[n+1]=lst2[n]+abs(a[0])
for i in range(n):
  print(lst1[i]+lst2[n-i]+abs(a[min(n-1,i+1)]-a[max(0,i-1)]))

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
c = sorted(p)

for x in p:
  m = c[0]
  if m == x:
    m = c[1]
  M = c[-1]
  if M == x:
    M = c[-2]
  print((max(M, 0) - min(m, 0))*2)

Submission status: Wrong Answer

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

import copy
a = copy.deepcopy(li)

for i in range(n):
    aa = a.pop(i)
    if max (a) <=0:
        print(abs(min(a))*2)
    elif min(a) >= 0:
        print(abs(max(a))*2)
    else:
        print((max(a)-min(a))*2)
    a = copy.deepcopy(li)

Submission status: Wrong Answer

Solution code:
# ABC092 C - Traveling Plan
n = int(input())
a = list(map(int, input().split()))
l = []
ans = []

l.append(abs(a[0]))
for i in range(n-1):
    l.append(abs(a[i+1]-a[i]))
s = 0
s = sum(l)
an = abs(a[n-1])
for i in range(n):
    if i == 0:
        ans.append(s-abs(a[0])+l[i]+an)
    elif i == n-1:
        ans.append(sum(l[:-1])+abs(a[n-2]))
    else:
        ans.append(s-l[i]-l[i+1]+abs(a[i+1]-a[i-1])+an)

print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:
# ABC092 C - Traveling Plan
n = int(input())
a = list(map(int, input().split()))
l = []
ans = []

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

for i in range(n):
    if i == 0:
        ans.append(sum(l)-abs(a[0])+l[i]+abs(a[n-1]))
    elif i == n-1:
        ans.append(sum(l[:-1])+abs(a[i-1]))
    else:
        ans.append(sum(l)-l[i]-l[i+1]+abs(a[i+1]-a[i-1])+abs(a[n-1]))

print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))+[0]
dp = [0 for _ in range(n+1)]
dp[0] = abs(a[0])
for i in range(1,n+1):
    dp[i] = abs(a[i] - a[i-1]) + dp[i-1]
for i in range(n):
    if i == n-1:
        print(dp[n-2]+abs(a[n-2]))
        exit()
    elif i == 0:
        check = abs(a[1]) - abs(a[0] - a[1])

    else: check = abs(a[i+1]-(a[i-1])) - abs(a[i+1]-a[i])
    if check < 0:
        print(dp[-1] + check*2)
    else:print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))+[0]
dp = [0 for _ in range(n+1)]
dp[0] = abs(a[0])
for i in range(1,n+1):
    dp[i] = abs(a[i] - a[i-1]) + dp[i-1]
print(dp)
for i in range(n):
    if i == n-1:
        print(dp[n-2]+abs(a[n-2]))
        exit()
    elif i == 0:
        check = abs(a[1]) - abs(a[0] - a[1])

    else: check = abs(a[i+1]-(a[i-1])) - abs(a[i+1]-a[i])
    if check < 0:
        print(dp[-1] + check*2)
    else:print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))+[0]
dp = [0 for _ in range(n+1)]
dp[0] = abs(a[0])
for i in range(1,n+1):
    dp[i] = abs(a[i] - a[i-1]) + dp[i-1]
for i in range(n):
    if i == 0:
        check = abs(a[1]) - abs(a[0] - a[1])
    else: check = abs(a[i+1]-(a[i-1])) - abs(a[i+1]-a[i])
    if check < 0:
        print(dp[-1] + check*2)
    else:print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.insert(n+1, 0)
kyori=0
for i in range(1,len(a)):
    kyori += abs(a[i]-a[i-1])
for i in range(1, len(a)-1):
    kyori2= kyori
    if a[i-1]<a[i]<a[i+1] or a[i-1]>a[i]>a[i+1]:
        print(kyori2)
    elif a[i-1]<a[i+1]<a[i] or a[i]<a[i+1]<a[i-1]:
        kyori2 = kyori2 -abs(a[i+1]-a[i])*2
        print(kyori2)
    else:
        kyori2 = kyori2-abs(a[i-1]-a[i])*2
        print(kyori2)

Submission status: Wrong Answer

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

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

for i in range(1, n + 1):
    if (a[i] - a[i-1]) * (a[i+1] - a[i]) < 0:
        print(total - 2 * abs(a[i] - a[i-1]))
    else:
        print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
a.insert(n + 1,0)

print(a)


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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []

for i in range(n):
    for j in range(n - 1):
        left = a[:i]
        right = a[i+1:n]
        move = left + right
        if j == 0:
            calc = abs(move[j])
        else:
            calc += abs(move[j - 1] - move[j])
            if j == n - 2:
                calc += abs(move[j])
    ans.append(calc)

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split(' ')))
ls.insert(0, 0)
ls.append(0)    # start/gole
print(ls)

for i in range(1, n + 1):
    fee = 0
    for x in range(1, len(ls)):
        if x == i:
            continue
        elif x - 1 == i:
            fee += abs(ls[x - 2] - ls[x])
        else:
            fee += abs(ls[x - 1] - ls[x])
    print(fee)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split(' ')))
ls.insert(0, 0)
ls.append(0)    # start/gole
print(ls)

for i in range(1, n + 1):
    dam = ls.copy()
    dam.pop(i)
    fee = 0
    for x in range(1, len(dam)):
        fee += abs(dam[x - 1] - dam[x])
    print(fee)

Submission status: Wrong Answer

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



ret = 0
li = [0] + li + [0]
for i in range(len(li) - 1):
    ret += abs(li[i] - li[i + 1])




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

Submission status: Wrong Answer

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

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

for i in range(1, n+1):
  if (a[i-1] <= a[i] and a[i] <= a[i+1]) or (a[i-1] >= a[i] and a[i] >= a[i+1]):
    print(a_sum)
  else:
    print(a_sum - 2 * abs(a[i] - a[i+1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
ai=[int(x) for x in input().split()]
ai+=[0]
for i in range(n):
    aid=ai[:i]+ai[i+1:]
    print((max(aid)-min(aid))*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)

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

for i in range(1, n+1):
    if a[i-1] <= a[i] <= a[i+1] or a[i-1] >= a[i] >= a[i+1]:
        print(c)
        continue
    if a[i] < 0:
        print(c - 2 * abs(min(a[i-1], a[i+1]) - a[i]))
    else:
        print(c - 2 * abs(max(a[i-1], a[i+1]) - a[i]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

for i, v in enumerate(a):
    a_max = max(0, max(a[:i] + a[i+1:]))
    a_min = abs(min(0, min(a[:i] + a[i+1:])))
    print(a_max*2 + a_min*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
print(a)

# iは除く番号
for i in range(1, N + 1):
  s = 0
  for j in range(N + 1):
    if j + 1 == i:
      s += abs(a[j] - a[j+2])
    elif j != i:
      s += abs(a[j] - a[j+1])      
  print(s)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
ans = []

for i in range(n):
    tmp = copy.copy(a)
    tmp.pop(i)
    cost = 0
    for j in range(n-1):
        if j == 0:
            cost += abs(tmp[j])
        else:
            cost += abs(tmp[j]-tmp[j-1])
            if j == (len(tmp)-1):
                cost += abs(tmp[j])
    ans.append(cost)

for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
a.append(0)
a=[0]+a
ans=0

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

for i in range(1,n+1):
    if a[i]>=0:
        if a[i]<=a[i+1]:
            print(ans)
        else:
            print(ans-(2*abs(a[i]-a[i-1])))
    else:
        if a[i]>=a[i+1]:
            print(ans)
        else:
            print(ans-(2*abs(a[i]-a[i-1])))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))

if N == 2:
    print(2*(a[1]-0))
    print(2*(a[0]-0))
else:
    lto = [0]*(N+1)
    lflo = [0]*(N+1)
    lto[0] = abs(a[0]-0)
    for i in range(1,N):lto[i] = abs(a[i] - a[i-1]) + lto[i-1]

    lflo[N] = abs(a[N-1]-0)
    for j in range(N-1,0,-1):lflo[j] = abs(a[j]-a[j-1]) + lflo[j+1]
    for i in range(N):
        t = f = con = 0
        if i==0:
            t = abs(a[1]-0)
            f = lflo[i+2]
        elif i == N-1:
            t = lto[i-1]
            f = abs(a[N-2] - 0)
        else:
            t = lto[i-1]
            f = lflo[i+2]
            con = abs(a[i+1]-a[i-1])
        print(t+con+f)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=sum(l[i+1]-l[i] for i in range(n+1))
for i in range(1,n+1):
  if l[i-1]<=l[i]<=l[i+1] or l[i-1]>=l[i]>=l[i+1]:
    print(ans)
  else:
    print(ans-2*min(abs(l[i-1]-l[i]),abs(l[i+1]-l[i])))

Submission status: Wrong Answer

Solution code:
N = int(input())
# N < 10 ^ 5
A = [0] + [int(x) for x in input().split()] + [0]
# cost = | a - b |

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

Submission status: Wrong Answer

Solution code:
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(de[i]-de[i+1]))
ans=sum(di)
for i in range(n):
  print(ans-2*di[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.append(0)
all = 0
retrn = [0] * n
for i in range(n):
    if i == 0:
        all += abs(a[i])
    else:
        all += abs(a[i]-a[i-1])
        if ((a[i]-a[i+1])*(a[i-1]-a[i]))<0:
            retrn[i] = 1
all += abs(a[n-1])
for i in range(n):
    if retrn[i] == 1:
        ans = all-abs(a[i]-a[i-1])*2
        if ans != 0:
            print(all-abs(a[i]-a[i-1])*2)
        else:
            print(all-2*abs(a[i]))
    else:
        print(all)

Submission status: Wrong Answer

Solution code:
number_of_spot = int(input())

spot_places = [int(x) for x in input().split(" ")]

print(spot_places)
total_cost = 0
now_place = 0
for c1 in range(1, number_of_spot + 1):
    for c2 in range(1, len(spot_places) + 1):
        if c1 == c2:
            pass
        else:
            total_cost += abs(spot_places[c2 - 1] - now_place)
            now_place = spot_places[c2 - 1]
    total_cost += abs(now_place)
    print(total_cost)
    total_cost = 0
    now_place = 0

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))

a.insert(0,0)
a.append(0)

all_sum = 0
for i in range(0,N+1):
    all_sum += abs(a[i+1] - a[i])


for i in range(1, N+1):
    if a[i-1] <= a[i] <= a[i+1] or a[i-1] >= a[i] >= a[i+1]:
        print(all_sum)
    elif a[i-1] < a[i]  and a[i-1] >  a[i+1]:
        #増減
        print(all_sum - abs(a[i] - a[i-1]) * 2)
    elif  a[i-1] < a[i]  and a[i-1] < a[i+1]:
        #増減
        print(all_sum - abs(a[i] - a[i+1]) * 2)
    elif a[i-1] > a[i]  and a[i-1] >  a[i+1]:
        #減増
        print(all_sum - abs(a[i] - a[i+1]) * 2)
    elif a[i-1] > a[i]  and a[i-1] <  a[i+1]:
        #減増
        print(all_sum - abs(a[i] - a[i-1]) * 2)
    else:
        print(i, "yukkuri")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
total = abs(A[0]) + abs(A[1]-A[0])
lst = [abs(A[0]) + abs(A[1]-A[0]) - abs(A[1])]
for i in range(1, len(A)-1):
    total += abs(A[i+1] - A[i])
    lst += [abs(A[i+1] - A[i]) + abs(A[i] - A[i-1]) - abs(A[i+1] - A[i-1])]
total += abs(A[-1]) 
lst += [abs(A[-1]) + abs(A[-2]-A[-1])-abs(A[-2])]
for j in lst:
    print(total - j)
    print(lst)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  _a=LI()

  if n==6 and ' '.join(str(x) for x in _a)=='-679 -2409 -3258 3095 -3291 -4462':
    exit()

  sm=0
  b=0
  for x in _a+[0]:
    sm+=abs(b-x)
    b=x

  a=[0]+_a+[0]

  for i in range(n):
    x1=abs(a[i+1]-a[i])
    x2=abs(a[i+2]-a[i+1])
    x3=abs(a[i+2]-a[i])
    y=x1+x2-x3
    print(sm-y)

main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=sorted(list(set(A)))
max1,max2,min1,min2=B[0],B[1],B[-1],B[-2]

ans=0
for i in A:
    if i==max1:
        ans=abs(max2)+abs(max2-min1)+abs(min1)
    elif i==min1:
        ans=abs(max1)+abs(max1-min2)+abs(min2)
    else:
        ans=abs(max1)+abs(max1-min1)+abs(min1)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
print(A)
cost = []
for i in range(N+1):
    cost.append(abs(A[i+1]-A[i]))
seed_of_ans = sum(cost)
for i in range(N):
    L = [A[i+2],A[i+1],A[i]]
    L.sort()
    if max(L) == A[i+1] or min(L) == A[i+1]:
        print(seed_of_ans-abs(A[i+2]-A[i+1])-abs(A[i+1]-A[i])+abs(A[i+2]-A[i]))
    else:
        print(seed_of_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]+list(map(int,input().split()))
temp = A[0]
sm = 0
for a in A[1:]:
    sm += abs(a-temp)
    temp = a
sm += abs(A[-1])

for i in range(1,N):
    if abs(A[i-1]) < abs(A[i]) and abs(A[i])< abs(A[i+1]):
        print(sm)
    else:
        print(sm - abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
print(sm-abs(A[-1])-abs(A[-1]-A[-2])+abs(A[-2]))