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 = list(map(int, input().split()))

A_list.insert(0, 0)
A_list.append(0)
A_list_abs = []
A_sum = 0

for i in range(1, N+2):
    temp = abs(A_list[i] - A_list[i-1])
    A_list_abs.append(temp)
    A_sum += temp


for i in range(N):
    if (A_list[i] <= A_list[i+1] <= A_list[i+2]) or (A_list[i] >= A_list[i+1] >= A_list[i+2]):
        print(A_sum)
    else:
        print(A_sum - A_list_abs[i] - A_list_abs[i+1] + abs(A_list_abs[i] - A_list_abs[i+1]))

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	n=II()
	A=[0]+LI()+[0]
	total=0


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


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











if __name__ == "__main__":
	main()

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

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

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

Solution (Python):
from itertools import accumulate


N, *A = map(int, open(0).read().split())

A = [0] + A + [0]
P = list(accumulate([abs(A[i] - A[i + 1]) for i in range(N + 1)], initial=0))

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
res = 0
pre = 0
for a in A:
    res += abs(a-pre)
    pre = a
else:
    res += abs(0-pre)


ans = [0]*n
A = [0]+A+[0]
for i in range(n):
    j = i+1
    temp = res-abs(A[j-1]-A[j])-abs(A[j+1]-A[j])+abs(A[j+1]-A[j-1])
    ans[i] = temp
print(*ans, sep='\n')

Solution (Python):


def main():
    n = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    dist = [abs(a[i] - a[i - 1]) for i in range(1, n + 2)]
    total = sum(dist)
    ans = [0] * n
    for i in range(n):
        ans[i] = total - dist[i] - dist[i + 1] + abs(a[i] - a[i + 2])
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()

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

for i in range(n):
    print(cost - sum(bl[i:i+2]) + abs(al[i] - al[i+2]))

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

all = 0

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

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

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

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

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

a = sum(fee)

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

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] - 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()))
A=[0]+A+[0]
ans=0
LC=[0]*(n+2)
for i in range(1,n+1):
    ans+= abs(A[i]-A[i-1])
    if A[i-1]<A[i] and A[i]>A[i+1]:
        LC[i]= 2*( A[i]- max(A[i-1],A[i+1]) )
    if A[i-1]>A[i] and A[i]<A[i+1]:
        LC[i]= -2*(A[i]- min(A[i-1],A[i+1])) 
ans+= abs(A[n])
for i in range(n):
    print(ans-LC[i+1])

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

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

    if before <= A[i] <= after or \
        after <= A[i] <= before:
        print(no_change)
    else:
        c = no_change - min(abs(A[i]-before),abs(A[i]-after))*2
        print(c)

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

td = cnt + abs(a[0]) + abs(a[-1])

for i in range(1,n-1):
  x = abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i+1] -a[i-1])
  arr[i] = x
arr[0] = abs(a[0]) + abs(a[0] - a[1]) - abs(a[1])
arr[-1] = abs(a[n-2] - a[n-1]) + abs(a[n-1]) - abs(a[n-2])
            
ans = [td - x  for x in arr]

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

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

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

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

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

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

money = 0

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

for i in range(1, N + 1):
    s = money + 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 = list(map(int, input().split()))

money = 0

last = 0
for a in A:
    money += abs(last - a)
    last = a
money += abs(last)

for i in range(N):
    if i == 0:
        t1 = A[i]
        t2 = A[i + 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    elif i == N - 1:
        t1 = A[i]
        t2 = A[i - 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    else:
        a0 = A[i - 1]
        a1 = A[i]
        a2 = A[i + 1]
        if (a0 <= a1 and a1 <= a2) or (a0 >= a1 and a1 >= a2):
            print(money)
        elif (a0 <= a2 and a2 <= a1) or (a0 >= a2 and a2 >= a1):
            print(money - abs(a2 - a1) * 2)
        else:
            print(money - abs(a1 - a0) * 2)

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

for i in range(1,n+2):
  cst+=abs(x[i]-x[i-1])
for i in range(1,n+1):
  print(cst-abs(x[i]-x[i-1])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1]))

Solution (Python):

from collections import deque 
N = int(input())
A = deque(map(int,input().split()))
A.appendleft(0)
A.append(0)
A = list(A)

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

ans = []
for j in range(1,N+1):
    s = S -(abs(A[j]-A[j-1]) + abs(A[j+1]-A[j])) + abs(A[j+1]-A[j-1])
    ans.append(s)

