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):




def main():
    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):
        l, r = min(A[i - 1], A[i + 1]), max(A[i - 1], A[i + 1])
        if l <= A[i] <= r:
            print(S)
        elif A[i] <= l:
            print(S - 2 * (l - A[i]))
        else:
            print(S - 2 * (A[i] - r))


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
n = int(input())
a = [0]+list(map(int,input().split()))+[0]
s = [abs(a[i]-a[i+1]) for i in range(n+1)]
s = sum(s)
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):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

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

ans = []
for i in range(1, N + 1):
    rst = S
    rst -= C[i] + C[i - 1]
    rst += abs(A[i + 1] - A[i - 1])
    ans.append(rst)

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

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

d = 0
a.insert(0, 0)
a.append(0)
for i in range(n+1):
  d += abs(a[i+1] - a[i])
  
for i in range(n):
  ans = d - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1]) + abs(a[i+2]-a[i])
  print(ans)

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

for i in range(n):
    if a[i] <= a[i+1] <= a[i+2] or a[i+2] <= a[i+1] <= a[i]:
        print(origin_len)
    else:
        len_a = abs(a[i+1] - a[i])
        len_b = abs(a[i+1] - a[i+2])

        print(origin_len - 2 * min(len_a, len_b))

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])
Si = [0]*(N+2)
for i in range(1, N+1):
  Si[i] = S-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
  print(Si[i])

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

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

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]
a0 = a[0]
b = []
for i in range(1,n+2):
    b.append(abs(a0-a[i]))
    a0 = a[i]
s = sum(b)
for i in range(n):
    print(s+abs(a[i]-a[i+2])-(b[i]+b[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):
    Si = S + abs(A[i-1]-A[i+1]) - (abs(A[i-1]-A[i]) + abs(A[i]-A[i+1]))
    print(Si)

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

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

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

tlen = sum(B)
for i in range(N) :
    print(tlen - B[i] - B[i+1] + C[i])

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    diff = []
    for i in range(1, N+1):
        if A[i-1]<A[i] and A[i+1]<A[i]:
            diff.append((A[i]-max(A[i-1], A[i+1]))*2)
        elif A[i-1]>A[i] and A[i+1]>A[i]:
            diff.append((min(A[i-1], A[i+1])-A[i])*2)
        else:
            diff.append(0)
    res = 0
    for i in range(N+1):
        res += abs(A[i+1]-A[i])
    for i in diff:
        print(res-i)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
src = [0] + list(map(int,input().split())) + [0]
cums = [0]
for a,b in zip(src,src[1:]):
    d = abs(a-b)
    cums.append(cums[-1] + d)

ans = []
for i in range(N):
    tmp = cums[i] + abs(src[i] - src[i+2]) + cums[-1] - cums[i+2]
    ans.append(tmp)
print(*ans, sep='\n')

Solution (Python):
import math
N = int(input())
ARR = [int(s) for s in input().split(" ")]
ARR.insert(0,0)
ARR.append(0)


def calculate(arr):
    S = 0
    for i in range(len(arr)-1):
        S = S + int(math.fabs(arr[i+1]-arr[i]))

    for i in range(1,len(arr)-1):
        print(int(S + math.fabs(arr[i-1]-arr[i+1]) - (math.fabs(arr[i-1]-arr[i]) + math.fabs(arr[i]-arr[i+1]))))



calculate(ARR)

Solution (Python):
N = int(input())
AList = list(map(int, input().split()))
sumFee = 0


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


for i in range(N):
  low_i = abs(AList[i] - AList[i-1]) if i != 0 else abs(AList[0])
  high_i = abs(AList[i + 1] - AList[i]) if i != N - 1 else abs(AList[N-1])
  if i == 0 :
    mix_i = abs(AList[i + 1])
  elif i == N - 1 :
    mix_i = abs(AList[i - 1])
  else:
    mix_i = abs(AList[i + 1] - AList[i - 1])
  
  print(sumFee - low_i - high_i + mix_i)

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

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

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

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

Solution (Python):
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
s=sum(abs(l[i+1]-l[i]) for i in range(n+1))
for i in range(n):
  a,b,c=l[i:i+3]
  print(s-min(abs(b-c),abs(b-a))*2*(max(a,c)<b or min(a,c)>b))

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

l=[0]+l+[0]

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

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

Solution (Python):
n = int(input())

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

a_abs_max = sum(a_abs)
for i in range(1,n+1):
    ans = a_abs_max - abs(a[i]-a[i+1]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1])
    print(ans)

Solution (Python):
from copy import deepcopy
N = int(input())
A = list(map(int,input().split()))
A = [0] + A + [0]
dist = []
for i in range(N+1):
    dist.append(abs(A[i]-A[i+1]))
S = sum(dist)
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 = [int(x) for x in input().split()]

a.append(0)
a.insert(0,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-1] - a[i+1]) - (abs(a[i] - a[i-1]) + abs(a[i] - a[i+1])))

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

