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

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

Solution (Python):
N = int(input())
input_array = list(map(int,input().split()))
input_array.insert(0,0)
input_array.append(0)
d1 = []
d2 = []

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

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

total= sum(d1)

for i in range(N):
    print(total-(d1[i]+d1[i+1])+d2[i])

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

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

for i in range(1, N+1):
    x = C[i-1]
    y = C[i]
    z = abs(A[i-1] - A[i+1])
    print(S - x - y + z)

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

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

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

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

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

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

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

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

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

main()

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    
    A = [0] + A
    A = A + [0]
    cum_map = dict()

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

    for i in range(1, N + 1):
        if i == 1:
            d = abs(A[i + 1] - A[0]) + cum_map[(0, N)] - cum_map[
                (0, i + 1)] + abs(A[N] - A[0])
        elif i == N:
            d = abs(A[N - 1] - A[0]) + cum_map[(0, N - 1)]
        else:
            d = cum_map[(0, i - 1)] + abs(A[N] - A[0]) \
                + abs(A[i + 1] - A[i - 1]) \
                + (cum_map[(0, N)] - cum_map[(0, i + 1)])
        print(d)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    
    

    
    

    
    A = [0] + A
    A = A + [0]
    cum_map = dict()

    
    

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

    for i in range(1, N + 1):
        if i == 1:
            d = abs(A[i + 1] - A[0]) + cum_map[(0, N)] - cum_map[
                (0, i + 1)] + abs(A[N] - A[0])
        elif i == N:
            d = abs(A[N - 1] - A[0]) + cum_map[(0, N - 1)]
        else:
            d = cum_map[(0, i - 1)] + abs(A[N] - A[0]) \
                + abs(A[i + 1] - A[i - 1]) \
                + (cum_map[(0, N)] - cum_map[(0, i + 1)])
        
        print(d)

Solution (Python):
import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [0] + [int(i) for i in inp] + [0]
s = np.sum(np.abs(np.diff(A,n=1)))

for j in range(1,N+1):
    df = np.abs(A[j+1]-A[j-1]) - np.abs(A[j]-A[j-1]) - np.abs(A[j+1]-A[j])
    print(int(s+df))

Solution (Python):
N = int(input())
*A, = map(int, input().split())
A = [0] + A + [0]
s = sum(abs(b-c) for b, c in zip(A, A[1:]))
s += abs(A[2]) - abs(A[1]) - abs(A[2] - A[1])
B = [s]
for i in range(N-1):
    s += (abs(A[i+3] - A[i+1]) + abs(A[i+1] - A[i])) - (abs(A[i+3] - A[i+2]) + abs(A[i+2] - A[i]))
    B.append(s)
print(*B, sep='\n')

Solution (Python):
def main():
    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]))

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

main()

Solution (Python):
def main():
    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]))

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

main()

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

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

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

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())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))

Solution (Python):
from sys import stdin 
n = int(stdin.readline())
a = [0] + map(int,stdin.readline().split())
ans = 0 
for i in xrange(1,n+1):
    ans += abs(a[i] - a[i-1])
ans += abs(a[n])
b = []
cur = abs(a[2])
for i in xrange(3,n+1):
    cur += abs(a[i] - a[i-1])
cur += abs(a[n])
b.append(cur)

for i in xrange(2,n):
    cur = ans - abs(a[i]-a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1]-a[i+1])
    b.append(cur)
cur = 0
for i in xrange(1,n):
    cur += abs(a[i]-a[i-1])
cur += abs(a[n-1])
b.append(cur)
for i in b:
    print i

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

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

sum = sum([abs(i) for i in dA])

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

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


def money(arr):
    now_x = 0
    total_score = 0

    for i in arr:
        total_score += abs(i-now_x)
        now_x = i

    total_score += abs(now_x)
    return total_score


total = money(a)


for i in range(len(a)-2):
    now_point = a[i]
    break_point = a[i+1]
    next_point = a[i+2]

    break_distance = abs(next_point-now_point)
    normal_distance = abs(break_point-now_point) + \
        abs(next_point - break_point)

    if(break_distance == normal_distance):
        print(total)
    else:
        print(total - abs(break_distance-normal_distance))

Solution (Python):
def c_traveling_plan(N, A):
    total = 0  
    a = [0] + A + [0]  
    for i in range(N + 1):
        total += abs(a[i] - a[i + 1])
    ans = ''
    for i in range(1, N + 1):
        
        
        delta1 = abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])
        delta2 = abs(a[i - 1] - a[i + 1])
        ans += '{0}\n'.format(total - delta1 + delta2)
    return ans[:-1]
  
