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 = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)

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

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=[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 = [0] + [int(i) for i in input().split()] + [0]
total = 0
for i in range(len(A) - 1):
    total += abs(A[i + 1] - A[i])
for i in range(1, len(A) - 1):
    print(
        total - 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.append(0)
adjustment = [0] * n
base_money = 0
position = 0
for i in range(n):
    if position > l[i] and l[i] < l[i+1]:
        if position < l[i+1]:
            adjustment[i] = (abs(l[i + 1] - l[i]) -
                             abs(l[i + 1] - position)) * 2
        else:
            adjustment[i] = (abs(l[i] - position) -
                             abs(l[i + 1] - position)) * 2
    elif position < l[i] and l[i] > l[i + 1]:
        if position < l[i+1]:
            adjustment[i] = (abs(l[i] - position) -
                             abs(l[i + 1] - position)) * 2
        else:
            adjustment[i] = (abs(l[i + 1] - l[i]) -
                             abs(l[i + 1] - position)) * 2
    base_money += abs(l[i] - position)
    position = l[i]
base_money += abs(position)
for i in range(n):
    print(base_money - adjustment[i])

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

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

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

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

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

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

shortcut = [0] * n
for i in range(1,n+1):
  shortcut[i-1] = abs(aa[i]-aa[i-1]) + abs(aa[i+1]-aa[i]) - abs(aa[i+1]-aa[i-1])  
  
for i in range(n):
  print(comp - shortcut[i])

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):
    ans = s + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]))
    print(ans)

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

for i in range(N):
    dif = 0
    if i == 0:
        dif = abs(A[1] - A[0]) + abs(A[0]) - abs(A[1])
    else:
        dif = abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i - 1])
    print(total - dif)

Solution (Python):
N = int(input())
A = [0]

A_0 = map(int, input().split())
for i in A_0:
    A.append(i)
A.append(0)
    
sum_A = 0
for i in range(N + 1):
    sum_A += abs(A[i] - A[i + 1])

for i in range(1, N + 1):
    if (A[i+1] - A[i]) * (A[i] - A[i-1]) >= 0:
        print(sum_A)
    else:
        print(sum_A - min(abs(A[i+1] - A[i]), abs(A[i] - A[i-1])) * 2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.insert(0, 0)
A.append(0)
distance = []
sum_val = 0
for i in range(1,len(A)):
    d = abs(A[i] - A[i - 1])
    sum_val += d
    distance.append(d)
banish_list = []
now_direct = "no"
for next in range(1,len(A)):

    if A[next - 1] < A[next]:
        next_direct = "right"
    elif A[next - 1] > A[next]:
        next_direct = "left"
    else:
        next_direct = "no"
    if now_direct != next_direct and (next_direct != "no" and now_direct != "no"):
        d = min(distance[next - 1] , distance[next - 2])
    else:
        d = 0
    banish_list.append(d)
    now_direct = next_direct
banish_list.pop(0)
for b in banish_list:
    print(sum_val - b * 2)

Solution (Python):
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
total = np.abs(np.diff(A)).sum()
saved = np.abs(A[1:-1] - A[:-2]) + np.abs(A[1:-1] - A[2:]) - np.abs(A[:-2] - A[2:])
answer = total - saved
print(*answer, sep='\n')

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

cur = 0
for i in range(N):
    if (cur <= A[i] <= A[i+1]) or (A[i+1] <= A[i] <= cur):
        print(total)
    elif (A[i+1] <= cur <= A[i]) or (A[i] <= cur <= A[i+1]):
        print(total-abs(A[i]-cur)*2)
    elif (A[i] <= A[i+1] <= cur) or (cur <= A[i+1] <= A[i]):
        print(total-abs(A[i+1]-A[i])*2)
    cur = A[i]

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = [0]*len(A)
C = [0]*len(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = [0]*len(A)
C = [0]*len(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    C[i] = C[i+1] + abs(A[i]-A[i+1])
for i in range(1, N+1):
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


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

B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    
    C[i] = C[i+1] + abs(A[i]-A[i+1])

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

exit(0)

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

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

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

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

D = []

for n in range(N+1):
    D.append(abs(A[n]-A[n+1]))

tot = sum(D)

for n in range(N):
    ans = tot - abs(D[n]+D[n+1]) + abs(A[n]-A[n+2])
    print(ans)

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

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

for i in range(1,N+1):
    Si=Sum+abs(As[i-1]-As[i+1])-(abs(As[i-1]-As[i])+abs(As[i]-As[i+1]))
    print(Si)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A=[0]+A+[0]
ans=0
for i in range(1,n+2):
    ans+=abs(A[i-1]-A[i])
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]
B = [0]*n
C = [0]*(n+1)

for i in range(n):
    B[i]=abs(A[i]-A[i+2])
for i in range(n+1):
    C[i]=abs(A[i]-A[i+1])
sumC = sum(C)
for i in range(n):
    print(sumC+B[i]-C[i]-C[i+1])

Solution (Python):
def examC():
    N = I()
    A = LI()
    cost1 = [0]*(N+1); cost2 = [0]*(N+1)
    A.append(0)
    for i in range(N+1):
        cost1[i] = abs(A[i]-A[i-1])
        cost2[i] = abs(A[i]-A[i-2])
    ans = []
    cost = sum(cost1)
    for i in range(N):
        cur = cost - cost1[i] - cost1[i+1] + cost2[i+1]
        ans.append(cur)
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

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

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

for i in range(1, len(A)-1):
    if A[i-1] < A[i] < A[i+1] or A[i+1] < A[i] < A[i-1]:
        print(sum_dis)
    else:
        print(sum_dis - (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()))
A = [0] + A
A.append(0)

tot = 0
s = 0
for a in A:
    tot += abs(a-s)
    s = a

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

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

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

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

def cost(x1, x2):
    return abs(x1 - x2)

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

def diff_cost(A, i):
    return cost(A[i-1], A[i]) + cost(A[i], A[i+1]) - cost(A[i-1], A[i+1])

for i in range(1,N+1):
    print(cost_sum - diff_cost(A,i))

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()))
a.append(0)
a.insert(0,0)
cnt = 0
for i in range(n+1):
	cnt += abs(a[i+1] - a[i])

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

