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

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

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

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

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

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

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

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

ans = [0] * N

for i in range(N):
    if i == 0:
        if (int(A[i]) * int(A[i+1]) < 0) or (int(A[i+1]) == 0):
            ans[i] = dis - abs(int(A[i])) * 2
        elif int(A[i]) == 0:
            ans[i] = dis
        else:
            if abs(int(A[i+1])) >= abs(int(A[i])):
                ans[i] = dis
            else:
                ans[i] = dis - abs(int(A[i+1]) - int(A[i])) * 2
    elif i == N-1:
        a = int(A[i-1])
        b = int(A[i])
        if (a*b > 0):
            if abs(b)-abs(a) > 0:
                ans[i] = dis - abs(b-a)*2
            else:
                ans[i] = dis
        else:
            ans[i] = dis - abs(b)*2
    else:
        a = int(A[i-1])
        b = int(A[i]) - a
        c = int(A[i+1]) - a
        if (b * c < 0) or (c == 0):
            ans[i] = dis - abs(b) * 2
        elif b == 0:
            ans[i] = dis
        else:
            if abs(c) >= abs(b):
                ans[i] = dis
            else:
                ans[i] = dis - abs(c - b) * 2


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

Solution (Python):
import sys

with sys.stdin as f:
    s_input = f.read()

    s_args = s_input.splitlines()
    n = int(s_args[0])
    sa = s_args[1].split()
    a = [0] + [int(elm) for elm in sa]

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

    D += abs(a[n])
            
    for i in range(1,n+1):
        if i != n:
            print(D - (dist[i-1] + dist[i]) + sd[i])
        else:
            print(D - (dist[n-1] + abs(a[n])) + abs(a[n-1]))
            
sys.exit(0)

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
m = []
for i in range(n):
    if a[i] <= a[i + 1] <= a[i + 2] or a[i + 2] <= a[i + 1] <= a[i]:
        m.append(0)
    elif a[i] <= a[i + 2] <= a[i + 1] or a[i + 1] <= a[i + 2] <= a[i]:
        m.append(1)
    elif a[i + 1] <= a[i] <= a[i + 2] or a[i + 2] <= a[i] <= a[i + 1]:
        m.append(-1)

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

for i, m0 in enumerate(m):
    if m0 == 0:
        print(s)
    elif m0 == 1:
        print(s - 2 * abs(a[i + 1] - a[i + 2]))
    elif m0 == -1:
        print(s - 2 * abs(a[i] - a[i + 1]))

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    all_cost = abs(0 - A[0])
    for i in range(N-1):
        all_cost += abs(A[i] - A[i+1])
    all_cost += abs(A[N-1] - 0)
    for i in range(N):
        buf = 0
        if i == 0:
            if (A[0] > 0 and A[0] < A[1]) or (A[0] < 0 and A[0] > A[1]):
                buf = 0
            elif (A[0] > 0 and A[0] > A[1]) or (A[0] < 0 and A[0] < A[1]):
                buf += abs(0 - A[0])
                buf += abs(A[0] - A[1])
                buf -= abs(0 - A[1])
        elif i == N-1:
            if (0 < A[N-1] < A[N-2]) or (0 > A[N-1] > A[N-2]):
                buf = 0
            else:
                buf += abs(0 - A[N-1])
                buf += abs(A[N-2] - A[N-1])
                buf -= abs(0 - A[N-2])
        else:
            if (A[i-1] < A[i] < A[i+1]) or (A[i-1] > A[i] > A[i+1]):
                buf = 0
            else:
                buf += abs(A[i-1] - A[i])
                buf += abs(A[i] - A[i+1])
                buf -= abs(A[i-1] - A[i+1])
        print(all_cost - buf)

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

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

d = [ [abs(A[i] - A[i+1]), abs(A[i] - A[i+2])] for i in range(len(A) - 2)]
d.append([0, 0])
d.insert(0, [0, 0])