total = 0

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

for j in range(1,n+1):
    print(total-abs(xs[j]-xs[j-1])-abs(xs[j]-xs[j+1])+abs(xs[j-1]-xs[j+1]))

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

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

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

Solution (Python):


N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))


S=0
for i in range( len(A_list) ):
    if i==0:
        S = abs(A_list[i])
    else:
        S += abs(A_list[i] - A_list[i-1])
        
S += abs(A_list[i])


ans_S=[]
for i in range( len(A_list) ):
    if i == 0:
        ex_S = S - abs(A_list[i+1] - A_list[i]) - abs(A_list[i] - 0) + abs(A_list[i+1] - 0)
    elif i == len(A_list)-1:
        ex_S = S - abs(0 - A_list[i]) - abs(A_list[i] - A_list[i-1]) + abs(0 - A_list[i-1])
    else:
        ex_S = S - abs(A_list[i+1] - A_list[i]) - abs(A_list[i] - A_list[i-1]) + abs(A_list[i+1] - A_list[i-1])
    
    ans_S.append(ex_S)


for i in ans_S:
    print(i)

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

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


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

Solution (Python):
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
C = []
c = 0
for i in range(n+1):
  c += abs(A[i+1] - A[i])
for i in range(1, n+1):
  if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
    print(c)
  elif A[i] <=A[i-1] <= A[i+1] or A[i] <= A[i+1] <= A[i-1]:
    print(c - abs(min(A[i-1], A[i+1]) - A[i])*2)
  elif A[i-1] <= A[i+1] <= A[i] or A[i+1] <= A[i-1] <= A[i]:
    print(c - abs(A[i] - max(A[i+1], A[i-1]))*2)

Solution (Python):
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
C = []
c = 0
for i in range(n+1):
  c += abs(A[i+1] - A[i])
for i in range(1, n+1):
  if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
    print(c)
  elif A[i] <=A[i-1] <= A[i+1] or A[i] <= A[i+1] <= A[i-1]:
    print(c - abs(min(A[i-1], A[i+1]) - A[i])*2)
  else:
    print(c - abs(A[i] - max(A[i+1], A[i-1]))*2)

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

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

res=0

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

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

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

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

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

Solution (Python):

n=int(input())
a=[0]+[int(j) for j in input().split()]+[0]
d1=[abs(a[i]-a[i+1]) for i in range(n+1)]
d2=[abs(a[i]-a[i+2]) for i in range(n)]
sum_all=sum(d1)
for i in range(n):
    print(sum_all-d1[i]-d1[i+1]+d2[i])

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

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

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

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
a.append(0)
total = 0
for i in range(n+1):
    total += abs(a[i] - a[i-1])
    
for i in range(-1,n-1):
    if (a[i+1]-a[i]) *(a[i+2]-a[i+1]) > 0:
        print(total) 
    else: print(total - 2 * min(abs(a[i+1] -a[i]) ,abs(a[i+1] -a[i+2])))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.append(0)
ary = []
for i, a in enumerate(A):
    if i == 0:
        ary.append(abs(0-a))
    else:
        ary.append(ary[-1]+abs(A[i-1]-a))
for i in range(N):
    ans = 0
    if i != 0:
        ans = ary[i-1]
        ans += abs(A[i-1]-A[i+1])
    else:
        ans += abs(A[1])
    ans += ary[-1]-ary[i+1]
    print(ans)

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

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

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

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

All = 0

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

for i in range(1,N+1):
        print(All- 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()))
to = abs(a[0]) + abs(a[-1])

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

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

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

for i in range(N + 1):
    summ += abs(coordinate[i + 1] - coordinate[i])

diff_coorinate = []

for i in range(N):
    distance = abs(coordinate[i + 2] - coordinate[i])
    diff_coorinate.append(distance)

for i in range(N):

    next = coordinate[i + 1] - coordinate[i]
    n_next = coordinate[i + 2] - coordinate[i + 1]
    
    if (next * n_next >= 0):
        ans = summ
    elif (coordinate[i + 2] - coordinate[i] >= 0):
        d = abs(min(next, n_next))
        ans = summ - 2 * d
    else:
        d = max(next, n_next)
        ans = summ - 2 * d
    
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = 0
ol = 0
for i in a:
	s += abs(i-ol)
	ol = i