Solution (Python):
from sys import stdin
import numpy as np
import math
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

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

for j in range(1,len(lin)-1):
    print(point-(abs(lin[j]-lin[j-1])+abs(lin[j+1]-lin[j]))+abs(lin[j+1]-lin[j-1]))

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):
    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):
N = int(input())
array = list(map(int,input().split()))
expense = [0] * (N+1)
expense[0] = abs(array[0])
for i in range(N-1):
    expense[i+1] = abs(array[i+1] - array[i])
expense[N] = abs(array[N-1])
total = sum(expense)
for i in range(N):
    tmp = total
    tmp -= expense[i]+expense[i+1]
    tmp += (abs(array[i+1] - array[i-1]) if i != 0 else abs(array[i+1])) if i != N-1 else abs(array[N-2])
    print(tmp)

Solution (Python):
n = int(input())
a = list(int(x) for x in input().split())
judge = [0] + a + [0]
key = [0]*n
ans = 0

for i in range(n):
    x, y, z = [judge[i], judge[i+1], judge[i+2]]
    key_list = [x, y, z]
    if max(key_list) == y or min(key_list) == y:
        key[i] = 2 * min(abs(x-y), abs(y-z))
        ans = ans + abs(y-x)
    else:
        ans = ans + abs(y-x)
ans += abs(a[-1])

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

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


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

Solution (Python):
N = int(input())
A = [0] * (N + 2)
for i, a in enumerate(map(int, input().split())):
    A[i + 1] = a
costs = [0] * (N + 2)
for i in range(1, N + 2):
    costs[i] = abs(A[i] - A[i - 1])
cost = sum(costs)

for i in range(1, N + 1):
    actual = abs(A[i + 1] - A[i - 1])
    plan = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])
    print(cost - (plan - actual))

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

sum_price = 0
list_diff = []
pre = abs(list_a[1] - list_a[0])
for i in range(1, n+1):
  sum_price += pre
  temp = abs(list_a[i+1] - list_a[i])
  list_diff.append(abs(list_a[i+1] - list_a[i-1]) - (temp + pre))
  pre = temp
sum_price += pre

for one_diff in list_diff:
  print(sum_price + one_diff)

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

a.append(0)
a.insert(0, 0)
s = sum([abs(a[i+1]-a[i]) for i in range(n+1)])

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

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

D = [abs(A[i+1]-A[i]) for i in range(len(A)-1)]
base = sum(D)

for i in range(n):
  print(base-D[i]-D[i+1]+abs(A[i+2]-A[i]))

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input().strip())
A = [int(x) for x in input().strip().split()] + [0]
totalcost = 0
a_ = 0
for a in A:
    totalcost += abs(a - a_)
    a_ = a

C = [totalcost] * N
a_ = 0
for i, a in enumerate(A):
    if i == len(A)-1:
        break
    C[i] += -abs(a - a_) -abs(A[i+1] - a) + abs(A[i+1] - a_)
    a_ = a

for c in C:
    print(c)

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

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

sumdis = sum(b)
a.append(0)
for i in range(n):
    print(sumdis + abs(a[i-1]-a[i+1]) - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]))

Solution (Python):
N = int(input())
A = list(map(lambda x: int(x), input().split(' ')))
A.append(0)
A.insert(0, 0)

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

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

