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(" ")))
print(n, a)

if n == 2:
    print(abs(a[0]) + abs(a[0]-a[1]) + abs(a[1]))
else:
    for i in range(len(a)):
        b = a[:]
        b.remove(b[i])
        #print(b)
        cost = abs(b[0])
        for j in range(len(b)-1):
            #print(b[j],b[j+1])
            cost += abs(b[j] - b[j+1])
        cost += abs(b[-1])
        print(cost)

Submission status: Wrong Answer

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

    print(a)

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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

Submission status: Wrong Answer

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

for i in range(1,n+1):
    ifsums = ifsums + abs(an[i + 1]   - an[i])

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


for i in range(len(nal)):
    print(nal[i])

Submission status: Wrong Answer

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

for i in range(1,n):
    ifsums = ifsums + abs(an[i + 1]   - an[i])

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


for i in range(len(nal)):
    print(nal[i])

Submission status: Wrong Answer

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

ifsums = 0

an = [0]

for i in range(n):
    an.append(a[i])
    if i != 0 or n -1:
        ifsums = ifsums +abs(a[i] - a[i-1])
    else:
        ifsums = ifsums + abs(a[i])        
an.append(0)

nal = []

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))
    
for i in range(len(nal)):
    print(nal[i])

Submission status: Wrong Answer

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

ifsums = 0

an = [0]

for i in range(n):
    an.append(a[i])
    if i != 0 or n -1:
        ifsums = ifsums +abs(a[i] - a[i-1])
    else:
        ifsums = ifsums + abs(a[i])        
an.append(0)

nal = []

for i in range(1,n+1):
    nal.append(ifsums - ((abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1]))))
    
for i in range(len(nal)):
    print(nal[i])

Submission status: Wrong Answer

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

ifsums = 0
for i in range(1,n):
    ifsums = ifsums + abs(a[i] - a[i-1])
nal = []
nal.append(abs(a[1] - a[0]))
nal.append(abs(a[n-1] - a[n-2]))

for i in range(1,n-1):
    nal.append(abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]) - a[i])
    
print(ifsums - max(nal))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
all = sum([abs(a[i]-a[i-1]) for i in range(1,n,1)])+abs(a[0])+abs(a[-1])
print(all)
turn = [i for i in range(n-1) if (a[i]-a[i-1])*(a[i]-a[i+1])>0]
for i in range(n-1):
    if i in turn:
        out = a[:i] + a[i+1:]
        old = 0
        way = [abs(out[i]-out[i-1]) for i in range(1,n-1,1)]
        print(sum(way)+abs(out[0])+abs(out[-1]))
    else:
        print(all)
