Problem:
 Score : 300 points    Problem Statement There are N sightseeing spots on the x -axis, numbered 1, 2, ..., N .
Spot i is at the point with coordinate A_i .
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0 , then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0 .  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i .
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N , find the total cost of travel during the trip when the visit to Spot i is canceled.      Constraints  2 \leq N \leq 10^5  -5000 \leq A_i \leq 5000 ( 1 \leq i \leq N )  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print N lines.
In the i -th line, print the total cost of travel during the trip when the visit to Spot i is canceled.        Sample Input 1 3
3 5 -1      Sample Output 1 12
8
10  Spot 1 , 2 and 3 are at the points with coordinates 3 , 5 and -1 , respectively.
For each i , the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:   For i = 1 , the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.  For i = 2 , the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.  For i = 3 , the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.        Sample Input 2 5
1 1 1 2 0      Sample Output 2 4
4
4
2
4       Sample Input 3 6
-679 -2409 -3258 3095 -3291 -4462      Sample Output 3 21630
21630
19932
8924
21630
19288

Solution (Python):
N = int(input())
A = [0]+[int(X) for X in input().split()]+[0]
Cost = sum(abs(A[T+1]-A[T]) for T in range(N+1))
for T in range(1,N+1):
    Cut = Cost+abs(A[T+1]-A[T-1])-abs(A[T]-A[T-1])-abs(A[T+1]-A[T])
    print(Cut)

Solution (Python):
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
B = [abs(a-b) for a,b in zip(A,A[1:])]
C = sum(B)

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

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

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

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

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

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

dist_cum = [0] * (N+2)
for i in range(N+1):
    dist_cum[i+1] = dist_cum[i] + dist[i+1]

for i in range(1, N+1):
    if A[i-1] < A[i] and A[i] < A[i+1]:
        print(dist_cum[-1])
    elif A[i-1] > A[i] and A[i] > A[i+1]:
        print(dist_cum[-1])
    else:
        tmp = dist_cum[i-1]
        tmp += dist_cum[-1] - dist_cum[i+1]
        tmp += abs(A[i+1] - A[i-1])
        print(tmp)

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

for i in a:
    total += abs(i-pre)
    pre = i

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

Solution (Python):
from copy import deepcopy
n=int(input())
A=list(map(int, input().split()))
B=[0]+deepcopy(A)+[0]
total=0
b=0
for a in A:
    total+=abs(a-b)
    b=a
total+=abs(b)
for i in range(1,n+1):
    z,x,c=B[i-1], B[i], B[i+1]
    print(total-abs(x-z)-abs(c-x)+abs(c-z))

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

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N=z()
A = zz()
A.append(0)
diff = [0]*N
prev = 0
A_ = [0]
A_.extend(A)
sum_ = 0
for i in range(len(A_)-1):
    sum_ += abs(A_[i] - A_[i + 1])
    
for i in (range(1,N+1)):
    sub = abs(A_[i]-A_[i-1]) + abs(A_[i] - A_[i+1])
    add = abs(A_[i - 1] - A_[i + 1])
    print(sum_ + add - sub)

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

res = 0

al.append(0)
al.insert(0,0)

for i in range(n+1):
    res += abs(al[i+1]-al[i])

for j in range(1,n+1):
    if (al[j+1]-al[j]) * (al[j]-al[j-1]) >= 0:
        print(res)
    else:
        print(res - min(abs(al[j+1]-al[j]),abs(al[j]-al[j-1]))*2)

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

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

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

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


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


print(total - abs(a_li[-1]) - abs(a_li[-1] - a_li[-2]) + abs(a_li[-2]))

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

A_sum=0
a_start=0
for a in A:
    A_sum += abs(a_start-a)
    a_start=a
a=0
A_sum += abs(a_start-a)

A_=[0]
A_.extend(A)
A_.append(0)
for a_idx in range(1,len(A_)-1):
    a_before = A_[a_idx-1]
    a_ = A_[a_idx]
    a_after = A_[a_idx+1]
    print(A_sum-(abs(a_-a_before)+abs(a_-a_after)-abs(a_before-a_after)))

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

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