N = int(input())
A = [int(i) for i in input().split()]
print(c_traveling_plan(N, A))

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

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

sum = sum([abs(i) for i in dA])

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

Solution (Python):
import itertools as it

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

L = 0
for i in range(N+1):
    L += abs(A[i+1] - A[i])
    
for i in range(1,N+1):
    print(L - (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.insert(0, 0)
a.append(0)
d = 0
for j in range(N+1):
    d += abs(a[j+1] - a[j])


for i in range(1,N+1):
    d_pre = a[i] - a[i-1]
    d_nxt = a[i+1] - a[i]
    

    if d_pre * d_nxt>=0:
        out = d
    else:
        out = d - 2 * min(abs(d_nxt), abs(d_pre))
    print(out)

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

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

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

Solution (Python):

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

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

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

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

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

    f(N, A)


def f(N, A):
    """
    2 ≤ N ≤ 10^5
    −5000 ≤ Ai ≤ 5000 (1≤ i≤ N)

    第一印象: 累積和?
    →不要,合計のみ必要だった
    """
    costs = [abs(A[0])]
    for i in range(1, N):
        cost = abs(A[i] - A[i-1])
        costs.append(cost)

    
    cost_N_to_start = abs(A[-1])
    costs.append(cost_N_to_start)
    costs_cumsum = sum(costs)

    for i in range(N):
        total = costs_cumsum
        
        total -= (costs[i] + costs[i+1])

        
        bef, aft = 0, 0
        if i - 1 >= 0:
            bef = A[i-1]
        if i + 1 < N:
            aft = A[i+1]
        total += abs(bef - aft)

        print(total)


if __name__ == '__main__':
    main()

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


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

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

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

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

Solution (Python):
def cost(a):
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i] - a[i-1])
    return total

def cancel(a, i, total):
    prev = a[i-1]
    spot = a[i]
    nxt = a[i+1]
    if (nxt >= prev and spot < prev) or (nxt <= prev and spot > prev):
        return total - 2 * abs(prev - spot)
    if (nxt >= prev and spot > nxt) or (nxt <= prev and spot < nxt):
        return total - 2 * abs(nxt - spot)
    return total
        
    
if __name__ == '__main__':
    _ = int(input())
    a = [0] + list(map(int, input().split()))
    a.append(0)
    total = cost(a)
    for i in range(1, len(a)-1):
        print(cancel(a, i, total))

Solution (Python):

import numpy as np
N = input()
A = np.array(map(int, raw_input().split()))


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

for i in range(1, len(A) - 1):
    partial_sum = total_sum - np.abs(A[i + 1] - A[i]) - np.abs(A[i] - A[i - 1]) + np.abs(A[i + 1] - A[i - 1])
    print partial_sum

Solution (Python):
import numpy as np

def main():
    SpotNum = int(input())
    SpotCoordinate = [int(i) for i in input().split()]
    
    SpotCoordinate.insert(0, 0)
    SpotCoordinate.append(0)
    
    DiffSpotCoordinate = abs(np.diff(SpotCoordinate))

    






















    
    SumDiffSpotCoordinate = sum(DiffSpotCoordinate)
    for i in range(1,SpotNum+1):
        result = SumDiffSpotCoordinate - DiffSpotCoordinate[i-1] - DiffSpotCoordinate[i] + abs(SpotCoordinate[i-1] - SpotCoordinate[i+1])
        print(result)
        
if __name__=="__main__":
    main()

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

default= 0
tmp = 0
for i in range(n+2):
    default += abs(a[i]-tmp)
    tmp = 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(default)
    else:
        distance = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i])
        sa = distance - abs(a[i+1] - a[i-1])
        print(default-sa)

Solution (Python):


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

    dis = 0
    bef = 0
    for b in a:
        dis += abs(bef - b)
        bef = b
    dis += abs(bef)
    for i in range(n):
        m = 0 if i == 0 else a[i-1]
        l = 0 if i == len(a) - 1 else a[i+1]
        print(dis - (abs(m - a[i]) + abs(a[i] - l) - abs(m - l)))

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

n = int(input())

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

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