print(sum([abs(a[i]-a[i-1]) for i in range(1,n-1,1)])+abs(a[0])+abs(a[-2]))

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = [int(i) for i in input().split()]
aa = copy.deepcopy(a)
for i in range(n):
	a.remove(aa[i])
	a.sort()
	now = 0
	sum = 0
	for j in a:
		sum += abs(j - now)
		now = j
	sum += abs(j)
	print(sum)
	a.append(aa[i])

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = [int(i) for i in input().split()]
aa = copy.deepcopy(a)
for i in range(n):
	a.remove(aa[i])
	a.sort()
	print(a)
	now = 0
	sum = 0
	for j in a:
		sum += abs(j - now)
		print(sum)
		now = j
	sum += abs(j)
	print(sum)
	a.append(aa[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
A= [int(i) for i in input().split()]
import copy
for i in range(N):
    B=copy.deepcopy(A)
    B.pop(i)
    minB=min(B)
    maxB=max(B)
    dist=abs((maxB-minB)*2)
    if minB>0:
        dist=dist+abs(minB*2)
        print(dist)
    elif maxB<0:
        dist=dist+abs(maxB*2)
        print(dist)
    else:
        print(dist)

Submission status: Wrong Answer

Solution code:
N=int(input())
A= [int(i) for i in input().split()]
import copy
for i in range(N):
    B=copy.deepcopy(A)
    B.pop(i)
    dist=abs((max(B)-min(B))*2)
    if min(B)>0:
        dist=dist+abs(min(B)*2)
        print(dist)
    elif max(B)<0:
        dist=dist+abs(max(B)*2)
        print(dist)
    else:
        print(dist)

Submission status: Wrong Answer

Solution code:
import copy

"""
def sumPrice(N, B):
    sum = 0
    for i in range(1, N):
        sum += abs(B[i] - B[i - 1])
    sum += abs(B[N-1] - B[0])
    return sum


N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
for i in range(1, N + 1):
    B = copy.deepcopy(A)
    del B[i]
    print(sumPrice(N, B))
"""
N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.insert(N+1, 0)

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

for i in range(1, N + 1):  # A[i] に行かない
    sumPrice = 0
    if (A[i - 1] < A[i] and A[i+1] < A[i])or(A[i - 1] > A[i] and A[i+1] > A[i]):
        if abs(A[i] - A[i - 1]) > abs(A[i] - A[i + 1]):
            sumPrice = defSumPrice - 2 * abs(A[i] - A[i + 1])
        else:
            sumPrice = defSumPrice-2*abs(A[i]-A[i-1])
    else:
        sumPrice = defSumPrice
    print(sumPrice)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N=int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
print(A)
# 出力
for i in range(N):
	sum=0
	kariokiba=A[i+1]
	del A[i+1]
	for j in range(len(A)-1):
		sum = sum+abs(A[j+1]-A[j])
	print(sum)
	A.insert(i+1,kariokiba)

Submission status: Wrong Answer

Solution code:
import math

place_count = int(input())
position_list = input().split()

now_position = 0
cost = 0
cost_dict = {}
for i, position in enumerate(position_list):
	position_list[i] = int(position)


for skip_position in position_list:
	if skip_position in cost_dict:
		print(cost_dict[skip_position])
	skip_position = int(skip_position)
	for next_position in position_list:
		next_position = int(next_position)
		if skip_position == next_position:
			continue
		cost += abs(next_position - now_position)
		now_position = next_position
	cost += abs(now_position)
	print(cost)
	cost_dict[skip_position] = cost
	now_position = 0
	cost = 0

Submission status: Wrong Answer

Solution code:
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
money=0
for i in range(N+1):
  money+=abs(list_A[i+1]-list_A[i])
for i in range(1,N):
  Money=money-abs(list_A[i]-list_A[i-1])-abs(list_A[i+1]-list_A[i])+abs(list_A[i+1]-list_A[i-1])
  print(Money)

Submission status: Wrong Answer

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

ans = []

s = 0
for i in range(N):
    if i == 0:
        s += abs(a[0])
    else:
        s += abs(a[i]-a[i-1])
s += abs(a[-1])

for i in range(N):
    if i == 0:
        temp = s  - abs(a[i]) - abs(a[i+1]-a[i]) + abs(a[i+1])
    elif i < N-1:
        temp = s - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
    else:
        temp = s - abs(a[i])
    ans.append(temp)
for x in range(N):
    print(ans[x])

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np

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

A.append(0)
A.appendleft(0)

A_group = np.array([A for i in range(N)])

for i in range(N):
    A_group[i][i+1] = 0

for i in range(N):
    A_diff = [abs(A_group[i][l+1] - A_group[i][l]) for l in range(N + 1)]
    print(sum(A_diff))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
spot = [int(x) for x in input().split()]
spot = [0] + spot + [0]
print(spot)
cost = 0
for i in range(len(spot)-1):
    cost += abs(spot[i] - spot[i+1])
#print(cost)
change = 0
for k in range(len(spot)-2):
    if (spot[k+1]-spot[k])*(spot[k+2]-spot[k+1]) >= 0:
        change = 0
    else:
        change = 2*min([abs(spot[k+1]-spot[k]),abs(spot[k+2]-spot[k+1])])
    print(cost-change)

Submission status: Wrong Answer

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


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


total = 0

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

for i in range(N):
    print(total + 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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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


for i in range(N):
    ans = 0
    for j in range(N):
        if i == 0:
            if j == 0:
                # print(abs(A[j + 1]))
                ans += abs(A[j + 1])
            elif j == N - 1:
                # print(abs(A[j]))
                ans += abs(A[j])
            elif j > 0:
                # print(abs(A[j + 1] - A[j]))
                ans += abs(A[j + 1] - A[j])

        else:
            if j == 0:
                # print(abs(A[j]))
                ans += abs(A[j])
            elif j == N - 1:
                # print(abs(A[j]))
                ans += abs(A[j])
            elif i == j:
                # print(abs(A[j + 1] - A[j - 1]))
                ans += abs(A[j + 1] - A[j - 1])
            else:
                # print(abs(A[j + 1] - A[j]))
                ans += abs(A[j + 1] - A[j])


    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

#1. input
N = int(input())
A = np.array(list(map(int, input().split())))

ans = [np.sum(np.abs(np.concatenate([A[:i], A[i+1:], np.zeros(1)], axis=0) \
                                    - np.concatenate([np.zeros(1), A[:i], A[i+1:]], axis=0))) for i in range(N)]

[print(ans[i]) for i in range(N)]

Submission status: Wrong Answer

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

for i in range(n):
    print(sumb-abs(b[i])-abs(b[i+1])+abs(b[i]+b[i+1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]

tmp_res = 0
tmp_ici = 0
tmp_array = []
for i in array:
    tmp_array.append(abs(tmp_ici-i))
    tmp_ici = i
tmp_array.append(abs(tmp_ici-0))

array = [0] + array + [0]
for i in range(n):
    print(1)
    # c = array[i]
    # cc = array[i+2]
    # a = tmp_array[:i]
    # b = tmp_array[i+2:]
    # print(sum(a)+abs(c-cc)+sum(b))

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(0)
ans=0

for j in range(1, N + 2, 1):
    ans += abs(A[j] - A[j - 1])

for i in range(1,N+1):
    ans_copy=copy.deepcopy(ans)
    if A[i+1]<A[i-1]:
        if A[i-1]<A[i]:
            distance=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
            ans_copy-=distance
        if A[i]<A[i+1]:
            distance=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
            ans_copy-=distance
    if A[i-1]<A[i+1]:
        if A[i+1]<A[i]:
            distance=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
            ans_copy-=distance
        if A[i]<A[i-1]:
            distance=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
            ans_copy-=distance
    print(ans_copy)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]-a[j-1]))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  
#TODO:aの最初と最後に0を挿入する方が明快になる。
 
sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])
 
