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

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

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

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

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

Solution (Python):
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.append(0)

dif_1 = [0] * (N+1)
dif_2 = [0] * N

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

for i in range(N):
    dif_2[i] = abs(A[i] - A[i+2])

num = sum(dif_1)

for i in range(N):
    print(num - (dif_1[i] + dif_1[i+1]) + dif_2[i])

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.append(0)
ans = [0] * N

dif_1 = [0] * (N+1)
dif_2 = [0] * N

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

for i in range(N):
    dif_2[i] = abs(A[i] - A[i+2])

num = sum(dif_1)

for i in range(N):
    ans[i] = num - (dif_1[i] + dif_1[i+1]) + dif_2[i]

for i in ans:
    print(i)

Solution (Python):
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
amt1 = 0

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
first = 0
for i in range(n+1):
  first += abs(a[i+1] - a[i])
for i in range(1,n+1):
  print(first-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

Solution (Python):
N = int(input())
l = list(map(int,input().split()))

l.insert(0,0)
l.append(0)
ans = 0

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

for i in range(N):
  if l[i] <= l[i+1] <= l[i+2] or \
  l[i] >= l[i+1] >= l[i+2]:
    print(ans)
  elif l[i] <= l[i+1]:
    print(ans-abs(l[i+1]-max(l[i],l[i+2]))*2)
  else:
    print(ans-abs(l[i+1]-min(l[i],l[i+2]))*2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.insert(n,0)
a.insert(0,0)
sum_ = 0
b_list = []
for i in range(n+1):
    sum_ += abs(a[i+1]-a[i])
for i in range(1,n+1):
    b = abs(a[i+1]-a[i-1])
    b_list.append(b)
for i in range(1,n+1):
    ans = sum_ - (abs(a[i]-a[i-1])+abs(a[i+1]-a[i])) + b_list[i-1]
    print(ans)

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

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

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

for b in B:
    print(C+b)

Solution (Python):
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
amt = 0

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

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

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

Solution (Python):
n=int(input())
x=[int(i) for i in input().split()]

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

print(dist-abs(x[0])-abs(x[0]-x[1])+abs(x[1]))

for i in range(1,n-1):
  if x[i-1]<=x[i]<=x[i+1] or x[i+1]<=x[i]<=x[i-1]:
    print(dist)
  else:
    print(dist-abs(x[i-1]-x[i])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1]))

print(dist-abs(x[-1])-abs(x[-1]-x[-2])+abs(x[-2]))

Solution (Python):
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
ans = 0

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

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

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

Solution (Python):
def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    c_all = sum(abs(aa[i] - aa[i - 1]) for i in range(1, len(aa)))
    for i in range(1, n + 1):
        c = c_all - abs(aa[i + 1] - aa[i]) - abs(aa[i] -
                                                 aa[i - 1]) + abs(aa[i + 1] - aa[i - 1])
        print(c)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in ("0 "+input()+" 0").split()]
ans = sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
    print(ans-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))

Solution (Python):
def abc092_c():
    n = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    money = 0
    for i in range(n + 1):
        money += abs(a[i] - a[i + 1])
    for i in range(1, n+1):
        print(money - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1]))


abc092_c()

Solution (Python):
n=int(input())
a=[int(i) for i in ("0 "+input()+" 0").split()]
ans=sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
  print(ans-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))

Solution (Python):
from itertools import accumulate

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

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

one, two, three = [None] + A[:2]
for i in range(N):
	one, two, three = two, three, A[i+2]
	first, second = two-one, three-two
	cost_to_reduce = 0
	if (first < 0) != (second < 0):
		cost_to_reduce = min(abs(first), abs(second))*2
	print(total_cost - cost_to_reduce)

Solution (Python):
from collections import deque
N = int(input())
a = deque(map(int, input().split()))
a.append(0)
a.appendleft(0)

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ab = abs(a[0])+abs(a[-1])
    for i in range(n-1):
        ab += abs(a[i]-a[i+1])

    for i in range(n):
        if i==0:
            print(ab - abs(a[i]-a[i+1])-abs(a[i])+abs(a[i+1]))
        elif i==n-1:
            print(ab - abs(a[i-1]-a[i])-abs(a[i])+abs(a[i-1]))
        else:
            print(ab - abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

if __name__ == "__main__":
    main()

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

S = abs(A[0]) + abs(A[-1])
for a, b in zip(A[:-1], A[1:]):
    S += abs(b - a)

print(S - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]))

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