fee = 0
for i in d:
    fee += i[0]

res = [d[i+1][0] + d[i][0] - d[i][1] for i in range(2, len(d)-2)]
for r in res:
    print(fee - r)

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


a2 = [0]
a2.extend(a)
a2.append(0)

max_length = 0

for i in range(len(a2) - 1):
    max_length += abs(a2[i] - a2[i+1])

def checker(a2,j):
    n1,n2,n3 = a2[j-1], a2[j], a2[j+1]
    if n1 > n2 and n2 > n3:
        ans = 0
    elif n1 < n2 and n2 < n3:
        ans = 0
    else :
        ans = 2 * min(abs(n1 - n2), abs(n2 - n3))
        
    return ans

for i in range(len(a2)-2):
    j = i+1
    i_ans = max_length - checker(a2,j)
    print(i_ans)

Solution (Python):
import numpy

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

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

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

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

        elif i < n-1:
            ans = al[-1] + al[i] - al[i+2] + pr[i+1]
        else:
            ans = al[-3] + abs(a[-2])
        print(ans)

Solution (Python):
import math
import numpy as np
from operator import mul





























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

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

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

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

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

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

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

for i in range(n):

    if i == 0:
        before = 0
    else:
        before = a[i - 1]

    if i == n - 1:
        after = 0
    else:
        after = a[i + 1]

    dist_on = abs(a[i] - before) + abs(after - a[i])
    dist_off = abs(after - before)

    print(total - dist_on + dist_off)

Solution (Python):
n, a = input(), [0] + map(int, raw_input().split()) + [0]
r = [abs(a[i] - a[i + 1]) for i in xrange(n + 1)]
f, b, s = [], [], 0
for i in xrange(n + 1):
    f.append(s)
    s += r[i]
s = 0
for i in xrange(n, -1, -1):
    b.append(s)
    s += r[i]
b = b[::-1]
f, b = f[:-1], b[1:]
for i in xrange(n):
    print f[i] + b[i] + abs(a[i] - a[i + 2])

Solution (Python):
import sys

Tmp = []
N = int(input())

Tmp = input().rstrip().split(' ')

AllDis = 0
Data = [0 for i in range(N)]
TmpNow = 0


for i in range(N):
    TmpX = int(Tmp[i])
    TmpN = abs(TmpNow - TmpX)
    AllDis += TmpN
    
    if i+1 != N:
        TmpX2 = int(Tmp[i+1])
        TmpN2 = abs(TmpX2 - TmpX)
        Data[i] =  TmpN + TmpN2 - abs(TmpX2 - TmpNow) 
        TmpNow = TmpX
    else:
        TmpN2 = abs(0 - TmpX)
        AllDis += TmpN2
        Data[i] =  TmpN + TmpN2 - abs(0 - TmpNow)
        TmpNow = TmpX
        break

for i in range(N):
    Ans = AllDis - Data[i]
    print(Ans)

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


a = [0] + a + [0]
n += 2



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






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

Solution (Python):

N = int(input())
point = [0]
point.extend(list(map(int,input().split())))
point.append(0)

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

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

Solution (Python):


import numpy as np

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

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

diff = abs(D[0]) + abs(D[1] - D[0])
net = abs(D[1])
print(alll - diff + net)
for i in range(1,N-1):
    diff = abs(D[i-1] - D[i]) + abs(D[i] - D[i+1])
    net = abs(D[i-1] - D[i+1])
    print(alll - diff + net)
diff = abs(D[N-2] - D[N-1]) + abs(D[N-1])
net = abs(D[N-2])
print(alll - diff + net)

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


head_rm = points[1:]
tail_rm = points[0:len(points)-1]

amount = sum(abs(head_rm - tail_rm)) + abs(points[0]) + abs(points[-1])

points = np.insert(points, 0, 0)
points = np.insert(points, len(points), 0)

