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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

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

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


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

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

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

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


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

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

Solution (Python):

n = int(input())
As = [int(s) for s in input().split()]
As = [0] + As + [0]
full_cost = sum(abs(a - As[idx - 1]) for idx, a in enumerate(As) if idx - 1 >= 0)
for idx in range(1, len(As) - 1):
    a = As[idx]
    if any([
            As[idx - 1] <= a <= As[idx + 1],
            As[idx - 1] >= a >= As[idx + 1]]):
        ci = full_cost
    elif any([
            a > As[idx + 1] >= As[idx - 1],
            a < As[idx + 1] <= As[idx - 1]]):
        ci = full_cost - 2 * abs(a - As[idx + 1])
    elif any([
            a < As[idx - 1] <= As[idx + 1],
            As[idx + 1] <= As[idx - 1] < a]):
        ci = full_cost - 2 * abs(a - As[idx - 1])
    else:
        assert(False)
    print(ci)

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

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

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

Solution (Python):
N = int(input())
list = list(int(i) for i in input().split())
list.insert(0, 0)
list.insert(N+1, 0)
total = 0


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

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [0]+A[:]+[0]
s = 0
for i in range(N+1):
    s += abs(B[i]-B[i+1])

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [0]+A[:]+[0]
s = 0
for i in range(N+1):
    s += abs(B[i]-B[i+1])

for i in range(N):
    if B[i] < B[i+1] and B[i+1] <B[i+2]:
        print(s)
    else:
        t = abs(B[i+1]-B[i])+abs(B[i+2]-B[i+1])-abs(B[i+2]-B[i])
        print(s-t)

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

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

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

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

A.insert(0,0)
A.insert(N+1,0)
sum=0


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


for j in range(1,N+1):
    tmp=0
    tmp=abs(A[j-1]-A[j+1])-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])
    print(sum+tmp)

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



X.insert(0,0)
X.append(0)
Y = []
for i, x in enumerate(X[1:]):
    Y.append(abs(x-X[i]))
sumY = sum(Y)

for i, x in enumerate(X):
    if i not in [0,len(X)-1]:
        ans = sumY - (Y[i-1] + Y[i]) + abs(X[i+1]-X[i-1])
        print(ans)

Solution (Python):

n = int(input())
spot_list = list(map(int,input().split()))
max_cost = 0


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

spot_list = [0] + spot_list + [0]
for i in range(1,len(spot_list)-1):
    d_pay = abs(spot_list[i-1]-spot_list[i+1]) - (abs(spot_list[i]-spot_list[i-1])+abs(spot_list[i+1]-spot_list[i]))
    print(max_cost+d_pay)

Solution (Python):
N = int(input())
A_list = [0]
A_list.extend(list(map(int, input().split())))
A_list.append(0)
previous_val = 0
S = 0
for i in A_list[1:]:
    S += abs(previous_val - i)
    previous_val = i

for idx, val in enumerate(A_list):
    if idx == 0 or idx == (len(A_list) - 1):
        continue
    else:
        new_dif = abs(A_list[idx - 1] - A_list[idx + 1])
        old_dif = abs(A_list[idx - 1] - A_list[idx]) + abs(A_list[idx] - A_list[idx + 1])
        print(S + new_dif - old_dif)

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

i = 0
j = a[0]
s = abs(a[0])
for x in range(1, n+1):
    k = a[x]
    s += abs(j-k)
    if i<=j<=k or k<=j<=i:
        m.append(0)
    else:
        ij = abs(i-j)
        jk = abs(j-k)
        if ij<jk:
            m.append(-2*ij)
        else:
            m.append(-2*jk)
    i = j
    j = k
for x in m:
    print(s+x)

Solution (Python):
import copy

"""
def sumPrice(N, B):
    sum = 0
    for i in range(1, N):
        sum += abs(B[i] - B[i - 1])
    sum += abs(B[N-1] - B[0])
    return sum


N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
for i in range(1, N + 1):
    B = copy.deepcopy(A)
    del B[i]
    print(sumPrice(N, B))
"""
N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.insert(N+1, 0)

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

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

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

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

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

    if (tmp_2 - A[i]) * (A[i] - tmp_1) >= 0:
        print(ans_def)
    elif (A[i] - tmp_2) * (tmp_2 - tmp_1) >= 0:
        print(ans_def - abs(tmp_2 - A[i]) * 2)
    else:
        print(ans_def - abs(tmp_1 - A[i]) * 2)

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

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

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

Solution (Python):
from collections import deque
import numpy as np

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = np.array(a)

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

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

Solution (Python):
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)

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

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