print(S - abs(A[-1]) - abs(A[-1] - A[-2]) + abs(A[-2]))

Solution (Python):
N = int(input())
A_list = list(map(int,input().split()))
a = [0]
b = [0]
point_list = a + A_list + b
S = 0
for i in range(N+1):
    S += abs(point_list[i]-point_list[i+1])

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

Solution (Python):

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(n-1):
    s.append(abs(a[i]-a[i+1]))

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

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

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

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

tmp = 0
for i in range(1, n+2):
    tmp += abs(arr[i-1] - arr[i])
    
for j in range(1, n+1):
    ans = tmp - (abs(arr[j-1] - arr[j]) + abs(arr[j] - arr[j+1])) + abs(arr[j-1] - arr[j+1])
    print(ans)

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

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

Solution (Python):

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

def mydiff(a, b): return (a - b) if a > b else (b - a)


dist = mydiff(A[0], 0)
diffs = [0] * N
for i in range(N):
    if i == 0:
        diffs[i] =  mydiff(A[i], 0) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], 0)
        dist += mydiff(A[i + 1], A[i])
    elif i == N - 1:
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(0, A[i]) - mydiff(0, A[i - 1])
    else:
        dist += mydiff(A[i + 1], A[i])
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], A[i - 1])
dist += mydiff(0, A[-1])

for i in range(N): print(dist - diffs[i])

Solution (Python):
N = int(input())
A = [0] + [int(_) for _ in input().split()] + [0]

costmax = abs(A[1])
costskip = []
for i in range(1, N + 1):
    costmax += abs(A[i + 1] - A[i])
    costskip += [abs(A[i+1] - A[i]) + abs(A[i] - A[i-1]) - abs(A[i+1]-A[i-1])]
[print(costmax - _) for _ in costskip]

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.insert(0,0)
l.append(0)
c=0
for i in range(n+1):
  c+=abs(l[i+1]-l[i])
for j in range(1,n+1):
  print(c-abs(l[j]-l[j-1])-abs(l[j+1]-l[j])+abs(l[j+1]-l[j-1]))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = [0] * n
summ = sum([abs(a[i]-a[i+1]) for i in range(n-1)])
summ += abs(a[0]) + abs(a[-1])
for i in range(1, n-1):
  ans[i] = summ -abs(a[i-1]-a[i])-abs(a[i+1]-a[i])+abs(a[i-1]-a[i+1])
ans[0] = summ - abs(a[0]) -abs(a[0]-a[1]) + abs(a[1])
ans[-1] = summ - abs(a[-1]) -abs(a[-1]-a[-2])+abs(a[-2])
for i in ans:
  print(i)

Solution (Python):
n = int(input())
values = [0] + list(map(int, input().split())) + [0]
total_value = 0
for i in range(1, len(values)):
    total_value += abs(values[i] - values[i - 1])

for i in range(1, len(values) - 1):
    add = abs(values[i + 1] - values[i - 1])
    rem1 = abs(values[i] - values[i - 1])
    rem2 = abs(values[i + 1] - values[i])
    res = total_value + add - rem1 - rem2
    print(res)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
total = sum([ abs(A[x]-A[x+1]) for x in range(N+1) ])
for i in range(N):
    minus = abs(A[i] - A[i+1]) + abs(A[i+1] - A[i+2])
    plus = abs(A[i] - A[i+2])
    print(total-minus+plus)

Solution (Python):
N = int(input())
A = [0] + [int(x) for x in input().split()] + [0]
m = 0
for i in range(N + 1):
  m += abs(A[i + 1] - A[i])
skip = 0
for i in range(N):
  skip = abs(A[i + 2] - A[i + 1]) + abs(A[i + 1] - A[i]) - abs(A[i + 2] - A[i])
  print(m - skip)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]
sum = 0
for i in range(n+1):
    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(sum)
    else:
        print(sum - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + (abs(a[i-1] - a[i+1])))

Solution (Python):


iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]

iAll = sum([abs(aA[i+1]-aA[i]) for i in range(iN+1)])

print("\n".join(map(str,[iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]) for i in range(1,iN+1)])))

Solution (Python):

iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(str,map(lambda i:iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]), range(1,iN+1)))))

Solution (Python):
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(lambda i:str( iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1])), range(1,iN+1))))

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

Solution (Python):
import sys
import copy
input=sys.stdin.readline

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

