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

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

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

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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.insert(0,0)
l.append(0)
num = 1
sum = 0

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

    
for i in range(1,n+1):
  s1 = abs(l[i+1]- l[i-1])
  s2 = abs(l[i]- l[i-1])
  s3 = abs(l[i+1]- l[i])
  print(sum + s1 - (s2 + s3))

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array([0] + A + [0])

D = np.abs(A[1:] - A[:-1])


sum_D = D.sum()
for i in range(1, N + 1):
    c = np.abs(A[i - 1] - A[i + 1])
    print(sum_D - (D[i - 1] + D[i]) + c)

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

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

for i in range(1,N+1):
    s = S + abs(B[i-1]-B[i+1])-(abs(B[i-1]-B[i])+abs(B[i]-B[i+1]))
    ans.append(s)
for i in range(N):
    print(ans[i])

Solution (Python):
N = int(input())
lst = [0] + [int(x) for x in input().split()] + [0]
total = 0
for i in range(N + 1):
    total += abs(lst[i] - lst[i + 1])

for i in range(1, N + 1):
    a = abs(lst[i - 1] - lst[i])
    b = abs(lst[i] - lst[i + 1])
    c = abs(lst[i - 1] - lst[i + 1])
    print(total - a - b + c)

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

count = 0
for i in range(1,n+2):
    count+=+abs(l[i]-l[i-1])
for i in range(1,n+1):
    if l[i-1] <= l[i] <= l[i+1] or l[i-1] >= l[i] >= l[i+1]:
        print(count)
    else:
        print(count-(abs(l[i]-l[i-1])+abs(l[i+1]-l[i]))+abs(l[i+1]-l[i-1]))

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

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

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

Solution (Python):
from itertools import accumulate
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
cost = [abs(a[i] - a[i+1]) for i in range(n+1)]
acc = [0] + list(accumulate(cost))

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

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

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

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

def costs(a):
    prev = 0
    for x in a:
        yield abs(x - prev)
        prev = x

def main():
    input()
    A = [0] + [int(c) for c in input().split()] + [0]
    total = sum(costs(A))
    for i, x in enumerate(A[1:-1],1):
        prev_cost = abs(x - A[i-1])
        succ_cost = abs(A[i+1] - x)
        print(total - (prev_cost+succ_cost) + abs(A[i+1]-A[i-1]))

if __name__ == "__main__":
    main()

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

def costs(a):
    prev = 0
    for x in a:
        yield abs(x - prev)
        prev = x

def main():
    input()
    A = [0] + [int(c) for c in input().split()] + [0]
    total = sum(costs(A))
    for i, x in enumerate(A):
        if i == 0 or i == len(A)-1: continue
        prev_cost = abs(x - A[i-1])
        succ_cost = abs(A[i+1] - x)
        print(total - (prev_cost+succ_cost) + abs(A[i+1]-A[i-1]))

if __name__ == "__main__":
    main()

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

def total_cost(a):
    before = 0
    total = 0
    for x in a:
        total += abs(x - before)
        before = x
    return total

def main():
    input()
    A = [0] + [int(c) for c in input().split()] + [0]
    total = total_cost(A)
    for i, x in enumerate(A):
        if i == 0 or i == len(A)-1: continue
        prev_cost = abs(x - A[i-1])
        succ_cost = abs(A[i+1] - x)
        print(total - (prev_cost+succ_cost) + abs(A[i+1]-A[i-1]))

if __name__ == "__main__":
    main()

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