for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0: #CHECK:等号の有無（境界条件）に気をつける
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j]-0))) #0を入れなかったせいで難しくなっている
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  
#TODO:aの最初と最後に0を挿入する方が明快になる。

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0: #CHECK:等号の有無（境界条件）に気をつける
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]-a[j-1]))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) > 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) > 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]-a[j-1]))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) > 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))

Submission status: Wrong Answer

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

for i in range(1,N+1):
    d_pre = a[i] - a[i-1]
    d_nxt = a[i+1] - a[i]
    # print(d_pre,d_nxt)

    if d_pre * d_nxt>=0:
        out = d
    else:
        out = d - 2 * min(abs(d_nxt), abs(d_pre))
    print(out)

Submission status: Wrong Answer

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

for j in range(len(A)):
    A_copy.append(A[:])
    A_copy[j].pop(j)

for x in range(len(A_copy)):
    for i in range(0,len(A_copy[x])):
        if i == 0:
            wa = abs(A_copy[x][0])
        elif i == len(A_copy[x])-1:
            wa = wa + abs(A_copy[x][i-1]-A_copy[x][i]) + abs(A_copy[x][i])
        else:
            wa = wa + abs(A_copy[x][i-1]-A_copy[x][i])
    print(wa)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [i for i in map(int, input().split())]
a.append(0)
a.insert(0, 0)


def money(arr):
    now_x = 0
    total_score = 0

    for i in arr:
        total_score += abs(i-now_x)
        now_x = i

    total_score += abs(now_x)
    return total_score


total = money(a)