dis=copy.deepcopy(l)
a=0
for i in range(1,n+2):
    a+=abs(l[i]-l[i-1])

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
dif = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    dif += abs(A[i]-A[i+1])
ans = [dif] * N

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

for i in ans:
    print(i)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))

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

if( (A[0]-0)*(A[1]-A[0])<0 ):
    print(total-abs(A[0]) - abs(A[1] - A[0]) +abs(A[1]) )
else:
    print(total)


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

if( (A[n-1] - 0)*(A[n-2]-A[n-1]) <0):
    print(total-abs(A[n-1]) - abs(A[n-1] - A[n-2]) + abs(A[n-2]))
else:
    print(total)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
b = []

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

sd = sum(b)

for j in range(n):
  if j == 0:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1]))
  elif j == n - 1:
    print(sd - b[j] - b[j + 1] + abs(a[j - 1]))
  else:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1] - a[j - 1]))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
asum = abs(a[0])
for i in range(1,len(a)):
    asum += abs(a[i] - a[i - 1])
asum += abs(a[-1])
a.insert(0,0)
a.append(0)
for i in range(1,len(a) - 1):
    ans = asum - abs(a[i] - a[i-1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1])
    print(ans)

Solution (Python):
"""
C - Traveling Plan
あらかじめ、beginからnまで、endからnまでを計算しておく
"""

point_n = int(input())


points = [0]
for point in input().split():
    points.append(int(point))
points.append(0)


prep_forward = []
pre_point = 0
pre_distance = 0
for point in points:
    pre_distance += abs(pre_point - point)
    prep_forward.append(pre_distance)
    pre_point = point


prep_backward = []
pre_point = 0
pre_distance = 0
for point in reversed(points):
    pre_distance += abs(pre_point - point)
    prep_backward.append(pre_distance)
    pre_point = point
prep_backward

"""
print(points)
print(prep_forward)
print(prep_backward)
"""


for n in range(1, point_n+1):
    travel_distance = prep_forward[n-1] + abs(points[n-1] - points[n+1]) + prep_backward[point_n - n]
    
    
    
    print(travel_distance)

Solution (Python):
n = int(input()) + 2
a = [0] + list(map(int, input().split())) + [0]
all = 0
for i in range(1, n):
    all += abs(a[i - 1] - a[i])
for i in range(1, n - 1):
    if a[i - 1] < a[i] and a[i + 1] < a[i] or a[i - 1] > a[i] and a[i + 1] > a[i]:
        s = min(abs(a[i - 1] - a[i]) , abs(a[i + 1] - a[i]))
        print(all - s * 2)
    else:
        print(all)

Solution (Python):
N = int(input())
A = list(map(int,input().split(" ")))
A.append(0)
SUM = abs(A[0])
for i in range(N):
    SUM += abs(A[i+1]-A[i])
ans = SUM - abs(A[0]) - abs(A[1]-A[0]) + abs(A[1])
print(ans)
for i in range(1,N):
    ans  = SUM - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1])
    print(ans)

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

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

for i in range(n):
    num = sum
    if i == 0:
        num += abs(a[1]) - abs(a[0]) - abs(a[1] - a[0])
    elif i == n-1:
        num += abs(a[n-2]) - abs(a[n-2] - a[n-1]) - abs(a[n-1])
    else:
        num += abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1])
    print(num)

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

dl = [0]
x = 0
for a in A:
    dl.append(dl[-1] + abs(a-x))
    x = a
dl.append(dl[-1] + abs(a))

A = [0] + A + [0]

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = [0] + list(li()) + [0]

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
Total = abs(A[0]) + abs(A[N-1])
for i in range(1, N):
    Total += abs(A[i]-A[i-1])

start = 0
for i in range(N-1):
    cut = abs(A[i+1] - A[i]) + abs(A[i]-start) - abs(A[i+1] - start)
    print(Total - cut)
    start = A[i]
cut = abs(0 - A[N-1]) + abs(A[N-1] - start) - abs(0 - start)
print(Total - cut)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
ans = []
i = 1
s = [abs(a[1])] + [None for _ in range(n)]
d = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    s[i] = abs(a[i + 1] - a[i])
    if (a[i - 1] - a[i]) * (a[i] - a[i + 1]) >= 0:
        d[i] = 0
    else:
        d[i] = s[i] + s[i - 1] - abs(a[i + 1] - a[i - 1])
ss = sum(s)
for i in range(1, n + 1):
    print(ss - d[i])