for i in range(1,len(points) - 1):
	if (points[i] <= points[i-1] and points[i-1] <= points[i+1]) or (points[i] >= points[i-1] and points[i-1] >= points[i+1]):
		print(amount - 2 * abs(points[i-1] - points[i]))
	elif (points[i] <= points[i+1] and points[i+1] <= points[i-1]) or (points[i] >= points[i+1] and points[i+1] >= points[i-1]):
		print(amount - 2* abs(points[i+1] - points[i]))
	else:
		print(amount)

Solution (Python):
n = int(raw_input().strip())
ais = map(int, raw_input().strip().split())

sp = abs(ais[0]) + abs(ais[-1]) + sum([abs(ais[i + 1] - ais[i]) for i in xrange(n - 1)])

total = [sp for _ in xrange(n)]
for i in xrange(n):
    if i == 0:
        total[i] -= abs(ais[0] - 0)
        total[i] -= abs(ais[1] - ais[0])
    elif i == n - 1:
        total[i] -= abs(0 - ais[n - 1])
        total[i] -= abs(ais[n - 1] - ais[n - 2])
    else:
        total[i] -= abs(ais[i + 1] - ais[i])
        total[i] -= abs(ais[i] - ais[i - 1])

    if i == n - 1:
        total[i] += abs(0 - ais[n - 2])
    elif i == 0:
        total[i] += abs(ais[1] - 0)
    else:
        total[i] += abs(ais[i + 1] - ais[i - 1])

    print total[i]

Solution (Python):


N = int(raw_input())

point = map(int, raw_input().split())

prev = 0
total = 0
for i_p in point:
    current = abs(i_p - prev)
    total += current
    prev = i_p

total += abs(0 - prev)

point.insert(0, 0)
point.append(0)

origin = total



for idx, value in enumerate(point):
    if (idx == 0) or (idx == len(point) - 1):
        continue

    tmp1 = point[idx - 1]
    tmp = point[idx]
    tmp2 = point[idx + 1]

    total -= abs(tmp - tmp1)
    total -= abs(tmp - tmp2)
    total += abs(tmp2 - tmp1)

    print total

    total = origin

Solution (Python):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.append(0)
    a.insert(0,0)
    d_i=[]
    for i in range(n+1):
        d=abs(a[i]-a[i+1])
        d_i.append(d)
    tot_i=sum(d_i)
    for i in range(1,n+1):
        tot = tot_i - d_i[i-1] - d_i[i] + abs(a[i-1]-a[i+1])
        print(tot)
        
    
main()

Solution (Python):
N = int(raw_input())
points = map(int, raw_input().split())

points.insert(0,0)
points.insert(len(points),0)













dif_points = []

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



sum_fee = sum(dif_points)



for i in range(N):
    print (sum_fee - dif_points[i]  - dif_points[i+1] + abs(points[i] - points[i+2]))

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

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

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

D = [abs(A[i] - A[i+1]) for i in range(N+1)]
D2 = [abs(A[i] - A[i+2]) for i in range(N)]
S = sum(D)

for i in range(N):
    print(S + (D2[i] - (D[i]+D[i+1])))

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

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

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

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

sum = abs(a[0]) + abs(a[n-1])

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

for i in range(n):
    if i == 0:
        sum += abs(a[1]) - abs(a[0]) - abs(a[0] - a[1])
    elif i > 0 and i < n-1:
        sum += abs(a[i - 1] - a[i + 1]) - abs(a[i-1] - a[i]) -abs(a[i] - a[i+1])
    else:
        sum += abs(a[n-2]) - abs(a[n-1]) - abs(a[n-1] - a[n-2])
    print(sum)
    sum = s

Solution (Python):
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)
B = []
sum_ = abs(A[0]) + abs(A[-2])
for a0, a1, a2 in zip(A, A[1:], A[2:]):
    sum_ += abs(a0-a1)
    if (a0-a1)*(a1-a2) >= 0:
        B.append(0)
    else:
        B.append(2*min(list(map(abs, [a0-a1, a1-a2]))))