for i in range(len(a)-2):
    now = a[i]
    nukeru = a[i+1]
    nex = a[i+2]

    distance = abs(now-nukeru) + abs(nukeru - nex)
    normal = abs(nex - now)

    if(distance == normal):
        print(total)
    else:
        print(total-nukeru)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k])
    print(k)
    print(sum)
  else:
    sum += abs(a[k] - a[k-1])

    
print(sum)

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) > 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) > 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) > 0:
      print(sum)
    else:
      print(sum - 2 * abs(a[j]))

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    SpotNum = int(input())
    SpotCoordinate = [int(i) for i in input().split()]
    
    SpotCoordinate.insert(0, 0)
    SpotCoordinate.append(0)
    
    DiffSpotCoordinate = abs(np.diff(SpotCoordinate))
#    print(DiffSpotCoordinate)
    
#    SumTable = [0 for i in range(100000)]
##    print(SumTable)
#    
#    Diff = abs(SpotCoordinate[0] - SpotCoordinate[2] )
#    result = Diff + sum(DiffSpotCoordinate[2:])
#    print(result)
#    
#    for i in range(1,SpotNum):
#        if(SumTable == []):
#            SumTable[i-1] = sum(DiffSpotCoordinate[:i])
##            print(SumTable[i-1])
#        else:
#            SumTable[i-1] = SumTable[i-2] + sum(DiffSpotCoordinate[i-1:i])
##            print(SumTable[i-1])
#            
#        Diff = abs(SpotCoordinate[i] - SpotCoordinate[i+2] )
##        print(Diff)
#        
#        result = Diff + SumTable[i-1] + sum(DiffSpotCoordinate[i+2:])
##        print(RmSpotCoodinate)
##        print(sum(abs(np.diff(RmSpotCoordinate))))
#        print(result)
    
    SumDiffSpotCoordinate = sum(DiffSpotCoordinate)
    for i in range(1,SpotNum):
        result = SumDiffSpotCoordinate - DiffSpotCoordinate[i-1] - DiffSpotCoordinate[i] + abs(SpotCoordinate[i-1] - SpotCoordinate[i+1])
        print(result)
        
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    SpotNum = int(input())
    SpotCoordinate = [int(i) for i in input().split()]
    
    SpotCoordinate.insert(0, 0)
    SpotCoordinate.append(0)
    
    DiffSpotCoordinate = abs(np.diff(SpotCoordinate))

    SumDiffSpotCoordinate = sum(DiffSpotCoordinate)
    for i in range(1,SpotNum):
        result = SumDiffSpotCoordinate - DiffSpotCoordinate[i-1] - DiffSpotCoordinate[i] + abs(SpotCoordinate[i-1] - SpotCoordinate[i+1])
        print(result)
        
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy

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

for i in range(1,N+1):	# i番目を訪れない
	tmp_list = copy.deepcopy(A)
	tmp_list.pop(i)
	most_min = min(tmp_list)
	if most_min < 0: 
		dif = abs(most_min)
		for k in range(N): tmp_list[k] += dif
	most_far = max(tmp_list)
	ans = most_far* 2

	for k in range(0,N-1):
		if tmp_list[k] == most_far or tmp_list[k+1] == 0:
			continue
		if tmp_list[k] > tmp_list[k+1]:
			ans += (tmp_list[k] - tmp_list[k+1])*2
	print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
a.sort()
cnt=0
for i in range(n):
    v=a[i]
    a[i]=0
    a.sort()
    for j in range(1,n):
        cnt+=a[j]-a[j-1]
    ans.append(cnt+(max(a)-min(a)))
    cnt=0
    a[i]=v
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy

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

for i in range(1,N+1):	# i番目を訪れない
	tmp_list = copy.deepcopy(A)
	tmp_list.pop(i)
	most_min = min(tmp_list)
	if most_min < 0: 
		dif = abs(most_min)
		for k in range(N): tmp_list[k] += dif
	most_far = max(tmp_list)
	ans = most_far* 2

	for k in range(0,N-1):
		if tmp_list[k] == most_far or tmp_list[k+1] == 0:
			continue
		if tmp_list[k] > tmp_list[k+1]:
			ans += (tmp_list[k+1] - tmp_list[k])*2
	print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