for a in ans:
    print(a)

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

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

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

Solution (Python):
def main():
    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(N):
        ans = cost - abs(A[i] - A[i+1]) - abs(A[i+1]- A[i+2]) + abs(A[i] - A[i+2])
        print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
anslist = [0] * n
for j in range(1, n + 2):
    if j == 1:
        ans += abs(a[j])
    elif j == n + 1:
        ans += abs(a[n])
    else:
        ans += abs(a[j]-a[j - 1])

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

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

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


for i in range(n):
    c = cost
    if A[i] < A[i+1] and A[i+1] < A[i+2]:
        print(c)
    elif A[i] > A[i+1] and A[i+1] > A[i+2]:
        print(c)
    else:
        c -= (abs(A[i+1] - A[i]) + abs(A[i+2]-A[i+1])) - abs(A[i+2] - A[i])
        print(c)

Solution (Python):
N, *A = map(int, open(0).read().split())

A = [0] + A + [0]

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

for i in range(N):
    left = acc[i] - acc[0]
    right = acc[N + 1] - acc[i + 2]
    print(left + abs(A[i + 2] - A[i]) + right)

Solution (Python):
n=input()
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print(ans if l[i+1]<l[i] else ans+dif)
  else:print(ans if l[i+1]>l[i] else ans+dif)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = [0] + readInts() + [0]
dist = 0
for i in range(len(A)-1):
    dist+=abs(A[i] - A[i+1])

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

d = [x - y for y, x in zip(A[:-1], A[1:])]
dist = sum(abs(i) for i in d)

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

Solution (Python):
n = int(input())
al = [0] + list(map(int, input().split())) + [0]
csum = 0
for a0,a1 in zip(al[:-1], al[1:]):
    v = abs(a1-a0)
    csum += v

ansl = []
for a0,a1,a2 in zip(al[:-2], al[1:-1], al[2:]):
    if a0 <= a1 <= a2 or a2 <= a1 <= a0:
        ansl.append(csum)
    elif a0 <= a1 and a1 >= a2:
        ansl.append(csum-(a1-max(a0,a2))*2)
    else:
        ansl.append(csum -(min(a2,a0)-a1)*2)

for a in ansl: print(a)

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

Solution (Python):
import numpy as np
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
x = [0]
for i in range(len(A)-1):
    x.append(abs(A[i]-A[i+1]))
ans = sum(x)
for i in range(1, n+1):
    print(ans - (x[i]+x[i+1]) + abs(A[i-1]-A[i+1]))

Solution (Python):
n, *a = map(int, open(0).read().split())

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

Solution (Python):
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  S=abs(A[0])+abs(A[N-1])
  for i in range(N-1):
    S+=abs(A[i]-A[i+1])
  c=0
  for j in range(N-1):
    print(S-abs(c-A[j])-abs(A[j]-A[j+1])+abs(c-A[j+1]))
    c=A[j]
  print(S-abs(c-A[N-1])-abs(A[N-1])+abs(c))
  return 
main()

Solution (Python):
n = int(input())
a = [0]+list(map(int, input().split()))+[0]
d = []
for i in range(n+1):
    d.append(abs(a[i]-a[i+1]))
total = sum(d)
n = n+2
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):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    N = II()
    A = [0] + LI() + [0]

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

A = [0] + A + [0]

s = 0

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0, 0)
sum = 0
for i in range(N+1):
    sum += abs(A[i] - A[i+1])