Solution (Python):
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
b=sum(abs(i-j) for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):
    if i<=j<=k or i>=j>=k:
        print(b)
    elif min(i,j,k)==j:
        print(b-2*(min(i,k)-j))
    else:
        print(b-2*(j-max(i,k)))

Solution (Python):


import sys










def main():
    n = int(sys.stdin.readline().rstrip())
    a = [0] + [int(x) for x in sys.stdin.readline().split()] + [0]
    way = 0
    for i in range(n+1):
        way += abs(a[i+1] - a[i])
    
    for i in range(1, n+1):
        pre, cur, nex = a[i-1], a[i], a[i+1]
        if pre <= cur <= nex or pre >= cur >= nex:
            ans = way
        elif pre <= nex <= cur or pre >= nex >= cur:
            ans = way - abs(nex - cur) * 2
        elif cur <= pre <= nex or cur >= pre >= nex:
            ans = way - abs(cur - pre) * 2
        
        print(ans)

if __name__ == "__main__":
    
    main()

Solution (Python):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    S = sum((abs(A[i] - A[i+1]) for i in range(N+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])))


if __name__ == '__main__':
    main()

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

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] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]))

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    d = 0
    for a0, a1 in zip(aa, aa[1:]):
        d += abs(a0 - a1)
    for i in range(1, 1 + n):
        print(d - abs(aa[i - 1] - aa[i]) - abs(aa[i + 1] - aa[i]) + abs(aa[i - 1] - aa[i + 1]))

main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.append(0)
S=0
a=[]
c=[]
f=0

for n in range(N):
    S+=abs(A[n]-f)
    a.append(abs(A[n]-f))
    c.append(abs(A[n+1]-f))
    f=A[n]

S+=abs(A[n])
a.append(abs(A[n]))

for n in range(N):
    print(S-a[n]-a[n+1]+c[n])

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

for i in range(n):
    if i==0: 
        loss=abs(l[1]-l[0]) 
        loss+=abs(l[0])
        gain=abs(l[1])
        print(s-loss+gain)
    elif i==n-1:
        loss=abs(l[-1])
        loss+=abs(l[-1]-l[-2])
        gain=abs(l[-2])
        print(s-loss+gain)
    else: 
        loss=abs(l[i]-l[i-1])
        loss+=abs(l[i]-l[i+1])
        gain=abs(l[i-1]-l[i+1])
        print(s-loss+gain)

Solution (Python):

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

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


for i in range(1, N+1):
    minus = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i])
    plus = abs(A[i+1] - A[i-1])
    x = full - minus + plus
    print(x)

Solution (Python):

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













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)




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:
        
        ans = HEAD[i-1] + TAIL[N-i-2] + abs(A[i+1] - A[i-1])
    print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
total = 0

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


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

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

Solution (Python):
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)
    
    for i in range(1, n + 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()

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

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

for i in range(1,N+1):
    if (A[i]-A[i-1])*(A[i+1]-A[i])<0:
        print(S-d[i-1]-d[i]+abs(A[i-1]-A[i+1]))
    else:
        print(S)

Solution (Python):
import sys
def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    sc = 0
    for i in range(n + 1):
        if i == 0:
            sc += abs(0 - a[i])
        elif i == n:
            sc += abs(0 - a[i-1])
        else:
            sc += abs(a[i] - a[i-1])
    for i in range(n):
        if i == 0:
            print(sc + abs(a[i+1] - 0) - abs(a[i] - 0) - abs(a[i+1] - a[i]))
        elif i == n - 1:
            print(sc + abs(a[i-1] - 0) - abs(a[i] - 0) - abs(a[i] - a[i-1]))
        else:
            print(sc + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i+1] - a[i]))


if __name__ == '__main__':
    slove()

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

total = abs(a[0])

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

total += abs(a[-1])



for i in range(n):
    if i == 0:
        org = abs(a[i]) + abs(a[i] - a[i+1])
        skip = abs(a[i+1])
        print(total - org + skip)
        continue
    if i == n - 1:
        org = abs(a[i-1] - a[i]) + abs(a[i])
        skip = abs(a[i-1])
        print(total - org + skip)
        continue

    org = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])
    skip = abs(a[i-1] - a[i+1])
    print(total - org + skip)

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

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

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

cost=[abs(A[i]-A[i+1]) for i in range(N-1)]
costsum=total=sum(cost)+abs(A[0])+abs(A[N-1])
for i in range(N):
  total=costsum
  if i == 0:
    total-=abs(A[i])
    total-=cost[i]
    total+=abs(A[i+1])
  elif i == N-1:
    total-=abs(A[i])
    total+=abs(A[i-1])
    total-=cost[i-1]
  else:
    total-=cost[i]
    total-=cost[i-1]
    total+=abs(A[i+1]-A[i-1])
  print(total)

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

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