Solution (Python):
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)

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

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

Solution (Python):
import numpy as np

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

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

    A = np.array(A)
    
    cost = np.abs(A[1:] - A[:-1])    
    total = sum(cost)    
    
    for i in range(N):

        
        print(total - cost[i] - cost[i+1] + abs(A[i+2]-A[i]))

if __name__ == "__main__":
    main()

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

Sum = 0
Ans = 0

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

for i in range(N):
    Ans = Sum
    Ans = Ans - abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1]) + abs(A[i+2] - A[i])
    print("%d" % (Ans))

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

s = 0
for i in a:
    s += abs(i-x)
    x = i
s += abs(0-x)

b, f = 0, 0

for i in range(len(a)):
    if i == 0:
        f, b = 0, a[i+1]
    elif i == len(a)-1:
        f, b = a[i-1], 0
    else:
        f, b = a[i-1], a[i+1]

    c = s + abs(b-f) - (abs(a[i]-f)+abs(b-a[i]))
    c_lst.append(c)

for i in c_lst:
    print(i)

Solution (Python):
n = int(input())
a = [0]
a += [int(_) for _ in input().split()]
a += [0]

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

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

  print(sum)

Solution (Python):
n = int(input())
a = [0]
a += [int(_) for _ in input().split()]
a += [0]

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

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

Solution (Python):
import copy

def calcAbs(a, i):
	return abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]))

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

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

	for i in range(1, n+2-1):
		ans = total + calcAbs(a, i) 

		print(ans)


main()

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

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

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

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

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

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

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

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

total_price=0

negative=abs(A[0]-0)+ abs(A[1]-A[0])-abs(A[1]-(0))
total_price=full_price-negative
print(total_price)

for j in range (1,N-1):
    negative=abs(A[j]-A[j-1])+ abs(A[j+1]-A[j])-abs(A[j+1]-(A[j-1]))
    total_price=full_price-negative
    print(total_price)
    

negative=abs(0-A[N-1])+ abs(A[N-1]-A[N-2])-abs(0-A[N-2]) 
total_price=full_price-negative
print(total_price)

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

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

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

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

all_sum = 0

for i in range(0, place_count+1):
	all_sum += abs(position_list[i+1] - position_list[i])

for x in range(1, place_count+1):
	print(all_sum - abs(position_list[x-1] - position_list[x]) - abs(position_list[x+1] - position_list[x]) + abs(position_list[x+1] - position_list[x-1]))

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

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


for i in range(1, N + 1):
    
    ans = allsum - abs(spot[i - 1] - spot[i]) - abs(spot[i] - spot[i + 1]) + abs(spot[i - 1] - spot[i + 1])
    print(str(ans))

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

def diffWithoutNum( num):
    return B[num + 1] + B[num] - abs(A[i + 1] -A[i - 1])

for i in range( 1, N + 1):
    print( allPath - diffWithoutNum(i))

Solution (Python):
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
money=0
for i in range(N+1):
  money+=abs(list_A[i+1]-list_A[i])
for i in range(1,N+1):
  Money=money-abs(list_A[i]-list_A[i-1])-abs(list_A[i+1]-list_A[i])+abs(list_A[i+1]-list_A[i-1])
  print(Money)

Solution (Python):





if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]

    
    
    
    total_distance = 0
    total_cost = 0

    for i in range(spot_count + 1):
        total_distance += abs(spots[i + 1] - spots[i])

    for j in range(1, spot_count + 1):
        shortcut_cost = (abs(spots[j - 1] - spots[j]) + abs(spots[j] - spots[j + 1]))
        total_cost = total_distance + abs(spots[j - 1] - spots[j + 1]) - shortcut_cost
        print(total_cost)

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

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

for i in range(n):
    if i == 0:
        print(s + abs(0 - a[i + 1]) - (abs(0 - a[i]) + abs(a[i] - a[i + 1])))
    elif i == n - 1:
        print(s + abs(a[i - 1] - 0) - (abs(a[i - 1] - a[i]) + abs(a[i])))
    else:
        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(len(A)-1)]
sum = sum(B)
for i in range(N):
    ans = sum - B[i] - B[i+1] + abs(A[i+2]-A[i])
    print(ans)

Solution (Python):
from collections import deque
n=int(input())
x = deque(int(i) for i in input().split())
x.appendleft(0)
x.append(0)

d1=[]
d2=[]
for i in range(0,len(x)-1):
    d1.append(abs(x[i+1]-x[i]))
for i in range(0,len(x)-2):
    d2.append(abs(x[i+2]-x[i]))
d1sum=sum(d1)