Solution (Python):
n=int(input())
a=[0]
a.extend(list(map(int,input().split())))
a.append(0)
s=0
for i in range(n+1):
  s+=abs(a[i+1]-a[i])
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):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    a = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
    num = sum(a)
    print("\n".join(
        [str(num - a[i] - a[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()

Solution (Python):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    a = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    num = sum(a)
    print("\n".join(
        [str(num - a[i] - a[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()

Solution (Python):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    d = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    num = sum(d)
    print("\n".join(
        [str(num - d[i] - d[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()

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

yen = abs(ls[0])

for i in range(n - 1):
    yen += abs(ls[i + 1] - ls[i])

yen += abs(ls[n - 1])

for j in range(n):
    if j == 0:
        print(yen - abs(ls[0]) - abs(ls[1] - ls[0]) + abs(ls[1]))
    elif j == n - 1:
        print(yen - abs(ls[n - 1]) - abs(ls[n - 1] - ls[n - 2]) + abs(ls[n - 2]))
    else:
        print(yen - abs(ls[j + 1] - ls[j]) - abs(ls[j] - ls[j - 1]) + abs(ls[j + 1] - ls[j - 1]))

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

Solution (Python):
def solve(n, A):
    A = [0] + A + [0]
    diffs = [abs(A[i] - A[i + 1]) for i in range(n + 1)]
    total = sum(diffs)
    return [total - diffs[i] - diffs[i + 1] + abs(A[i] - A[i + 2]) for i in range(n)]

_n = int(input())
_A = list(map(int, input().split()))
print(*solve(_n, _A), sep='\n')

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

for i in range(N):
  if i==0:
    print(D-abs(A[0])-abs(A[1]-A[0])+abs(A[1]))
  elif i==(N-1):
    print(D-abs(A[N-1])-abs(A[N-1]-A[N-2])+abs(A[N-2]))
  else:
    print(D-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]

s = 0



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

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

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

A = [0]
A.extend(map(int, input().split()))
A.append(0)

S = 0
for i in range(N+2):
  if i+1 == N+2:
    continue
  S += abs(A[i+1] - A[i])
  
for i in range(1, N+1):
  tmp = S
  x = abs(A[i+1] - A[i-1])
  y = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
  tmp -= y-x
  print(tmp)

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

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

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

each_abs = [abs(nums[0])]
for i in range(1, n):
    each_abs.append(abs(nums[i] - nums[i-1]))

each_abs.append(abs(nums[-1]))
s = sum(each_abs)

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

del_list = []
for i in range(n):
    del_list.append(each_abs[i] + each_abs[i+1])

for i in range(n):
    print(s + add_list[i] - del_list[i])

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

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

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

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

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

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

list = [0] + list + [0]

total = 0


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


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

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

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


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


for i in range(1,n+1):
  ans=de
  x=a[i-1]
  y=a[i]
  z=a[i+1]
  if a[i-1]<=a[i]<=a[i+1] or a[i-1]>=a[i]>=a[i+1]:
    pass
  elif x<=z<=y or y<=z<=x:
    ans-=abs(a[i]-a[i+1])*2
  else:
    ans-=abs(a[i]-a[i-1])*2
  print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


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

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


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



if __name__ == '__main__':
    main()

Solution (Python):


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

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


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

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

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

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

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

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

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

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

Solution (Python):

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

B = []

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

distance = sum(B)

for i in range(1, N+1):
  sub = B[i-1] + B[i]
  add = abs(A[i+1] - A[i-1])
  print(distance - sub + add)

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

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

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

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 = [0] + list(map(int, input().split())) + [0]

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


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

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

li1 = [0,abs(a[1])]
li2 = [0,abs(a[n])]

for i in range(2,n+1):
    li1.append(abs(a[i-1]-a[i])+li1[len(li1)-1])
    li2.append(abs(a[n-i+1]-a[n-i+2])+li2[len(li2)-1])
    
li1.append(abs(a[n])+li1[len(li1)-1])
li2.append(abs(a[1])+li2[len(li2)-1])





for i in range(1,n+1):
    print(li1[i-1]+li2[n-i]+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)
time = 0
now = 0
for i in range(N+2):
    time += abs(A[i]-now)
    now = A[i]
for i in range(1,N+1):
    if A[i-1] <= A[i] <= A[i+1]:
        print(time)
    else:
        print(time-((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=[0]+A+[0]

dist=0
diff=[0]*(len(A)-2)
for i in range(len(A)-1):
  dist+=abs(A[i+1]-A[i])
  if 1<=i<=len(A)-2:
    diff[i-1]=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
  
for i in range(len(diff)):
  print(dist-diff[i])

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

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
A=[0]
a=list(map(int,input().split()))
for i in range(N):
    A.append(a[i])
A.append(0)

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

for i in range(1,N+1):
    ans=l
    if (A[i+1]-A[i])*(A[i]-A[i-1])<0:
        ans=l-2*min(abs(A[i+1]-A[i]),abs(A[i]-A[i-1]))
    print(ans)

"""if amin>0:
    for i in range(N):
        if A[i]!=amax:
            print(amax*2)
        else:
            print(amax2*2)
elif amax<0:
    for i in range(N):
        if A[i]!=amin:
            print(-amin*2)
        else:
            print(-amin2*2)
else:
    for i in range(N):
        if A[i]!=amax:
            if A[i]!=amin:
                print("A",amax*2-amin*2)
            else:
                if amin2>=0:
                    print(amax*2)
                else:
                    print(amax*2-amin2*2)
        else:
            if amax2<0:
                print(-amin*2)
            else:
                print(-amin*2+amax2*2)"""

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

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

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

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

Solution (Python):

import sys
sys_input = sys.stdin.readline

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

basic_cost = sum([abs(AAA[i + 1] - A) for i, A in enumerate(AAA[:N + 1])])

for i, A in enumerate(AAA[:N + 1]):
    if i == 0:
        continue
    adjusted_cost = basic_cost - abs(A - AAA[i-1]) - abs(A - AAA[i+1]) + \
        abs(AAA[i+1]-AAA[i-1])
    print(adjusted_cost)

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

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

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

As = [0] + As + [0]
dist = [As[i]-As[i-1] for i in range(1,N+2)]
absdist = [abs(d) for d in dist]
s = sum(absdist)
for i in range(N):
    minus = abs(As[i+1]-As[i]) + abs(As[i+2]-As[i+1])
    plus = abs(As[i+2] - As[i])
    print(s+plus-minus)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    dif = [0]*(N+1) 
    dif2 = [0]*N
    A = [0] + A + [0]
    for i in range(N+1):
        dif[i] = abs(A[i+1]-A[i])
    for i in range(N):
        dif2[i] = abs(A[i+2]-A[i])
    total_distance = sum(dif)
    
    
    for i in range(N):
        print(total_distance-dif[i]-dif[i+1]+dif2[i])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

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

*A, = map(int, input().split())
A.insert(0,0)
A.append(0)

sum = 0

for i in range(1,N+2,1):

    sum = sum + abs(A[i]-A[i-1])


for i in range(1,N+1,1):
    print(sum + 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(i) for i in input().split()]
a.append(0)
cost = []

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

sumcost = sum(map(abs,cost))

for i in range(n):
    ans = sumcost
    if cost[i] * cost[i+1] < 0:
        ans -= 2*min(abs(cost[i]),abs(cost[i+1]))
    print(ans)

Solution (Python):
N = int(input())
A = [0]*(N+2)
B = [0]*N

for i,x in enumerate(input().split()):
  A[i+1] = int(x)

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

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

for i in range(N):
  print(s-B[i])

Solution (Python):
N = int(input())
A = [0]*(N+2)
B = [0]*N

for i,x in enumerate(input().split()):
  A[i+1] = int(x)

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

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

for i in range(N):
  print(s-B[i])

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

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

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

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

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

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

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

Solution (Python):
import sys
import numpy as np 

n, *a = map(int, sys.stdin.read().split())
a = np.array([0] + a + [0])

def main():
    res1 = np.absolute(a[2:] - a[1:-1]) + np.absolute(a[1:-1] - a[:-2])
    res2 = np.absolute(a[2:] - a[:-2])
    default = np.absolute(a[1:] - a[:-1]).sum()
    
    ans = default - (res1 - res2)
    return ans

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    cur_x = 0
    tot = 0
    for a in A:
        tot += abs(cur_x - a)
        cur_x = a
    tot += abs(cur_x - 0)
    A.append(0)
    cur_x = 0
    for i in range(N):
        print(tot - abs(cur_x - A[i]) - abs(A[i] - A[i+1]) + abs(cur_x - A[i+1]))
        cur_x = A[i]
main()

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

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

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

B = [0] + A + [0]
total = 0

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

for i in range(1, N + 1):
    b = B[i]
    b_next = B[i + 1]
    b_prev = B[i - 1]
    ans = total - (abs(b - b_prev) + abs(b_next - b)) + abs(b_next - b_prev)
    print(ans)

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

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

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

D = [] 
now = 0

total = 0
for new1, new2 in zip(A[:-1], A[1:]):
    dist = abs(new1 - now)
    total += dist

    no_skip = abs(new2 - new1) + dist
    skip = abs(new2 - now)
    delta = skip - no_skip
    D.append(delta)
    now = new1

for i in range(n):
    ans = total + D[i]
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
A_diff = np.diff(A)
total = abs(A_diff).sum()
for i in range(1,N+1):
    ans = total
    ans -= abs(A_diff[i]) + abs(A_diff[i-1]) 
    ans += abs(A[i+1] - A[i-1])
    print(ans)

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

Solution (Python):

import sys
input = sys.stdin.readline

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

a = [0] + a + [0]

total_cost = sum([abs(i-j) for i,j in zip(a,a[1::])])

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

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

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
SUM=abs(A[0])
ans=[0]*n
for i in range(n-1):
    SUM+=abs(A[i+1]-A[i])
SUM+=abs(A[n-1])
A.append(0)
for i in range(n):
    if i==0:
        if A[i]<min(A[i+1],0):
            ans[i]=SUM-2*(min(A[i+1],0)-A[i])
        elif A[i]>max(A[i+1],0):
            ans[i]=SUM-2*(A[i]-max(A[i+1],0))
        else:
            ans[i]=SUM
    elif A[i]<min(A[i+1],A[i-1]):
        ans[i]=SUM-2*(min(A[i+1],A[i-1])-A[i])
    elif A[i]>max(A[i+1],A[i-1]):
        ans[i]=SUM-2*(A[i]-max(A[i+1],A[i-1]))
    else:
        ans[i]=SUM
print(*ans,sep='\n')

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