for i in range(1, N+1):
    print(sum-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 = [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):
    if (a[i-1] - a[i]) * (a[i] - a[i+1]) > 0:
        print(total)
    else:
        x = min(abs(a[i-1] - a[i]), abs(a[i] - a[i+1]))
        print(total - x*2)

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

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

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


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

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

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

Solution (Python):
import numpy

N = int(input())
p = [int(x) for x in input().split()]
p = [0] + p + [0]

S = numpy.sum(numpy.abs(numpy.diff(p)))

for i in range(1, N + 1):
    print(S - numpy.abs(p[i] - p[i - 1]) - numpy.abs(p[i + 1] - p[i]) + numpy.abs(p[i + 1] - p[i - 1]))

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

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

for i in range(1,n+1):
    sbs = abs(a[i]-a[i-1]) + abs(a[i+1] - a[i])
    add = abs(a[i+1]-a[i-1])
    ans = lenth -sbs + add
    print(ans)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
s=[0,*A,0]
x=[abs(s[i]-s[i-1]) for i in range(1,len(s))]
S=sum(x)

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
new_a = [0] + a + [0]
total_distance = 0
for i in range(1, len(new_a)):
    distance = new_a[i] - new_a[i-1]
    total_distance += abs(distance)
for j in range(1, len(new_a) - 1):
    ans = total_distance - abs(new_a[j] - new_a[j-1]) - \
        abs(new_a[j+1] - new_a[j]) + abs(new_a[j + 1] - new_a[j-1])
    print(ans)

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

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

cost = 0
for i in range(n+1):
  cost += abs(a[i+1]-a[i])
  
for i in range(1,n+1):
  if (a[i]>a[i-1] and a[i]>a[i+1]) or (a[i]<a[i-1] and a[i]<a[i+1]):
    print(cost - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i+1]-a[i-1]))
  else:
    print(cost)

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

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

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

A = [0] + A + [0]


base_lis = []
Sum = 0

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

for i in range(1,N+1):
    print(Sum - 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()))
cs=abs(a[0])
a.append(0)
for i in range(n):
  cs+=abs(a[i]-a[i+1])
print(cs-abs(a[0])-abs(a[0]-a[1])+abs(a[1]))
for i in range(1,n):
  print(cs-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

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

diff1 = []
diff2 = []
sum1 = 0
for i in range(n+1):
    sum1 += abs(L[i+1]-L[i])
    diff1.append(abs(L[i+1]-L[i]))

for i in range(n):
    diff2.append(abs(L[i+2]-L[i]))

for i in range(n):
    ans = sum1-(diff1[i]+diff1[i+1]) + diff2[i]
    print(ans)

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

s = 0

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

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

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

a_list = [0] + ls + [0];

S = 0;
for i in range(N + 1):
  	
  	S += abs(a_list[i] - a_list[i+1]);
    



for i in range(N):
	Si = S + abs(a_list[i] - a_list[i + 2]) - (abs(a_list[i] - a_list[i + 1]) + abs(a_list[i + 1] - a_list[i + 2]));
	print(Si);

Solution (Python):


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
distance = 0
Ret = []
for i in range(len(A)-1):
    distance += abs(A[i]-A[i+1])

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

for r in Ret:
    print(r)

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

total_cost = 0
cost = [0] * (N+1)

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

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

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import accumulate


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    A = [0] + A + [0]
    N = len(A)
    return N, A


def solve(N, A):
    D = [abs(A[i-1]-A[i]) for i in range(1, N)]
    S = sum(D)
    for i in range(1, N-1):
        ans = S - D[i] - D[i-1] + abs(A[i+1] - A[i-1])
        print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

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

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

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

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

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

Solution (Python):











def solve(n,a):
  tripCourse = [0] + a + [0]
  wholeSum = sum(abs(tripCourse[i+1] - tripCourse[i]) for i in range(n+1))
  res = [wholeSum]*n
  for i in range(n):
    res[i] -= abs(tripCourse[i+1] - tripCourse[i+2]) + abs(tripCourse[i] - tripCourse[i+1]) - abs(tripCourse[i+2]-tripCourse[i])
  return res



def main():
  N = int(input())
  
  a = list(map(int,input().split()))
  ans = solve(N,a)
  for i in range(N):
    print(ans[i])
  return

if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
now = 0
dis = 0
for i in A:
    dis += abs(now-i)
    now = i
ans = dis+abs(now)
B = [0]
B.extend(A)
B.append(0)
for i in range(1,N+1):
    if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:
        print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))
    else:
        print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
for i in range(1,N+1):
    if i==1:
        print(tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2]))
    elif i==N:
        print(tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1]))
    else:
        print(tot-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()))
total = abs(A[0])+abs(A[N-1])
for i in range(N-1):
  total += abs(A[i+1]-A[i])


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

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

B = [0]

B = B+A+[0]

count = 0

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

for i in range (1, N+1):
	if B[i+1] - B[i] >= 0:
		if B[i] - B[i-1] >= 0:
			print(count)
		else:
			print(count-abs(B[i+1]-B[i])-abs(B[i]-B[i-1])+abs(B[i+1]-B[i-1]))
	else:
		if B[i] - B[i-1] <= 0:
			print(count)
		else:
			print(count-abs(B[i+1]-B[i])-abs(B[i]-B[i-1])+abs(B[i+1]-B[i-1]))