Solution (Python):

N=int(input())
A=list(map(int, input().split()))
base=0
Now=0
Next=0
for i in range(N):
    Now=Next
    Next=A[i]
    base+=abs(Next-Now)
base+=abs(A[N-1]-0)
for i in range(N):
    if i==0:
        ans = base - abs(A[i] - 0) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - 0)
    elif i==N-1:
        ans = base - abs(A[i] - A[i - 1]) - abs(0 - A[i]) + abs(0 - A[i - 1])
    else:
        ans = base - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1])
    print(ans)

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


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

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

Solution (Python):
n = int(input())
l = [0]
for i in input().split():
    l.append(int(i))
l.append(0)
s = 0
for i in range(n+1):
    s += abs(l[i+1] - l[i])
for i in range(1, n+1):
    ans = s - abs(l[i] - l[i-1]) - abs(l[i+1] - l[i]) + abs(l[i+1] - l[i-1])
    print(ans)

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
s = sum([abs(a[i]-a[i-1]) for i in range(1, n+2)])
for i in range(1, n+1):
    x = abs(a[i]-a[i-1])
    y = abs(a[i+1]-a[i])
    z = abs(a[i+1]-a[i-1])
    print(s-x-y+z)

Solution (Python):

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


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


all_sum += abs(An[-1])

for i in range(N):
    if i == 0:
        ans = all_sum - abs(An[i]) - abs(An[i] - An[i+1]) + abs(An[i+1])
    elif i == N-1:
        ans = all_sum - abs(An[i-1] - An[i]) - abs(An[i]) + abs(An[i-1])
    else:
        ans = all_sum - abs(An[i-1] - An[i]) - abs(An[i] - An[i+1]) + abs(An[i-1]-An[i+1])

    print(ans)

Solution (Python):
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
ans=0
for i in range(n+1):
    ans+=abs(a[i]-a[i+1])
for i in range(1,n+1):
    print(ans-abs(a[i]-a[i+1])-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1]))

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
s = 0
for i in range(n+1):
  s += abs(a[i]-a[i+1])
for i in range(1,n+1):
  print(s-abs(a[i]-a[i+1])-abs(a[i]-a[i-1])+abs(a[i-1]-a[i+1]))

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

d, d_skip = [0], [0]
for i in range(n):
    if i == 0:
        d.append(abs(a[i]))
    else:
        d.append(abs(a[i]-a[i-1]))
d.append(abs(a[-1]))

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

d_cumsum = [0]
for d_i in d[1:]:
    d_cumsum.append(d_i+d_cumsum[-1])

for i in range(1, n+1):
    ans = d_cumsum[i-1] + d_skip[i] + (d_cumsum[-1] - d_cumsum[i+1])
    print(ans)

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

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

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

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()
A = [0] + A + [0]
B = [0]
for i in range(len(A) - 1):
    B.append(A[i + 1] - A[i])
del B[0]

total = 0
for b in B:
    total += abs(b)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = 0
ma = max(A)
mi = min(A)

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

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

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

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

amounts = [0] * N
for i in range(N):
    left = 0
    right = 0
    if i > 0:
        left = A[i - 1]
    if i < N - 1:
        right = A[i + 1]
    amounts[i] = total + abs(left - right) - (abs(left - A[i]) + abs(A[i] - right))

for i in range(N):
    print(amounts[i])

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

def a(i):
    if 0 <= i < N:
        return A[i]
    else:
        return 0

base = 0
for i in range(N + 1):
    base += abs(a(i) - a(i - 1))

for i in range(N):
    print(base - abs(a(i) - a(i - 1)) - abs(a(i + 1) - a(i)) + abs(a(i + 1) - a(i - 1)))

Solution (Python):
n = int(input())
a = [int(v) for v in input().split()]
a.append(0)

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

ans = []
if a[0] < 0 <= a[1] or a[0] > 0 >= a[1]:
    ans.append(all_sum - abs(a[0]) * 2)
elif 0 <= a[0] <= a[1] or 0 >= a[0] >= a[1]:
    ans.append(all_sum)
else:
    ans.append(all_sum - abs(a[0] - a[1]) * 2)

for i in range(n-1):
    if a[i+1] < a[i] <= a[i+2] or a[i+1] > a[i] >= a[i+2]:
        ans.append(all_sum - abs(a[i] - a[i+1]) * 2)
    elif a[i] <= a[i+1] <= a[i+2] or a[i] >= a[i+1] >= a[i+2]:
        ans.append(all_sum)
    else:
        ans.append(all_sum - abs(a[i+1] - a[i+2]) * 2)