total = sum(nums)
for i in range(n):
  ans = total - nums[i] - nums[i+1] + abs(a[i]-a[i+2])
  print(ans)

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

a = [0]+a+[0]

d=[]

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    M = 0
    for n in range(N + 1):
        M += abs(A[n] - A[n + 1])

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


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from copy import deepcopy
def main():
    n, *a = map(int, read().split())

    if n == 2:
        r = [abs(a[1] * 2), abs(a[0] * 2)]
        print(*r, sep='\n')
        sys.exit()

    amin = min(a)
    
    
    a.insert(0, 0)
    a.append(0)
    
    
    if amin < 0:
        a2 = [i - amin for i in a] 
    else:
        a2 = deepcopy(a)
    
    cost = 0
    for i1 in range(n + 1):
        cost += abs(a2[i1] - a2[i1 + 1])
    
    r = [cost] * (n + 2)
    
    for j in range(1, n + 1):
        if a2[j - 1] <= a2[j] <= a2[j + 1]:
            continue
        elif a2[j - 1] >= a2[j] >= a2[j + 1]:
            continue
        elif a2[j - 1] <= a2[j] and a2[j + 1] <= a2[j]:
            nearer_dis = min(abs(a2[j - 1] - a2[j]), abs(a2[j] - a2[j + 1]))
            r[j] -= nearer_dis * 2
        else:
            nearer_dis = min(abs(a2[j] - a2[j - 1]), abs(a2[j + 1] - a2[j]))
            r[j] -= nearer_dis * 2
    print(*r[1:-1], sep='\n')


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    cost = 0
    pre = 0
    for a in A[1:]:
        cost += abs(a - pre)
        pre = a

    for i, a in enumerate(A):
        if i == 0 or i == N + 1: continue
        print(cost - abs(a - A[i - 1]) - abs(a - A[i + 1]) + abs(A[i + 1] - A[i - 1]))


if __name__ == "__main__":
    main()

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