for i in range(n):
    if(i == 0):
        if((0 <= a[i] and a[i] <= a[i+1]) or (0 >= a[i] and a[i] >= a[i+1])):
            print(yen)
        elif(a[i] * a[i+1] < 0):
            print(yen - abs(a[i] * 2))
        elif(a[i] >= a[i+1] or a[i] <= a[i+1]):
            print(yen - abs(a[i+1] -a[i]) * 2)
        else:
            print(yen - abs(a[i] * 2))
    elif(i+1 < n):
        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(yen)
        elif((a[i-1] >= a[i] and a[i-1] >= a[i+1]) or (a[i-1] <= a[i] and a[i-1] <= a[i+1])):
            print(yen - abs((a[i+1] - a[i]) * 2))
        else:
            print(yen - abs((a[i] - a[i-1]) * 2))
    else:
        if((a[i-1] <= a[i] and a[i] <= 0) or (a[i-1] >= a[i] and a[i] >= 0)):
            print(yen)
        elif(a[i-1] * a[i] < 0):
            print(yen - abs(a[i] * 2))
        else:
            print(yen - abs((a[i-1] - a[i]) * 2))
        break

Solution (Python):
def abs(a,b):
    return a-b if a>b else b-a

N=int(input())
A=list(map(int,input().split(' ')))
A.append(0)
skip = []
total = 0
prev = 0
for i in range(len(A)-1):
    diff = abs(prev,A[i])
    total += diff
    skip.append(diff + abs(A[i],A[i+1]) - abs(prev,A[i+1]))
    prev = A[i]
total += abs(A[-1],A[-2])
for i in range(len(skip)):
    print(total - skip[i])

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


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

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))
    P.insert(0, 0)
    Dis = [[abs(P[i]-P[(i+j+1)%(N+1)]) for i in range(N+1)] for j in range(2)]
    temp = sum(Dis[0])
    temp2 = [sum(Dis[0][i:i+2]) for i in range(N)]
    for i in range(N): print(temp-temp2[i]+Dis[1][i])

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

for i, v in enumerate(a):
    if i != 0 and i != n + 1:
        h = abs(a[i-1]-a[i]) + abs(a[i] - a[i+1])
        u = abs(a[i-1] - a[i+1])
        print(total - (h-u))

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = [abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)]
    sumbar = sum(bar)

    spam = [0] + Ai + [0]
    for i in range(N):
        if foo[i] <= foo[i + 1] <= foo[i + 2] or foo[i + 2] <= foo[i + 1] <= foo[i]:
            print(sumbar)
        else:
            ans = sumbar - (bar[i] + bar[i + 1]) + abs(spam[i] - spam[i + 2])
            print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
points = list(map(int, input().split(' ')))
points.insert(0, 0)
points.insert(len(points), 0)

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


for i in range(1, len(points) - 1):
    tmp_sum = 0
    if points[i - 1] <= points[i] <= points[i + 1]:
        print(sum)
        continue

    if points[i - 1] <= points[i + 1] <= points[i]:
        print(sum - 2 * abs(points[i] - points[i + 1]))
        continue

    if points[i] <= points[i - 1] <= points[i + 1]:
        print(sum - 2 * abs(points[i] - points[i - 1]))
        continue

    if points[i] <= points[i + 1] <= points[i - 1]:
        print(sum - 2 * abs(points[i] - points[i + 1]))

        continue
    if points[i + 1] <= points[i - 1] <= points[i]:
        print(sum - 2 * abs(points[i] - points[i - 1]))

        continue
    if points[i + 1] <= points[i] <= points[i - 1]:
        print(sum)

        continue

Solution (Python):
import math

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

change = 0
now = 0
for i in range(N+1):
    if now < int(list[i]):
        change += int(list[i])-now
        now = int(list[i])
    else:
        change += now-int(list[i])
        now = int(list[i])
change += math.fabs(now)
change = int(change)

for i in range(1,N+1):
   ans = change - math.fabs(int(list[i])-int(list[i-1]))
   ans = ans - math.fabs(int(list[i+1])-int(list[i]))
   ans = ans + math.fabs(int(list[i+1])-int(list[i-1]))
   ans = int(ans)
   print(ans)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
sumroute = 0
ever = 0

for i in range(len(b)):
    sumroute += abs(b[i] - ever)
    ever = b[i]
sumroute += abs(b[-1])
b.insert(0,0)
b.append(0)
for i in range(len(b)-2):
    if (b[i+1]-b[i]) * (b[i+2]-b[i+1]) < 0:
        print(sumroute-2*min(abs(b[i+1]-b[i]),abs(b[i+2]-b[i+1])))
    else:
        print(sumroute)

