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

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

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

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

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

Solution (Python):
N = int(input())
a_list = [a for a in map(int, input().split())]
a_list.insert(0, 0)
a_list.append(0)
S = 0
before = 0
for a in a_list:
    S += abs(a - before)
    before = a

for i in range(1, N+1):
    a = a_list[i]
    s = S + abs(a_list[i-1] - a_list[i+1]) - (abs(a_list[i-1] - a_list[i]) + abs(a_list[i] - a_list[i+1]))
    print(s)

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

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

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

A.append(0)
money = [0]
for i in range(1, len(A)):
    money[0] += abs(A[i] - A[i - 1])


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

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

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

a_list = a_list + [0]


s = 0
before = 0
for i in a_list:
    s += abs(before - i)
    before = i



diff = 0
before = 0

for ind, i in enumerate(a_list):
    
    new_diff = i - before
    if diff * new_diff >= 0:
        if ind != 0:
            print(s)

    else:
        if ind != 0:
            print(s - 2 * min(abs(diff), abs(new_diff)))

    diff = new_diff
    before = i

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

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

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


if __name__ == '__main__':
    main()

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

for i in range(n):
    t = b
    if not (a[i]<=a[i+1]<=a[i+2] or a[i]>=a[i+1]>=a[i+2]):
        t -= abs(a[i]-a[i+1])
        t -= abs(a[i+1]-a[i+2])
        t += abs(a[i]-a[i+2])
    print(t)

Solution (Python):
N = int(input())
an = [0] + [int(i) for i in input().split()]+[0]
cn = [abs(an[i+1]-an[i]) for i in range(N+1)]
ct = sum(cn)
cs = [ct-cn[i]-cn[i+1]+abs(an[i]-an[i+2]) for i in range(N)]
print('\n'.join(map(str,cs)))

Solution (Python):
N = int(input())
an = [0] + [int(i) for i in input().split()]+[0]
t = sum([abs(an[i+1]-an[i]) for i in range(N+1)])
ts = []
for i in range(N):
  a,b,c = an[i:i+3]
  ts.append(t+(0 if 0 <= (a-b)*(b-c) else -2*(min(abs(a-b),abs(b-c)))))
print('\n'.join(map(str,ts)))

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

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

for i in range(1, N+1):
  if A[i-1] <= A[i] <= A[i+1]:
    print(full)
  else:
    print(full - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]))

Solution (Python):

"""
Created on Wed Aug  8 14:35:24 2018

@author: sugawara
"""


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






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

A = [0] + A + [0]
res = []
for i in range(N):
    res.append(sum_of_all - 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(res[i])

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N = int(input())
    A = li_input()
    A.insert(0, 0)
    A.append(0)

    total = 0

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

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


main()

Solution (Python):
import numpy as np

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




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




for i in range(1, len(A) - 1):
    d = orig_dist - \
        abs(A[i+1] - A[i]) - \
        abs(A[i] - A[i-1]) + \
        abs(A[i+1] - A[i-1])
    print(d)

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

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

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

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

d = []


prev = 0
for i in range(N + 1) :
    if i == 0 : d.append(abs(a[i]))
    elif i == N : d.append(abs(a[i - 1]))
    else : d.append(abs(prev - a[i]))
    
    if i != N : prev = a[i]

totsum = sum(d)

for i in range(N) :
    
    if i == 0 :
        x, y, z = 0, a[i], a[i + 1]
    elif i == N - 1 :
        x, y, z = a[i - 1], a[i], 0
    else :
        x, y, z = a[i - 1], a[i], a[i + 1]

    if x <= y <= z or x >= y >= z :
        print(totsum)
    else :
        print(totsum - abs(d[i] + d[i + 1]) + abs(d[i] - d[i + 1]))

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

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

total = sum(cost)

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

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

list=[0]
list += a
list += [0]

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

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

Solution (Python):


def main():
    n = int(input()) + 2
    a_list = list(map(int, input().split()))
    a_list.insert(0,0)
    a_list.append(0)

    all_price = 0
    for i in range(1, n):
        all_price += abs(a_list[i] - a_list[i-1])
    
    for i in range(1, n-1):
        diff = abs(a_list[i] - a_list[i-1]) + abs(a_list[i+1] - a_list[i]) - abs(a_list[i+1] - a_list[i-1])
        print(all_price - diff)

if __name__ == '__main__':
    main()

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

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

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

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

for i in range(n):
  if i==0:
    t1 = 0
  else:
    t1 = a[i-1]
  if i==n-1:
    t3 = 0
  else:
    t3 = a[i+1]
  t2 = a[i]
  ans = s+abs(t3-t1)-(abs(t3-t2)+abs(t2-t1))
  print(ans)

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

for i in range(1,N+1):
    if min(B[i-1],B[i+1]) <= B[i] and B[i] <= max(B[i-1],B[i+1]):
        print(sums)
    else:
        print(sums-2*min(abs(B[i]-B[i-1]),abs(B[i]-B[i+1])))

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

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

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


for i in range(N):
    ss = s
    ss -= abs(d[i]) + abs(d[i+1]) - abs(d[i] + d[i+1])
    print(ss)

Solution (Python):


N = int(input())


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


All = []
for i in range(N+1):
	All.append(abs(AN[i] - AN[i+1]))
dist = sum(All)


for i in range(1, N+1):
	tmp = dist
	tmp -= All[i-1] + All[i]
	tmp += abs(AN[i-1] - AN[i+1])
	print(tmp)

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

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

A2=[0]+A+[0]

D=0

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
summ = 0
i = 0
while i < N-1:
  summ += abs(A[i]-A[i+1])
  i += 1
print(abs(A[1])+abs(A[N-1])+summ-abs(A[0]-A[1]))
j = 1
while j < N-1:
  print(abs(A[0])+abs(A[N-1])+summ-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])+abs(A[j-1]-A[j+1]))
  j += 1