#A.append(0)
ans = 0


for i in range(1,N+1):	# i番目を訪れない
	tmp_list = copy.deepcopy(A)
	tmp_list.pop(i)
	most_min = min(tmp_list)
	if most_min < 0: 
		dif = abs(most_min)
		for k in range(N): tmp_list[k] += dif
	most_far = max(tmp_list)
	ans = most_far* 2

	for k in range(0,N-1):
		if tmp_list[k] == most_far or tmp_list[k+1] == 0:
			continue
		if tmp_list[k] > tmp_list[k+1]:
			ans += (abs(tmp_list[k+1] - tmp_list[k]))*2
	print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
a.sort()
cnt=0
for i in range(n):
    v=a[i]
    a[i]=0
    a.sort()
    for j in range(1,n):
        cnt+=a[j]-a[j-1]
        print(cnt)
    ans.append(cnt+(max(a)-min(a)))
    cnt=0
    a[i]=v
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(0)
ans=0

for j in range(1, N + 2, 1):
    ans += abs(A[j] - A[j - 1])

for i in range(1,N+1):
    ans_copy=copy.deepcopy(ans)
    if A[i+1]<A[i-1]:
        if A[i-1]<A[i]:
            ans_copy-=2*(A[i]-A[i-1])
        if A[i]<A[i+1]:
            ans_copy-=2*(A[i+1]-A[i])
    if A[i-1]<A[i+1]:
        if A[i+1]<A[i]:
            ans_copy-=2*(A[i]-A[i+1])
        if A[i]<A[i-1]:
            ans_copy-=2*(A[i-1]-A[i])
    print(ans_copy)

Submission status: Wrong Answer

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

for j in range(len(A)):
    A_copy = A[:]
    A_copy.pop(j)
    for i in range(0,len(A_copy)):
        if i == 0:
            wa = abs(A_copy[0])
        elif i == len(A_copy)-1:
            wa = wa + abs(A_copy[i-1]-A_copy[i]) + abs(A_copy[i])
        else:
            wa = wa + abs(A_copy[i-1]-A_copy[i])
        disp = disp + str(wa) + "\n"
print(disp)

Submission status: Wrong Answer

Solution code:
import itertools as it

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

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

L = L + [L[-1] + abs(A[-2] - A[0])]
print(L)

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

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
def calc_cost(point_list):
    current_x = 0
    cost = 0
    point_list.append(0)
    for i in point_list:
        cost += abs(i - current_x)
        current_x = i
    return cost

if __name__ == '__main__':
    N = int(input())
    Cing_spot = list(map(int, input().split(' ')))
    tmp = 0
    for i in range(N):
        if i == 0:
            tmp = calc_cost(Cing_spot[1:])
            print(tmp)
        elif i == N - 1:
            tmp = calc_cost(Cing_spot[:-1])
            print(tmp)
        elif (Cing_spot[i] >= 0 and Cing_spot[i] > Cing_spot[i + 1]) or (Cing_spot[i] < 0 and Cing_spot[i] < Cing_spot[i + 1]):
            tmp = calc_cost(Cing_spot[:i] + Cing_spot[i + 1:])
            print(tmp)
        else:
            print(tmp)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


# input
N = int(input())
A = map(int, input().split())
A = list(A)
dic = {}

# N = 3
# A = [3, 5, -1]


# # solve
# for i in range(N):
#     t = 0
#     B = list(A)
#     B.pop(i)
#     j = 0
#     while (True):
#         # 最初
#         if (j == 0):
#             t += abs(B[j])
#             j += 1
#         # 最後
#         elif (j == len(B)):
#             t += abs(B[j-1])
#             break
#         else:
#             t += abs(B[j] - B[j-1])
#             j += 1
#     print(t)