Solution (Python):
try:
    n = int(input().strip())
    spot = [int(i) for i in input().strip().split(" ")]
    spot.insert(0,0)
    spot.append(0)
    max=0
    for m in range(1,len(spot)):
        max+=abs(spot[m-1] - spot[m])
    for i in range(1,n+1):
        sub1=abs(spot[i-1] - spot[i])
        sub2=abs(spot[i] - spot[i+1])
        add1=abs(spot[i-1] - spot[i+1])
        print(max-sub1-sub2+add1)
except EOFError:
    pass

Solution (Python):
n = int(input())
dg = input().split(' ')
dg.append(0)
dg  = [0] + dg
sum_0 = sum([abs(int(dg[x]) - int(dg[x+1])) for x in range(len(dg)-1)])
for i in range(1, len(dg)-1):
    
    print(sum_0 - abs((abs(int(dg[i-1])-int(dg[i+1])) - (abs(int(dg[i-1])-int(dg[i])) + abs(int(dg[i])-int(dg[i+1]))))))

Solution (Python):
n = int(input())
A = [0]+[int(i) for i in input().split()]+[0]
S = [0]*(n+2)
current = 0
s = 0

for i in range(len(A)):
    s += abs(A[i]-current)
    S[i] = s
    current = A[i]




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

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


sum = 0
present = 0
for s, t in enumerate(a):
  sum += abs(t-present)
  present = t
sum += abs(present-0)

for i, each in enumerate(a):
  if i == 0:
    prev = 0
    tmp = each
    next = a[i+1]
  elif i == len(a)-1:
    prev = a[i-1]
    tmp = each
    next = 0
  else:
    prev = a[i-1]
    tmp = each
    next = a[i+1]

  before = abs(prev-tmp) + abs(tmp - next)
  after = abs(prev - next)

  print(sum - before + after)

Solution (Python):



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

a = 0
I = []
for b in A + [0]:
    I.append(b - a)
    a = b
S = sum(map(abs, I))

for i in range(N):
    j = i + 1
    n = S - (abs(I[i]) + abs(I[i + 1])) + abs(I[i] + I[i + 1])
    print(n)

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

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


sigma = cost   

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

for j in range(1,N-1):
    cost = sigma
    cost = cost - abs(A[j-1] - A[j]) - abs(A[j] - A[j+1]) + abs(A[j-1] - A[j+1])
    print(cost)

cost = sigma
print(cost - abs(A[N-2] - A[N-1])  -abs(A[N-1]) + abs(A[N-2]))

Solution (Python):
def cost(a):
    prev = 0
    total = 0
    for ai in a:
        total += abs(ai - prev)
        prev = ai
    total += abs(0 - prev)
    return total

def cancel(a, i, total_cost):
    prev_spot = a[i-1]
    spot = a[i]
    next_spot = a[i+1]
    if spot >= min(prev_spot, next_spot) and spot <= max(prev_spot, next_spot):
        return total_cost
    else:
        if (next_spot >= prev_spot and spot < prev_spot) or (next_spot <= prev_spot and spot > prev_spot):
            return total_cost - 2 * abs(prev_spot - spot)
        if (next_spot >= prev_spot and spot > next_spot) or (next_spot <= prev_spot and spot < next_spot):
            return total_cost - 2 * abs(next_spot - spot)
        
    
if __name__ == '__main__':
    _ = int(input())
    a = [0] + list(map(int, input().split()))
    a.append(0)
    no_cancellations = cost(a)
    for i in range(1, len(a)-1):
        print(cancel(a, i, no_cancellations))

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

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

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

Solution (Python):


def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)
a = read_line(*([int] * n))

def price(aa):
    sum = 0

    prev = 0
    for i in range(len(aa)):
        sum += abs(prev - aa[i])
        prev = aa[i]

    sum += abs(prev)
    return sum

aa = [0] + a + [0]
price_all = 0

for i in range(len(aa) - 1):
    price_all += abs(aa[i] - aa[i + 1])

for i in range(1, len(aa) - 1):
    p = price_all
    p -= abs(aa[i - 1] - aa[i])
    p -= abs(aa[i] - aa[i + 1])
    p += abs(aa[i - 1] - aa[i + 1])
    print(p)

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

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

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

for i in range(len(a) - 2):
    d1, d2 = a[i+1] - a[i], a[i+2] - a[i]
    if abs(d1) + abs(d2) == abs(d1 - d2):
        print(dist - 2 * abs(d1))
    elif 0 < d2 < d1:
        print(dist - 2 * abs(d1 - d2))
    elif d1 < d2 < 0:
        print(dist - 2 * abs(d1 - d2))
    else:
        print(dist)