for b in B:
    print(sum_ - b)

Solution (Python):
from math import fabs
N=int(input())
pos=list(map(int,input().split()))
pos.insert(0,0)
pos.insert(N+1,0)
total_len=0
for i in range(N+1):
    total_len+=fabs(pos[i+1]-pos[i])
    

for i in range(N):
    total=total_len-fabs(pos[i+1]-pos[i])-fabs(pos[i+2]-pos[i+1])+fabs(pos[i+2]-pos[i])
    print(int(total))

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

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

for i in range(1,N+1):
    diff = - abs(visit_list[i] - visit_list[i-1]) - abs(visit_list[i+1] - visit_list[i]) +\
        abs(visit_list[i+1]-visit_list[i-1])
    new_visit_cost = total_visit_cost + diff
    print(new_visit_cost)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    A.append(0)
    
    sum_A = 0
    for i in range(N + 1):
        sum_A += abs(A[i + 1] - A[i])

    

    for i in range(1, N + 1):
        if A[i - 1] <= A[i] <= A[i + 1] or A[i + 1] <= A[i] <= A[i - 1]:
            print(sum_A)
            continue

        print(sum_A - (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()))
X=[]
X.append(abs(A[0]))
for I in range(N-1):
	X.append(abs(A[I]-A[I+1]))
X.append(abs(A[N-1]))
SUM=sum(X)
for K in range(N):
	if K==0:
		print(SUM+abs(A[K+1])-X[0]-X[1])
	elif K==(N-1):
		print(SUM+abs(A[K-1])-X[N-1]-X[N])
	else:
		print(SUM+abs(A[K-1]-A[K+1])-X[K]-X[K+1])

Solution (Python):
N = int(input())
A = [0]

Astr = input().split()

for i in Astr:
    A.append(int(i))

A.append(0)

ans = 0
pos = 0
for i in range(len(A)):
    if i == 0:
        continue
    ans += abs(A[i]-pos)
    pos = A[i]

for i in range(len(A)):
    if i == 0 or i == len(A)-1:
        continue
    print(ans-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()]
ans=abs(A[-1])
A=[0]+A+[0]
diff=[0 for x in range(N)]
for i in range(1,N+1):
  dif=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1])
  ans+=abs(A[i]-A[i-1])
  diff[i-1]=dif

for i in range(N):
  print(ans-diff[i])

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

Solution (Python):
N = int(input())
root = list(map(int,input().split()))
root.append(0)
total = [0]*(N+2)
total[0] = abs(root[0])
for i in range(1,N+1):
    total[i] += abs(root[i]-root[i-1])
sumN = sum(total)
for j in range(N):
    tmp = sumN - (total[j] + total[j+1]) + abs(root[j+1] - root[j-1])
    print(tmp)

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

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
start = 0
end = sum(cost[2:])
for n in range(N):
    print(start + abs(A[n] - A[n + 2]) + end)
    if n != N - 1:
        start += cost[n]
        end -= cost[n + 2]

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

Solution (Python):
n=int(input())
arr=list((map(int, input().split(" "))))
arr.insert(0, 0)
arr.append(0)
total=0
for k in range(len(arr)-1):
    total+=abs(arr[k]-arr[k+1])
for i in range(len(arr)-2):
    diff=abs(arr[i+2]-arr[i+1])+abs(arr[i+1]-arr[i])-abs(arr[i+2]-arr[i])
    print(total-diff)

Solution (Python):
N = int(input())
a1 = list(map(int,input().split()))
ai = [0]
ai.extend(a1)
ai.append(0)
summ = 0;
array = []


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

for i in range(N):
	array.append(summ);

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

for i in range(N):
	print (array[i])