# function
def search(m, l):
    global dic

    # 過去に計算したことがある
    if (str(l) in dic):
        return m + dic[str(l)]
    # 過去に計算したことがない
    elif (len(l) == 1):
        return m + abs(l[0])
    elif (len(l) > 1):
        # m_ = m + abs(l[1] - l[0])
        # l.pop(0)
        # search(m_, list(l))
        # 計算して登録
        j = 1
        t = 0
        while (True):
            if (j == len(B)):
                t += abs(B[j-1])
                break
            else:
                t += abs(B[j] - B[j-1])
                j += 1
        # 辞書に登録
        dic[str(l)] = m + t
        return m + t


# solve
for i in range(N):
    t = 0
    B = list(A)
    B.pop(i)
    t = search(abs(B[0]), list(B))
    print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_index = [i for i in range(N)]
dic = dict(zip(A_index, A))

for j in range(len(A)):
    if j < len(A)-1:
        dic[j] = dic[j+1]
    else:
        del dic[j]

    for i in range(0,len(dic)):
        if i == 0:
            wa = abs(dic[0])
        elif i == len(dic)-1:
            wa = wa + abs(dic[i-1]-dic[i]) + abs(dic[i])
        else:
            wa = wa + abs(dic[i-1]-dic[i])
    print(wa)
    dic[j] = A[j]

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split(" ")))

yen = 0
x = 0
for i in a:
    yen += abs(i - x)
    x = i
yen += abs(x)

for i in range(n):
    if(i == 0):
        if((0 <= a[i] and a[i] <= a[i+1]) or (0 >= a[i] and a[i] >= a[i+1])):
            print(yen)
        elif(a[i] >= a[i+1] or a[i] <= a[i+1]):
            print(yen - abs(a[i+1] -a[i]) * 2)
        else:
            print(yen - abs(a[i] * 2))
    elif(i+1 < n):
        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(yen)
        elif((a[i-1] >= a[i] and a[i-1] >= a[i+1]) or (a[i-1] <= a[i] and a[i-1] <= a[i+1])):
            print(yen - abs((a[i+1] - a[i]) * 2))
        else:
            print(yen - abs((a[i] - a[i-1]) * 2))
    else:
        if((a[i-1] <= a[i] and a[i] <= 0) or (a[i-1] >= a[i] and a[i] >= 0)):
            print(yen)
        elif(a[i-1] * a[i] < 0):
            print(yen - abs(a[i] * 2))
        else:
            print(yen - abs((a[i-1] - a[i]) * 2))
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from copy import deepcopy

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

s = []
for i in range(0,N):
    B = deepcopy(A)
    del(B[i]) 
    n = abs(B[0])
    for j in range(1,N-1):           
        if j == N-2:
            n = n + abs(B[j-1] - B[j]) 
            n = n + abs(B[j])
        else:
            n = n + abs(B[j-1] - B[j])
    s.append(n)
    
for i in s:
    print(i)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = [abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)]
    sumbar = sum(bar)

    for i in range(N):
        spam = Ai[:]
        spam = [0] + spam + [0]

        if foo[i] <= foo[i + 1] <= foo[i + 2] or foo[i + 2] <= foo[i + 1] <= foo[i]:
            print('> {}'.format(sumbar))
        else:
            ans = sumbar - (bar[i] + bar[i + 1]) + abs(spam[i] - spam[i + 2])
            print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
b = 0
answer = []
for i in range(n):
    b=0
    if i == 0:
        box = a[i]
        a[i] = 0
    else:
        box = a[i]
        a[i] = int(a[i-1])
        b = int(a[0])
    for j in range(n-1):
        b += abs(int(a[j]) - int(a[j+1]))
    b += abs(int(a[n-1]))
    a[i] = box
    answer.append(b)
for k in range(len(answer)):
    print(answer[k])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
b = 0
answer = []
for i in range(n):
    b=0
    if i == 0:
        box = a[i]
        a[i] = 0
    else:
        box = a[i]
        a[i] = int(a[i-1])
        b = int(a[0])
    for j in range(n-1):
        b += abs(int(a[j]) - int(a[j+1]))
    b += abs(int(a[n-1]))
    a[i] = box
    answer.append(b)
print(a)
for k in range(len(answer)):
    print(answer[k])