for line in ans:
    print(line)

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

Solution (Python):
n = int(input())
listA = list(map(int, input().split()))
sumOriginal =0
index =0
while index<len(listA):
    if index == 0:
        sumOriginal+=(max(listA[index], 0)-min(listA[index], 0))
    elif index == len(listA)-1:
        sumOriginal+=(max(listA[index], 0)-min(listA[index], 0))
        sumOriginal+=(max(listA[index], listA[index-1])-min(listA[index], listA[index-1]))
    else:
        sumOriginal+=(max(listA[index], listA[index-1])-min(listA[index], listA[index-1]))
    index+=1

index2=0
listForAnswer =[]
while index2<len(listA):
    sumAnswer=0
    if index2 ==0:
        sumAnswer = sumOriginal-(max(listA[index2], 0)-min(listA[index2], 0))
        sumAnswer-=(max(listA[index2], listA[index2+1])-min(listA[index2], listA[index2+1]))
        sumAnswer+=(max(listA[index2+1], 0)-min(listA[index2+1], 0))
    elif index2 ==len(listA)-1:
        sumAnswer =sumOriginal-(max(listA[index2], 0)-min(listA[index2], 0))
        sumAnswer-=(max(listA[index2], listA[index2-1])-min(listA[index2], listA[index2-1]))
        sumAnswer+=(max(listA[index2-1], 0)-min(listA[index2-1], 0))
    else:
        sumAnswer =sumOriginal-(max(listA[index2], listA[index2+1])-min(listA[index2], listA[index2+1]))
        sumAnswer-=(max(listA[index2], listA[index2-1])-min(listA[index2], listA[index2-1]))
        sumAnswer+=(max(listA[index2-1], listA[index2+1])-min(listA[index2-1], listA[index2+1]))
    listForAnswer.append(sumAnswer)
    index2+=1

for ans in listForAnswer:
    print(ans)

Solution (Python):
n=int(input())
a=[0]
for i in input().split():
    a.append(int(i))
a.append(0)

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


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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
d=[]
tmp=0
for i,j in enumerate(a):
    if i==0:
        tmp+=abs(j)
        d.append(((abs(j)+abs(a[i]-a[i+1])),abs(a[i+1])))
    elif i==n-1:
        tmp+=abs(a[i-1]-a[i])+abs(j)
        d.append((abs(a[i-1]-a[i])+abs(j),abs(a[i-1])))
    else:
        f=abs(a[i]-a[i-1])
        tmp+=f
        d.append((abs(a[i-1]-a[i])+abs(a[i]-a[i+1]),abs(a[i-1]-a[i+1])))

for i in d:
    print(tmp-i[0]+i[1])

Solution (Python):
N = int(input())
p_l = [0] + [int(i) for i in input().split()] + [0]
s0 = 0
ans = ''

for i in range(N+1):
	s0 += abs(p_l[i+1] - p_l[i])

for i in range(1, N+1):
	s = s0 - abs(p_l[i+1]-p_l[i]) - abs(p_l[i]-p_l[i-1]) + abs(p_l[i+1]-p_l[i-1])
	ans += str(s)+'\n'

print(ans[:-1])

Solution (Python):
import copy
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0,0)
dist = 0
for j in range(N+1):
    dist += abs(A[j]-A[j+1])
for j in range(N):
    res = dist + abs(A[j+2]-A[j]) - abs(A[j+1]-A[j]) - abs(A[j+2]-A[j+1])
    print(res)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]
s = 0
for i in range(n+1):
    s += abs(a[i]-a[i+1])

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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
aa = inpl()
S = 0
ba = 0
for a in aa:
	S += abs(a-ba)
	ba = a
S += abs(ba)

aa = [0] + aa + [0]
for i in range(1,N+1):
	l,m,r = aa[i-1],aa[i],aa[i+1]
	bc = abs(m-l)+abs(r-m)
	nc = abs(r-l)
	print(S-bc+nc)

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

aa = [0]+a+[0]

b=[]

for i in range(n+1):
    b.append(abs(aa[i+1]-aa[i]))

c = sum(b)

for i in range(n):
    ans = c-b[i]-b[i+1]+abs(aa[i+2]-aa[i])
    print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

A = [0] + A + [0]

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

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)