d=0
a = [0] + a + [0]
for j in range(len(a)-1):
    d += abs(a[j]-a[j+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(d)
    else:
        print(d - abs(a[i-1]-a[i]) - abs(a[i+1]-a[i]) + abs(a[i-1]-a[i+1]))

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
idou=[abs(lst[0])]
for i in range(1,n):
    idou.append(abs(lst[i]-lst[i-1]))
idou.append(abs(lst[-1]))
kyori=sum(idou)


kyo=kyori-(idou[0]+idou[1])
kyo+=abs(lst[1])
print(kyo)

for i in range(1,n-1):
    kyo=kyori-(idou[i]+idou[i+1])
    kyo+=(abs(lst[i+1]-lst[i-1]))
    print(kyo)

kyo=kyori-(idou[-1]+idou[-2])
kyo+=abs(lst[-2])
print(kyo)

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

N = int(input())
A = list(map(int,input().split()))
b = [0]
for i in range(N):
    b.append(A[i])
b.append(0)

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

for j in range(1,N+1):
    sumc = sumb
    sumc = sumc - abs(b[j+1]-b[j])-abs(b[j]-b[j-1])+abs(b[j+1]-b[j-1])
    print(sumc)

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

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

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

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

d=[0]
d=d+al
d.append(0)
totald=0
for i in range(1,n+2):
    totald+=abs(d[i]-d[i-1])

for i in range(1,n+1):
    minus=abs(d[i]-d[i-1])+abs(d[i+1]-d[i])
    add=abs(d[i+1]-d[i-1])
    print(totald-minus+add)

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

    cumsum = [0] * (n+1)
    for i in range(1, n+2):
        cumsum[i-1] = abs(As[i] - As[i-1])
    cumsum_sum = sum(cumsum)
    for i in range(1, n+1):
        ans = cumsum_sum - cumsum[i-1] - cumsum[i] + abs(As[i+1] - As[i-1])
        print(ans)


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = [0] + in_nl() + [0]
    N = N + 2

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

    ans = [0] * (N - 2)
    for i in range(1, N - 1):
        if A[i - 1] <= A[i] and A[i] <= A[i + 1]:
            ans[i - 1] = dsum
        elif A[i - 1] >= A[i] and A[i] >= A[i + 1]:
            ans[i - 1] = dsum
        elif A[i - 1] <= A[i] and A[i] >= A[i + 1]:
            ans[i - 1] = dsum - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
        elif A[i - 1] >= A[i] and A[i] <= A[i + 1]:
            ans[i - 1] = dsum - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()

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

B=[0]+A+[0]
count=[0]*N
S=abs(B[1]-0)
i=1
while i<=N:
    if B[i-1]<=B[i]<=B[i+1] or B[i-1]>=B[i]>=B[i+1]:
        count[i-1]=0
    else:
        count[i-1]=2*min(abs(B[i]-B[i-1]),abs(B[i+1]-B[i]))
    S+=abs(B[i+1]-B[i])
    i+=1

for c in count:
    print(S-c)

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

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


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
n = int(input())
spot = [0] + list(map(int, input().split())) + [0]
mlst = []
plst = []
dissum = 0
for i in range(1, n + 1):
  mlst.append(abs(spot[i + 1] - spot[i]) + abs(spot[i] - spot[i - 1]))
  plst.append(abs(spot[i + 1] - spot[i - 1]))
  dissum += abs(spot[i] - spot[i - 1])
dissum += abs(spot[n])
for i in range(n):
  print(dissum - mlst[i] + plst[i])

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

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    A = [0]+list(mi())+[0]
    S = sum(abs(A[i]-A[i+1]) for i in range(N+1))
    l = [S-abs(A[i]-A[i+1])-abs(A[i+1]-A[i+2])+abs(A[i]-A[i+2]) for i in range(N)]
    print(*l, sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

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

Solution (Python):

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

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

for ind in range(1, N + 1):
    res = full_res - sum(full_place[ind - 1:ind + 1]) + abs(full_root[ind - 1] - full_root[ind + 1])

    print(res)

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

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


sm1=sm_al-abs(a[1]-a[0])-abs(a[0])+abs(a[1])
print(sm1)

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

smn=sm_al-abs(a[n-1]-a[n-2])-abs(a[n-1])+abs(a[n-2])
print(smn)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

l = [0,*a,0]


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

for i in range(1, n + 1):
    delcost = abs(l[i + 1] - l[i]) + abs(l[i] - l[i - 1])
    addcost = abs(l[i + 1] - l[i - 1])
    print(s - delcost + addcost)

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

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

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

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

s_d = sum(d_1)
for i in range(1, n+1):
  print(s_d - d_1[i-1] - d_1[i] + d_2[i-1])

Solution (Python):

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array([0] + lr() + [0])
diff = np.diff(A)
total = np.abs(diff).sum()
answer = []
for i in range(N):
    answer.append(total - abs(diff[i]) - abs(diff[i+1]) + abs(A[i+2]-A[i]))

print('\n'.join(map(str, answer)))

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

for i in range(N):
    if i == 0:
        if (0 <= A[i] <= A[i+1]) or (A[i+1] <= A[i] <= 0):
            tmp = ans 
        else:
            tmp = ans - abs(A[0]) - abs(A[0]-A[1]) + abs(A[1])
        print(tmp)
    elif i == N-1:
        if (0 <= A[i] <= A[i-1]) or (A[i-1] <= A[i] <= 0):
            tmp = ans
        else:
            tmp = ans - abs(A[i]-A[i-1]) - abs(A[i]) + abs(A[i-1])
        print(tmp)
    else:
        if (A[i-1] <= A[i] <= A[i+1]) or (A[i-1] >= A[i] >= A[i+1]):
            print(ans)
        else:
            tmp = ans - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i+1]-A[i-1])
            print(tmp)

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left, bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

dist = 0
difs = [0]*N
for i, a in enu(A[:-2]):
    c = a
    n = A[i+1]
    nn = A[i+2]
    dist += abs(n-c)

    dif = 0 
    flg_dif = (c<=n)^(n<=nn)
    if flg_dif:
        difs[i] = min(2*abs(n-c), 2*abs(nn-n))
dist += abs(A[-2])



for i, a in enu(A[1:-1]):
    print(dist-difs[i])

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
ais = [0]
ais.extend(As)
m = 0
ais.append(m)
S = 0
for i in range(n-1):
  S += abs(As[i]-As[i+1])
S += abs(As[0]) + abs(As[n-1])
for i in range(1,n+1):
  sb1 = abs(ais[i-1]-ais[i])
  sb2 = abs(ais[i]-ais[i+1])
  ad = abs(ais[i-1]-ais[i+1])
    
  ans = S - sb1 - sb2 + ad
  print(ans)

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
S = 0
for i in range(n-1):
  S += abs(As[i]-As[i+1])
S += abs(As[0]) + abs(As[n-1])
for i in range(n):
  if i == 0:
    sb1 = abs(As[i])
    sb2 = abs(As[i]-As[i+1])
    ad = abs(As[i+1])
  elif i == n-1:
    sb1 = abs(As[i-1]-As[i])
    sb2 = abs(As[i])
    ad = abs(As[i-1])
  else:
    sb1 = abs(As[i-1]-As[i])
    sb2 = abs(As[i]-As[i+1])
    ad = abs(As[i-1]-As[i+1])
    
  ans = S - sb1 - sb2 + ad
  print(ans)

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

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

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


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

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

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

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

s = []
for i in range(n+1):
    s.append(abs(a[i]-a[i+1]))
ss = sum(s)
for i in range(1,n+1):
    print(ss+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()))