Solution (Python):
N = int(input())
xlist = list(map(int,input().split()))
xlist = [0]+xlist+[0]
div = []
n = len(xlist)-1
for i in range(n):
    div.append(abs(xlist[i+1]-xlist[i]))
al = sum(div)
for i in range(n-1):
    print(al-div[i]-div[i+1]+abs(xlist[i+2]-xlist[i]))

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

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

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

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


for j in range(N):
    if j == 0:
        x = abs(abs(A[j]-0)+abs(A[j+1]-A[j])-abs(A[j+1]-0))
    elif j < N-1:
        x = abs(abs(A[j]-A[j-1])+abs(A[j+1]-A[j])-abs(A[j+1]-A[j-1]))
    else:
        x = abs(abs(A[j]-A[j-1])+abs(0-A[j])-abs(0-A[j-1]))
    print(z-x)

Solution (Python):


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    A.append(0)
    
    honrai_cost = 0
    for i in range(N+1):
        honrai_cost += abs(A[i]-A[i+1])
    
    for i in range(1, N+1):
        minus_cost = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])
        plus_cost  = abs(A[i-1] - A[i+1])
        print(honrai_cost - minus_cost + plus_cost)

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




N = int(input())
s = input().split(" ")
route = [int(i) for i in s]

price_of_route = []
for i in range(N + 1 ) :
    if i == 0 : 
        price_of_route.append( abs(route[i] - 0) )
    elif i == N : 
        price_of_route.append( abs(route[i-1] - 0) )
    else:
        price_of_route.append( abs(route[i] - route[i-1]) )

X = sum(price_of_route)

for i in range(N) : 
    if i == 0 :
        rst = X - price_of_route[0] - price_of_route[1] + abs(route[1] - 0) 
    elif i == N-1 : 
        rst = X - price_of_route[len(price_of_route) - 1] - price_of_route[len(price_of_route) - 2] + abs(route[N - 2] - 0) 
    else : 
        rst = X - price_of_route[i] - price_of_route[i + 1]  + abs(route[i + 1 ] - route[i-1]) 
        
    print(rst)

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

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

all_price = 0
pre1 = 0
pre2 = 0
B = []

for ai in A:
    all_price += abs(pre1 - ai)
    B += [abs(ai - pre2) - abs(pre1 - pre2) - abs(ai - pre1)]
    pre2, pre1 = pre1, ai

all_price += abs(pre1 - 0)
B += [abs(0 - pre2) - abs(pre1 - pre2) - abs(0 - pre1)]
B = B[1:]

for bi in B:
    print(all_price + bi)

Solution (Python):
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    N = int(read_func().strip().split()[0])
    input_raw = read_func().strip().split()
    
    A = [0]
    for i in range(N):
        A.append(int(input_raw[i]))
    A.append(0)

    D = {}
    cost_sum = 0
    for i in range(N + 1):
        cost = abs(A[i] - A[i + 1])
        D[(i, i+1)] = cost
        cost_sum += cost

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

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

A = {}

sumup = abs(Ai[0])

count = 0
while count < len(Ai)-1:
    A[(count,count+1)]=abs(Ai[count]-Ai[count+1])
    sumup += A[(count,count+1)]
    count += 1

A[(count,0)]=abs(Ai[count])
sumup += abs(Ai[-1])

temp = sumup - abs(Ai[0]) - A[(0,1)] + abs(Ai[1])
print(temp)

count = 1
while count < len(A)-1:
    temp = sumup - A[(count,count+1)]-A[(count-1,count)]+abs(Ai[count+1]-Ai[count-1])
    print(temp)
    count+=1

temp = sumup - A[(count,0)]-A[(count-1,count)]+abs(Ai[count-1])
print(temp)

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

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