s += abs(ol)
a.insert(0,0)
a.append(0)
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 (s)
	else:
		print (s-min(abs(a[i-1]-a[i]),abs(a[i]-a[i+1]))*2)

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
dist = sum([abs(a[i] - a[i + 1]) for i in range(n + 1)])
for i in range(1, n + 1):
    print(dist - 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()))
cum_a = [0]
cum_b = [0]
here_a = 0
here_b = 0
for i in range(n):
    cum_a.append(abs(here_a-a[i]) + cum_a[i])
    here_a = a[i]
    cum_b.append(abs(here_b - a[n-1-i]) + cum_b[i])
    here_b = a[n-1-i]
cum_a.append(abs(a[-1])+cum_a[-1])
cum_b.append(abs(a[0]) + cum_b[-1])
here = 0
a.append(0)
for i in range(n):
    l = cum_a[i]
    r = cum_b[n-1-i]
    move = abs(here-a[i+1])
    here = a[i]
    print(l+r+move)

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

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+1] - a[i])
for i in range(1, n+1):
    print(total + abs(a[i+1] - a[i-1]) - abs(a[i+1] - a[i]) - abs(a[i-1] - a[i]))

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+1] - A[i])
for j in range(1, N+1):
    print(total + abs(A[j + 1] - A[j - 1]) - abs(A[j + 1] - A[j]) - abs(A[j-1] - A[j]))

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
DP = []
ans = []
DP.append(abs(0-A[0]))
for i in range(1,N):
    DP.append(abs(A[i]-A[i-1]))

sum_DP = sum(DP)

for j in range(N):
    if j == 0:
        tmp = sum_DP-DP[0]-DP[1]+abs(A[1])+abs(A[N - 1])
    elif j == N-1:
        tmp = sum_DP-DP[N-1]+abs(A[N - 2])
    else:
        tmp = sum_DP + abs(A[N - 1])-DP[j]-DP[j+1]+abs(A[j+1]-A[j-1])
    ans.append(tmp)

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

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

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

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

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

Solution (Python):

n=int(input())
lists=list(map(int,input().split()))
a=[0 for i in range(n+2)]
for i in range(n):
    a[i+1]=lists[i]

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

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

Solution (Python):
import math
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)

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

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

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
sum = 0
X.insert(0,0)
X.append(0)

for n in range(N+1):
    sum += abs(X[n] - X[n+1])


for n in range(N):
    l = abs(X[n] - X[n+1])
    r = abs(X[n+1] - X[n+2])

    if X[n] < X[n+1] and X[n+1] < X[n+2]:
        print(sum)
    elif X[n] > X[n+1] and X[n+1] > X[n+2]:
        print(sum)

    elif l < r:
        sep = 2*abs(X[n] - X[n+1])
        print(sum - sep)
    else:
        sep = 2*abs(X[n+2] - X[n+1])
        print(sum - sep)

Solution (Python):

def main():
    n = int(input())
    a_s = [0] + list(map(int,input().split())) + [0]
    default = sum([abs(a_s[i-1] - a_s[i]) for i in range(1,len(a_s))])
    answer = 0
    for i in range(1,len(a_s)-1):
        if (a_s[i] >=  a_s[i-1]) == (a_s[i+1] >= a_s[i]):
            
            answer = default
        else:
            answer = default - abs(a_s[i]-a_s[i-1]) - abs(a_s[i+1]-a_s[i]) + abs(a_s[i+1] - a_s[i-1])
        print(answer)





if __name__ == '__main__':
    main()

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

    total_tour_cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
    ans = []
    for i in range(1, N + 1):
        
        
        delta1 = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])
        delta2 = abs(A[i - 1] - A[i + 1])
        ans.append(total_tour_cost - delta1 + delta2)
    return '\n'.join(map(str, ans))

print(c_traveling_plan())

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

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

for i in range(n):
    t=whole
    t-=abs(X[i+1]-X[i])+abs(X[i+2]-X[i+1])
    t+=abs(X[i+2]-X[i])
    print(t)

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

Solution (Python):
from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.extend([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-1]-A[i])+abs(A[i]-A[i+1]))-abs(A[i-1]-A[i+1])))

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


total = 0
for i in dis:
    total += abs(i)


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

for i in ans:
    print(i)

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