print(abs(A[0])+abs(A[N-2])+summ-abs(A[N-2]-A[N-1]))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
result_1 = 0
result_1 += abs(a[0])
for i in range(n-1):
    result_1 += abs(a[i+1]-a[i])
result_1 += abs(a[n-1])
a.insert(0,0)
a.insert(n+1,0)
for i in range(n):
    if a[i+2] >= a[i+1] >= a[i] or a[i+2] <= a[i+1] <= a[i]:
        print(result_1)
    else:
        b = abs(a[i+2]-a[i+1])
        c = abs(a[i+1]-a[i])
        d = abs(a[i+2]-a[i])
        result = result_1 - (b + c - d)
        print(result)

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

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

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

Solution (Python):

def main():
    n = int(input())
    ai = [int(i) for i in input().split()]
    ai = [0] + ai + [0]

    z = sum([abs(y - x) for x, y in zip(ai, ai[1:])])
    for i in range(1, len(ai)-1):
        zz = z
        zz -= abs(ai[i-1] - ai[i])
        zz -= abs(ai[i] - ai[i+1])
        zz += abs(ai[i-1] - ai[i+1])
        print(zz)

if __name__ == '__main__':
    main()

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

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

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

def cost_delta(A, index):
    size = len(A)
    d = abs(A[index-1] - A[(index+1)%size])
    d -= abs(A[index] - A[(index+1)%size])
    d -= abs(A[index-1] - A[index])
    return d


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

for i in range(1,N):
    delta = cost_delta(A, i)
    print(total_cost + delta )

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

Solution (Python):
N = int(input())
spot = list(map(int,(input()).split()))
cost = []
cost1 = []

spot = [0] + spot + [0]

for i in range(N+1):
    cost.append(abs(spot[i+1]-spot[i]))

for i in range(N):
    cost1.append(abs(spot[i+2]-spot[i]))

costsum = 0
for i in cost:
    costsum += i

for i in range(1,N+1):
    prisum = costsum
    prisum = prisum - cost[i-1] - cost[i] + cost1[i-1]
    print(prisum)

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

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

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

A_sum = sum([abs(a1-a2) for a1, a2 in zip(A, A[1:])])