for i in range(len(a)):
  diff = 0
  if i == 0:
    diff = abs(a[i+1]) - abs(a[i]) - abs(a[i+1] - a[i])
  elif i == n-1:
    diff = abs(a[i-1]) - abs(a[i]) - abs(a[i] - a[i-1])
  else:
    diff = abs(a[i+1] - a[i-1]) - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i])

  print(fee_sum + diff)

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

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

for i in range(n):
    before_p = a[i - 1] if i != 0 else 0
    next_p = a[i + 1] if i != n - 1 else 0


    loss = abs(a[i] - before_p) + abs(next_p - a[i])
    add = abs(next_p - before_p)
    ans = money - loss + add
    print(ans)

Solution (Python):
n = int(input())
point = [0]
price = 0
point += list(map(int,input().split()))
point.append(0)
for j in range(len(point)):
  price += abs(point[j-1] - point[j])
for k in range(1,len(point)-1):
  pp = price - abs(point[k-1]-point[k]) - abs(point[k]-point[k+1]) + abs(point[k-1]-point[k+1])
  print(pp)

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

def weight(i,j):
    global a
    return abs(a[i]-a[j])


nomiss = 0

for i in range(len(a)-1):
    nomiss+=weight(i,i+1)

def course(miss):
    skipDist = weight(miss-1,miss+1)
    curDist = weight(miss,miss+1)+weight(miss,miss-1)
    return (nomiss-curDist)+skipDist

for i in range(1,len(a)-1):
    print(course(i))

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

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

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

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

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

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

res = original_price + abs(A[1]) - abs(A[0]) - abs(A[1]-A[0])
print(res)

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

res = original_price + abs(-A[N-2]) - abs(A[N-1]-A[N-2]) - abs(-A[N-1])
print(res)

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

for i in range(n):
    if i == 0:
        print(num - abs(a[0]) - rec[1] + abs(a[1]) + abs(a[-1]))
    elif i == n - 1:
        print(num - rec[-1] + abs(a[-2]))
    else:
        print(num - rec[i] - rec[i + 1] + abs(a[i + 1] - a[i - 1]) + abs(a[-1]))

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

for i in range(n):
    if i == 0:
        ans = dif - (abs(a[i+1]-a[i])) + abs(a[1]) + abs(a[n-1])
    elif i == n-1:
        ans = dif - (abs(a[i-1]-a[i])) + abs(a[0]) + abs(a[n-2])
    else:
        ans = dif - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])) + abs(a[i-1]-a[i+1]) + abs(a[0]) + abs(a[n-1])
    print(ans)

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

for i in range(1,n+1):
	if i != n:
		print(all - (abs(a[i+1]-a[i]) + abs(a[i] - a[i-1])) + abs(a[i+1]-a[i-1]) + abs(a[n]))
	else:
		print(all - abs(a[i]-a[i-1]) + abs(a[n-1]))

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

sum = 0
pos = 0
for i in range(1, N + 2):
    sum += abs(pos - As[i])
    pos = As[i]

for i in range(1, N + 1):
    skip_pos = As[i]
    pre_pos = As[i - 1]
    post_pos = As[i + 1]

    if (pre_pos - skip_pos) * (post_pos - skip_pos) <= 0:
        print(sum)
    else:
        print(sum - abs(pre_pos - skip_pos) - abs(post_pos - skip_pos) + abs(pre_pos - post_pos))

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

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

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

for k in range(n):
    if lis[k+2]>lis[k+1] and lis[k+1]>lis[k]:
        print(cou)
    elif lis[k+2]<=lis[k+1] and lis[k+1]<=lis[k]:
        print(cou)
    else:
        print(cou-(abs(lis[k+2]-lis[k+1])+abs(lis[k+1]-lis[k])-abs(lis[k+2]-lis[k])))

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

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

for i in range(N):
    if i==0:
        prev = 0
    else:
        prev = A[i-1]
    if i==N-1:
        next = 0
    else:
        next = A[i+1]

    print(S-abs(A[i]-prev)-abs(A[i]-next)+abs(prev-next))

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