for i in range(0,i+1):
    ans = d1sum + d2[i] - d1[i] -d1[i+1]
    print(ans)

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

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

ans = []

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

for i in range(N):
    if i == 0:
        temp = s  - abs(a[i]) - abs(a[i+1]-a[i]) + abs(a[i+1])
    elif i < N-1:
        temp = s - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
    else:
        temp = s - abs(a[i]) - abs(a[i]-a[i-1]) + abs(a[i-1])
    ans.append(temp)
for x in range(N):
    print(ans[x])

Solution (Python):



import sys

N = int(sys.stdin.readline())
A = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))

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

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

for i in range(1, N + 1):
	currentCost = totalCost
	currentCost -= abs(A[i] - A[i -1]) + abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i - 1])
	print (str(currentCost))

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

Solution (Python):
N = int(input())
a = list(int(i) for i in input().split())
A =[]
A.append(0)
A.extend(a)
A.append(0)
s = 0
for j in range(N+1):
    s += abs(A[j+1]-A[j])
for i in range(1, N+1):
    ans = s -(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1])
    print(ans)

Solution (Python):
import sys
for line in sys.stdin:
    if line == None or line == '\n':
        break
    line = line.rstrip()
    line = line.split(" ")
    if len(line) == 1:
        N = int(line[0])
        continue
    else:
        coordinates = line

        coordinates.insert(0, 0)
        coordinates.append(0)

        prev_coord = int(coordinates[0])
        total_cost = 0
        for i in range(1, len(coordinates)):
            total_cost += abs(int(coordinates[i]) - int(coordinates[i-1]))

        for i in range(1, len(coordinates) - 1):
            print(total_cost - abs(int(coordinates[i]) - int(coordinates[i - 1])) - abs(int(coordinates[i]) - int(coordinates[i + 1])) + abs(int(coordinates[i + 1]) - int(coordinates[i - 1])))

Solution (Python):
import math
n = int(input())
arr = input().split(' ')
arr = [0] + [int(a) for a in arr] + [0]

cost = 0
for j in range(1, len(arr)):
	cost += math.fabs(arr[j] - arr[j - 1])

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

Solution (Python):
x = int(raw_input())
s = raw_input().split(" ")
s.insert(0, "0")

def cost(a, b):
 return abs(int(a)-int(b))

totalCost = cost(s[-1], s[0])
skipGain = [None] * (x+1)

costPrev = cost(s[0], s[1])
for i in range(0, x):
 costThisOne = cost(s[i+1], s[0 if i==x-1 else i+2])
 totalCost += costPrev
 skipGain[i+1] = cost(s[i], s[0 if i==x-1 else i+2]) - costPrev - costThisOne
 costPrev = costThisOne

for i in range(1, x+1):
 print totalCost + skipGain[i]

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

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

for i in range(1,N+1):
    if As[i-1] == As[i] or As[i] == As[i+1] or \
            (As[i-1] < As[i]) == (As[i] < As[i+1]):
        print(total)
    else:
        da = abs(As[i-1]-As[i])
        db = abs(As[i]-As[i+1])
        print(total-2*min(da,db))

Solution (Python):
N=int(input())
s=list(map(int,input().split()))
s.insert(0,0)
s.append(0)
ans=0
for k in range(N+1):
    ans+=abs(s[k]-s[k+1])
for i in range(N):
    a,b,c=s[i]-s[i+1],s[i+1]-s[i+2],s[i]-s[i+2]
    if a*b>=0:
        print(ans)
    else:
        print(ans-abs(a)-abs(b)+abs(c))

Solution (Python):
from collections import deque

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

A.append(0)
A.appendleft(0)

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

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

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

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

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

Solution (Python):
import numpy as np
N=int(input())
A=list(map(int,input().split()))

A.insert(0,0)
A.append(0)
A=np.array(A)
S=np.sum(np.abs(np.diff(A)))

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

Solution (Python):


N = int(input())

a = [i for i in map(int, input().split())]

a = [0] + a + [0]

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

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

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

Solution (Python):


n = int(input())
spot = [int(x) for x in input().split()]
spot = [0] + spot + [0]
cost = 0
for i in range(len(spot)-1):
    cost += abs(spot[i] - spot[i+1])
change = 0
for k in range(len(spot)-2):
    if (spot[k+1]-spot[k])*(spot[k+2]-spot[k+1]) >= 0:
        change = 0
    else:
        change = 2*min([abs(spot[k+1]-spot[k]),abs(spot[k+2]-spot[k+1])])
    print(cost-change)

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

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

Solution (Python):