for i in range(1, n+1):
    if a[i-1] <= a[i+1]:
        if a[i - 1] <= a[i] <= a[i + 1]:
            print(money)
        elif a[i] < a[i - 1]:
            print(money - 2 * (a[i - 1] - a[i]))
        elif a[i + 1] < a[i]:
            print(money - 2 * (a[i] - a[i + 1]))
    else:
        if a[i + 1] <= a[i] <= a[i - 1]:
            print(money)
        elif a[i] < a[i + 1]:
            print(money - 2 * (a[i + 1] - a[i]))
        elif a[i - 1] < a[i]:
            print(money - 2 * (a[i] - a[i - 1]))

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

l.insert(0, 0)
l.extend([0])
S = 0
ans = 0
for ix, i in enumerate(l[:-1]):
    S += abs(i - l[ix+1])

for ix in range(1,len(l)-1):
    S_i = S - abs(l[ix-1] - l[ix]) - abs(l[ix] - l[ix+1]) + abs(l[ix-1] - l[ix+1])
    print(S_i)

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

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

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

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

for i in range(1, len(a) - 1):
  print(s + 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(int, input().split()))
a = [0] + a + [0]

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

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

sum_b = sum(b)
for i in range(n):
    print(sum_b - sum(b[i:i+2]) + c[i])

Solution (Python):
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

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

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()))
all = abs(A[0]) + abs(A[N-1])
for i in range(1, N):
    all += abs(A[i] - A[i-1])

for i in range(N):
    answer = all
    if i == 0:
        prev = 0
    else:
        prev = A[i-1]
    if i == N-1:
        next = 0
    else:
        next = A[i+1]
    curr = A[i]
    if prev > curr and curr < next:
        if prev >= next:
            answer -= abs(curr - next) * 2
        else:
            answer -= abs(curr - prev) * 2
    elif prev < curr and curr > next:
        if prev >= next:
            answer -= abs(curr - prev) * 2
        else:
            answer -= abs(curr - next) * 2
    print(answer)

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

for i in range(N):
    answer = all
    if i == 0:
        prev = 0
    else:
        prev = A[i-1]
    if i == N-1:
        next = 0
    else:
        next = A[i+1]
    curr = A[i]
    if prev > curr and curr < next:
        if prev >= next:
            answer -= abs(curr - next) * 2
        else:
            answer -= abs(curr - prev) * 2
    elif prev < curr and curr > next:
        if prev >= next:
            answer -= abs(curr - prev) * 2
        else:
            answer -= abs(curr - next) * 2
    print(answer)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

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

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

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

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

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

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):
N = int(input())
A = list(map(int, input().split()))

"""考え方
累積の移動距離を順番に計算しておく。
その後、累積距離とAの配列から「対象地域をスキップした場合」の総移動距離を出力する。
"""



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

accm.append(accm[-1]+abs(A[-1]))
base_cost = accm[-1]





for n in range(0,N):
  if n == N-1:
    bene = abs(A[-1])+abs(A[-1]-A[-2])-abs(A[-2])
  elif n == 0:
    bene = abs(A[1]-A[0])+abs(A[0])-abs(A[1])
  else:
    bene = abs(A[n+1]-A[n])+abs(A[n]-A[n-1])-abs(A[n+1]-A[n-1])
  
  ans = base_cost - bene
  print(ans)

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
import queue
import copy


def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z


def bfs(SS, x, y, H, W):
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" 
    for i in range(4): 
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      
      
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" 
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      
  return mlength


def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a


def has_duplicates(seq):
  return len(seq) != len(set(seq))







N = int(input())
A = [int(x) for x in input().split()]

a = abs(A[0])

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

a += abs(A[N-1])

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

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

print(a-abs(A[N-1])-abs(A[N-1]-A[N-2])+abs(A[N-2]))

Solution (Python):
def main():
    spots_number = int(input())
    spots = [0] + list(map(int, input().split(" "))) + [0]
    visit_time = [0] * (spots_number + 2)
    for i in range(1, spots_number + 1):
        visit_time[i] = visit_time[i - 1] + abs(spots[i] - spots[i - 1])
    visit_time[-1] = visit_time[-2] + abs(spots[-2])
    for i in range(1, spots_number + 1):
        print(visit_time[i - 1] + visit_time[-1] - visit_time[i + 1] + abs(spots[i + 1] - spots[i - 1]))


if __name__ == '__main__':
    main()

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



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

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

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

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

Solution (Python):
import sys

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

now = 0
count = 0
t = 0

for i in li:
  t += abs(i - now)
  now = i

t += abs(now)

li.insert(0, 0)
li.append(0)

for n in range(1, N+1):
  print(t - (abs(li[n-1] - li[n])) - abs(li[n] - li[n+1]) + abs(li[n-1] - li[n+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,n+2):
    total+=abs(a[i]-a[i-1])
for i in range(1,n+1):
    print(total-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))