Solution (Python):

"""
C - Traveling Plan
https://beta.atcoder.jp/contests/abc092/tasks/arc093_a

"""
import sys
from sys import stdin

input = stdin.readline


def solve(spots, N):
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])

    ans = []
    spots.append(0)
    spots.insert(0, 0)
    for i in range(1, N):
        if spots[i-1] <= spots[i] <= spots[i+1] or spots[i-1] >= spots[i] >= spots[i+1]:
            ans.append(total_cost)
        else:
            if spots[i] <= spots[i-1] <= spots[i+1]:
                t = abs(spots[i] - spots[i-1]) * 2
            elif spots[i-1] <= spots[i+1] <= spots[i]:
                t = abs(spots[i] - spots[i+1]) * 2
            elif spots[i-1] >= spots[i+1] >= spots[i]:
                t = abs(spots[i] - spots[i+1]) * 2
            else:
                t = abs(spots[i] - spots[i-1]) * 2
            ans.append((total_cost - t))

    spots = spots[:-2]
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])
    ans.append(total_cost)

    return ans


def main(args):
    N = int(input())
    spots = [int(x) for x in input().split()]
    ans = solve(spots, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

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

val=0
bfr=0
a.append(0)

for ai in a:
    val+=abs(ai-bfr)
    bfr=ai

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

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

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

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

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

now = 0
cost = 0
for po in A:
    cost += abs(now - po)
    now = po
cost += abs(now)

dist = array('l',[0]+A+[0,0])

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

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

    f(N, A)


def f(N, A):
    """
    2 ≤ N ≤ 10^5
    −5000 ≤ Ai ≤ 5000 (1≤ i≤ N)

    第一印象: 累積和?
    """
    costs = [abs(A[0])]
    costs_cumsum = [abs(A[0])]
    for i in range(1, N):
        cost = abs(A[i] - A[i-1])
        cumsum = cost + costs_cumsum[-1]

        costs.append(cost)
        costs_cumsum.append(cumsum)

    
    cost_N_to_start = abs(A[-1])
    costs.append(cost_N_to_start)
    costs_cumsum.append(cost_N_to_start + costs_cumsum[-1])

    for i in range(N):
        total = costs_cumsum[-1]
        
        total -= (costs[i] + costs[i+1])

        
        bef, aft = 0, 0
        if i - 1 >= 0:
            bef = A[i-1]
        if i + 1 < N:
            aft = A[i+1]
        total += abs(bef - aft)

        print(total)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.append(0)
    
total_normal = 0
prev = 0
for a in A:
    length = abs(a-prev)
    total_normal += length
    prev = a

prev = 0
for i in range(N):
    now = A[i]
    nex = A[i + 1]
    ans = total_normal - (abs(now - prev) + abs (nex - now)) + abs(nex - prev)
    print(ans)
    prev = now

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

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

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

Solution (Python):


import sys
n = int(input())
li = list(map(int, input().split()))

d = []
prev=0
for x in li:
  d.append(abs(x-prev))
  prev=x
d.append(abs(0-prev))
dist = sum(d)


prev=0
post=0
for i in range(n):
  if i==0:
    prev=0
  else:
    prev=li[i-1]
  if i==n-1:
    post=0
  else:
    post=li[i+1]
  nowe = li[i]

  if prev <= nowe and nowe <= post:
    print(dist)
  elif prev >= nowe and nowe >= post:
    print(dist)
  elif prev >= nowe and nowe <= post:
    print(dist-2*min(d[i], d[i+1]))
  elif prev <= nowe and nowe >= post:
    print(dist-2*min(d[i],d[i+1]))

Solution (Python):
N = int(input())
zero = ["0"]
LST = input().split(" ")
LST = zero + LST + zero

s = 0
for i in range(len(LST)):
    if i < len(LST)-1:
        s += abs(int(LST[i]) - int(LST[i+1]))
    else:
        s += abs(int(LST[i]))
    

for i in range(len(LST)):
    if i > 0 and i < len(LST)-1:

        minus = 0
        temp = int(LST[i])
        prev = int(LST[i-1])
        past = int(LST[i+1])
        
        if (prev <= temp and temp <= past) or (past <= temp and temp <= prev):
            minus = 0
        elif past < temp:
            minus = abs(temp - past) + abs(temp - prev) - abs(prev - past)
        elif prev > temp:
            minus = abs(temp - past) + abs(temp - prev)- abs(prev - past)

        print(s - minus)