n=int(raw_input())
a=map(int,raw_input().split())
a.append(0)
a.insert(0,0)
s=[]
for i in xrange(n+1):
 s.append(abs(a[i+1]-a[i]))
ss=sum(s)
for i in xrange(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()))
A = [0] + A + [0]
total_dist = 0
now = 0
for A_i in A:
    total_dist += abs(A_i - now)
    now = A_i

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


solve()

Solution (Python):
distanceSum = 0
spotCount = int(input())
spotList = input().split()
spotList = [int(i) for i in spotList]
spotList.append(0)

def calcDistance(num): 
    if num == 0: 
        return abs(spotList[num])
    elif num == spotCount: 
        return abs(spotList[num-1])
    else:
        return abs(spotList[num]-spotList[num-1])

def calcSkipEffect(num): 
    if num == 0: 
        return abs(spotList[num+1])-abs(spotList[num])-abs(spotList[num+1]-spotList[num])
    else:
        return abs(spotList[num+1]-spotList[num-1])-abs(spotList[num]-spotList[num-1])-abs(spotList[num+1]-spotList[num])

for i in range(spotCount+1): 
    distanceSum += calcDistance(i)
    
for j in range(spotCount): 
    print(str(distanceSum + calcSkipEffect(j)))

Solution (Python):

if __name__ == "__main__":
    n = int(input())
    a = [0]+list(map(int, input().split()))
    factor = sum([ abs(a[tmp]-a[tmp+1]) for tmp in range(n) ]) + abs(a[-1]-a[0])
    for position in range(1,n+1):
        if position != n:
            difference = abs(a[position-1]-a[position])+abs(a[position]-a[position+1])
            ans = factor-difference+abs(a[position-1]-a[position+1])
        else:
            difference = abs(a[position-1]-a[position])+abs(a[position]-a[0])
            ans = factor-difference+abs(a[position-1]-a[0])
        print(ans)

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
first = 0
last = sum([abs(A[i + 2] - A[i + 3]) for i in range(len(A) - 3)])
for i in range(1, len(A) - 1):
    if i != 1:
        first += abs(A[i - 2] - A[i - 1])
        last -= abs(A[i] - A[i + 1])
    print(first + abs(A[i - 1] - A[i + 1]) + last)

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

cost_sum=0

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

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

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

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

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

Solution (Python):


n = int(raw_input())
spot = [0] + map(int, raw_input().split()) + [0]

all_sum = 0
for j in range(n+1):
    all_sum = all_sum + abs(spot[j+1] - spot[j])

for i in range(n):
    ans = all_sum - abs(spot[i+1] - spot[i]) - abs(spot[i+2] - spot[i+1]) + abs(spot[i+2] - spot[i])
    print(ans)

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

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

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split())) + [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):
    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())
a = str(input()).split()

for i in range(0,n):
    a[i] = int(a[i])
    
def abs(c): 
    if c > 0: 
        return c 
    else: 
        return -c

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


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

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

print(pre-abs(a[n-1]-a[n-2])-abs(a[n-1])+abs(a[n-2]))

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

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

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

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

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

sum_cost = [0 for i in range(0, n + 2)] 

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


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

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

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

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

visited = []
for i in range(1, N + 1):
    a = abs(A[i - 1] - A[i + 1])
    b = abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1])
    visited.append(total + (a - b))

for v in visited:
    print(v)

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

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

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

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

for i in range(1,len(A)):
    wa = wa + abs(A[i-1] - A[i])
    rem1.append(abs(A[i-1]-A[i]))
    rem2.append(abs(A[i]- A[i+1]) if i+1 < len(A) else 0)
    add.append(abs(A[i-1]-A[i+1]) if i+1 < len(A) else abs(A[i-1]))

for j in range(0,len(A)-2):
    print(wa-rem1[j]-rem2[j]+add[j])

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

for i in range(1, N + 1):
    abc = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])
    ac = abs(A[i - 1] - A[i + 1])
    print(ALL - abc + ac)

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

Solution (Python):

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


a.append(0)
a.insert(0,0)
costs = []

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


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

Solution (Python):
n = int(input())
array = [int(x) for x in input().split()]

tmp_res = 0
tmp_ici = 0
tmp_array = []
for i in array:
    tmp_array.append(abs(tmp_ici-i))
    tmp_ici = i
tmp_array.append(abs(tmp_ici-0))
tmp_sum = sum(tmp_array)

array = [0] + array + [0]
for i in range(n):
    c = array[i]
    cc = array[i+2]
    a = sum(tmp_array[i:i+2])
    print(tmp_sum-a+abs(c-cc))