Solution (Python):
import numpy as np
n = int(input())
A = [0]+list(map(int, input().split()))+[0]
a = []
for i in range(n+1):
    a.append(abs(A[i]-A[i+1]))
ans = sum(a)
for i in range(i):
    print(ans-a[i]-a[i+1]+abs(A[i]-A[i+2]))

Solution (Python):
from itertools import accumulate
N = int(input())
A = tuple([0,] + list(map(int, input().split())) + [0,])
D = []
sum = 0
for i, a in enumerate(A[1:-1]):
  i += 1
  pre = A[i - 1]
  tem = A[i]
  nex = A[i + 1]
  x = abs(pre - tem)
  y = abs(tem - nex)
  sum += x
  D.append(abs(pre - nex) - x - y)
sum += y
for d in D:
  print(sum + d)

Solution (Python):

n, *a = map(int, open(0).read().split())
a = [0] + a + [0]
s = 0
for i in range(n + 1):
    s += abs(a[i] - a[i + 1])
for i in range(n):
    print(s + abs(a[i] - a[i + 2]) - abs(a[i] - a[i + 1]) -
          abs(a[i + 1] - a[i + 2]))

Solution (Python):
spot_num = int(input())
spot_place = [ int(p) for p in input().split(" ") ]
diff_table = []
max_num = 0

for i in range(spot_num):
  if i == 0:
    max_num += abs(spot_place[0] - 0)
    diff_table.append(abs(spot_place[1] - 0) - \
    (abs(spot_place[0] - 0) + abs(spot_place[1] - spot_place[0])))
  elif i == spot_num-1:
    diff_table.append(abs(0 - spot_place[i-1]) - \
    (abs(spot_place[i] - spot_place[i-1]) + abs(0 - spot_place[i])))
    max_num += abs(spot_place[i] - spot_place[i-1])
  else:
    diff_table.append(abs(spot_place[i+1] - spot_place[i-1]) - \
    (abs(spot_place[i] - spot_place[i-1]) + abs(spot_place[i+1] - spot_place[i])))
    max_num += abs(spot_place[i] - spot_place[i-1])
    
max_num += abs(0 - spot_place[spot_num-1])

for i in range(spot_num):
  print(max_num+diff_table[i])

Solution (Python):

import sys
input=sys.stdin.readline
        
def main():
    plan=[0]
    n = int(input())
    plan+=list(map(int,input().split()))
    plan.append(0)
    pay_sum = 0
    for i in range(1,n+2):
        pay_sum += abs(plan[i] - plan[i-1])
    
    for i in range(1,n+1):
        result = abs(plan[i-1] - plan[i+1])
        result -= abs(plan[i-1] - plan[i])
        result -= abs(plan[i+1] - plan[i])
        print(pay_sum + result)

if __name__=="__main__":
    main()

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


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    A = [0] + A + [0] 
    diff = [0] * n 
    prev = 0
    _sum = 0
    for i in range(1,n+1):
        _sum += abs(prev - A[i])
        prev = A[i]
        diff[i-1] = abs(A[i-1] - A[i+1]) - (abs(A[i]-A[i-1]) + abs(A[i+1] - A[i]))
    
    _sum += abs(A[n])
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

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


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    diff = [0] * n 
    prev = 0
    _sum = 0
    for idx, a in enumerate(A):
        _sum += abs(prev - a)
        prev = a
        if idx == 0:
            diff[idx] = abs(0 - A[1]) - (abs(a-0) + abs(a - A[1]))
        elif idx < n - 1:
            diff[idx] = abs(A[idx - 1] - A[idx + 1]) - (abs(a - A[idx - 1]) + abs(a - A[idx + 1]))
        elif idx == n - 1:
            diff[idx] = abs(A[idx - 1] - 0) - (abs(a - A[idx - 1]) + abs(a - 0))
    _sum += abs(a)
    
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Solution (Python):
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    A.insert(0, 0)
    A.append(0)
    sumA = 0
    for i in range(n+1):
        sumA += abs(A[i+1] - A[i])

    for i in range(n):
        ansA = sumA - abs(A[i+1] - A[i]) - \
            abs(A[i + 2] - A[i + 1]) + abs(A[i + 2] - A[i])
        print(ansA)


if __name__ == '__main__':
    main()