pre = 0
sumall = 0

for i in range(N):
   sumall += abs(A[i] - pre)
   pre = A[i]

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

Solution (Python):
import copy
n=int(input())
a=[int(x) for x in input().rstrip().split()]
aa=copy.deepcopy(a)
a=[0]+a+[0]
sa=[]
for i in range(n+1):
  sa.append(abs(a[i+1]-a[i]))

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

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

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

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

  
for j in range(n):  
  if abs(l[j+2]-l[j])<abs(l[j+1]-l[j])+abs(l[j+2]-l[j+1]):
    if abs(l[j+1]-l[j])<abs(l[j+2]-l[j+1]):
      print(wa-2*abs(l[j+1]-l[j]))
    else:
      print(wa-2*abs(l[j+2]-l[j+1]))
  else:
    print(wa)

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

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] - a[i + 1]))

ref = sum(d)

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

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


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



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

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

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

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

for i in range(1, N+1):
    left = locate[i] - locate[i-1]
    right = locate[i+1] - locate[i]
    if left*right < 0:
        print(ALL - 2 * min(abs(left), abs(right)))
    else:
        print(ALL)

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

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

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

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n = int(input())
    A =[0] +  list(map(int,input().split())) + [0]
    prf = [0]
    for i in range(1,n+2):
        d = abs(A[i] - A[i-1])
        prf.append(prf[i-1] + d)
    for i in range(1,n+1):
        ans = prf[-1] - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1]-A[i-1])
        print(ans)

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

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

for i in range(1, len(a)-1):
    tmp = s + 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_list = [0] + [int(x) for x in input().split()] + [0]
d1_list = [abs(a_list[i + 1] - a_list[i]) for i in range(n + 1)]
d2_list = [abs(a_list[i + 2] - a_list[i]) for i in range(n)]
travel_all = sum(d1_list)
for i in range(n):
    print(travel_all - d1_list[i] - d1_list[i + 1] + d2_list[i])

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

for i in range(1, n+1):
  if (a0[i]-a0[i-1])*(a0[i+1]-a0[i]) >= 0:
    print(suma)
  else:
    print(suma-abs(a0[i]-a0[i-1])-abs(a0[i+1]-a0[i])+abs(a0[i+1]-a0[i-1]))

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

costs = [0]
for a, b in zip(A[:-1], A[1:]):
    costs.append(abs(a-b))

from itertools import accumulate
costs_acc = list(accumulate(costs))

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

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