for i in range(1,N+1):
    print(A_sum + 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.insert(N, 0)
A.insert(0, 0)
cost_sum = 0
for i in range(1, len(A)):
	cost_sum += abs(A[i] - A[i-1])
for i in range(1, len(A) - 1):
	print(cost_sum + abs(A[i-1] - A[i+1]) - abs(A[i-1] - A[i]) - abs(A[i+1] - A[i]))

Solution (Python):
from itertools import islice

n = int(input())
xs = [0] + [int(x) for x in input().split()] + [0]


total = sum(abs(a-b) for a,b in zip(xs, islice(xs, 1, None)))

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

Solution (Python):
N = int(input())
a_list = input().split(" ")
A_list = list(map(int,a_list))
A_list.insert(0,0)

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

sum_len += abs(A_list[N])

for j in range(1,N+1):
	if(j != N):
		length = sum_len - (abs(A_list[j-1]-A_list[j])+abs(A_list[j]-A_list[j+1]))
		length += abs(A_list[j-1]-A_list[j+1])
		print(length)
	elif(j == N):
		length = sum_len - abs(A_list[j-1]-A_list[j]) - abs(A_list[j])
		length += abs(A_list[j-1])
		print(length)

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

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


  
COST=[None]*N

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

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

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

money = abs(A[0]) + abs(A[N-1])

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

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
all = abs(a[0]) + abs(a[n-1])
for i in range(n-1):
	all += abs(a[i+1] - a[i])
for u in range(n):
	if u == 0:
		print(all + abs(a[1]) - abs(a[0]) - abs(a[1] - a[0]))
	elif u == n-1:
		print(all + abs(a[n-2]) - abs(a[n-1]) - abs(a[n-1] - a[n-2]))
	else:
	    b = abs(a[u] - a[u-1])
	    c = abs(a[u+1] - a[u])
	    d = abs(a[u+1] - a[u-1])
	    print(all - b - c + d)

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(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):
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
distance = []

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


dist_sum = sum(distance)

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

Solution (Python):

N=int(input())

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

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


for k in range(1,N+1):
    mae=A[k-1]
    usiro=A[k+1]
    if mae<= A[k]<=usiro or usiro<= A[k]<=mae:
        print(tujyo)
    else:
        print(tujyo-abs(A[k]-mae)-abs(usiro-A[k])+abs(usiro-mae))

Solution (Python):
n = int(input())
lis = [0] + list(map(int,input().split())) + [0]
b = 0
for i in range(n+1):
 b += abs(lis[i+1]-lis[i])
for i in range(1,n+1):
 if (lis[i-1] <= lis[i] <= lis[i+1]) or (lis[i+1] <= lis[i] <= lis[i-1]):
   print(b)
 else:
  print(b-abs(lis[i-1] - lis[i]) - abs(lis[i+1] - lis[i]) + abs(lis[i+1] - lis[i-1]))

Solution (Python):
n = int(input())
A = list(map(int, input().split(' ')))
A.insert(0,0)
A.append(0)
An = [abs(A[1] - A[0])]
Ann = []
i = 0
while i < n:
    An.append(abs(A[i+2] - A[i+1]))
    Ann.append(abs(A[i+2] - A[i]) - An[i] - An[i+1])
    i += 1
s = sum(An)
ans = ""
for q in Ann:
    ans += str(q + s) + '\n'
print(ans[:-1])

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

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

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

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

def main():
    A.insert(0, 0)
    A.append(0)

    costs = 0
    skip_benf = []
    for i in range(len(A) - 1):
        p1 = A[i]
        p2 = A[i + 1]
        cost = abs(p1 - p2)
        costs += cost

        if i > N - 1:
            continue

        p3 = A[i + 2]
        benf = (cost + abs(p2 - p3) - abs(p1 - p3))
        skip_benf.append(benf)

    for benf in skip_benf:
        ans = costs - benf
        print(ans)

if __name__ == "__main__":
    main()

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


m()

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

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

for i in range(n):
    print(num - rec[i][0] - rec[i][1] + rec[i][2])

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

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

now = 0
d = []
for p in a + [0]:
    d.append(abs(p - now))
    now = p

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

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

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

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

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

Solution (Python):
n=int(input())
A=[0]
A.extend([int(i) for i in input().split()])
A.append(0)
Sb=[0 for i in range(n+2)]
t=0

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

for i in range(1,n+1):
  if max(abs(A[i]),abs(A[i-1]),abs(A[i+1])):
    cb=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])
    ca=abs(A[i+1]-A[i-1])
    print(t-cb+ca)
  else:
    print(t)

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

S = 0
Slist = []
for i in range(len(B)-1):
    distance = abs(B[i] - B[i+1])
    Slist.append(distance)
    S += distance

for j in range(len(A)):
    print(S + abs(B[j]-B[j+2]) - Slist[j] - Slist[j+1])

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

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

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

if __name__ == '__main__':
    main()

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

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

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

for i in range(1,N+1):
    ans = d + 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 = [int(x) for x in input().split()]

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

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

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

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

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

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

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

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

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

sched = abs(A[0])

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

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

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

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

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
sum_before = 0
for i in range(n-1):
    sum_before += abs(a[i] - a[i+1])
sum_before += abs(a[0])+abs(a[n-1])
for i in range(n):
    if i == 0:
        print(sum_before-(abs(a[0])+abs(a[1]-a[0])) + abs(a[1]))
    elif i == n-1:
        print(sum_before - (abs(a[n-2]-a[n-1])+abs(a[n-1]))+abs(a[n-2]))
    else:
        print(sum_before-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]))

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

A = [0] + A + [0]
S = 0
k = 0
for a in A:
    S += abs(a-k)
    k = a

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

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

Solution (Python):
n = int(input())
As = input().split()
aa = 0
for i in range(n):
    a = int(As[i])
    As[i] = a
    if i == 0:
        aa += abs(a)
    else:
        aa += abs(a - As[i - 1])
aa += abs(As[n - 1])
for i in range(n):
    ans = aa
    if i == 0:
        ans  = ans - abs(As[0]) - abs(As[1] - As[0]) + abs(As[1])
    elif i == n- 1:
        ans  = ans - abs(As[n - 1]) - abs(As[n - 1] - As[n - 2]) + abs(As[n- 2])
    else:
        ans = ans - abs(As[i + 1] - As[i]) - abs(As[i] - As[i - 1]) + abs(As[i + 1] - As[i - 1])
    print(ans)

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