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):
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printmultiplerow(a):
    for i in a:
        print(i)
def printrow(a):
    for i in range(len(a)-1):
        print(a[i],end = " ")
    print(a[-1])

n = ip()
a = [0]
a.extend(iprow())
a.append(0)
sub = []
jsub = []
n+=2
for i in range(n-1):
    sub.append(abs(a[i+1]-a[i]))
for i in range(n-2):
    jsub.append(abs(a[i+2]-a[i]))
s = sum(sub)
s-=sub[0]
for i in range(n-2):
    s-=sub[i+1]
    print(s+jsub[i])
    s+=sub[i]

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


if __name__ == "__main__":
    test()

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

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

Solution (Python):
N = int(input())
array = [0]
array2 = list(map(int, input().split()))
array.extend(array2)
array.append(0)
gokei = 0
for i in range(N+1):
    gokei += abs(array[i+1] - array[i])
for i in range(N):
    print(gokei+abs(array[i]-array[i+2])-(abs(array[i]-array[i+1])+abs(array[i+1]-array[i+2])))

Solution (Python):


N=int(input())
A=[0]
A=A+list(map(int,input().split()))
A.append(0)
A.append(0)
dis=[]
sum_dis=[0]
skip=[]
sum_skip=[0]

for i in range(N+1):
    dis.append(abs(A[i+1]-A[i]))
    sum_dis.append(dis[-1]+sum_dis[i])
    skip.append(abs(A[i+2]-A[i]))

for i in range(len(sum_dis)-2):
    print(skip[i]+sum_dis[len(sum_dis)-1]-sum_dis[i+2]+sum_dis[i])

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

A = [0] + A + [0]

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    d = 0
    for a0, a1 in zip(aa, aa[1:]):
        d += abs(a0 - a1)
    for i in range(1, 1 + n):
        print(d - abs(aa[i - 1] - aa[i]) - abs(aa[i + 1] - aa[i]) + abs(aa[i - 1] - aa[i + 1]))

main()

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

Solution (Python):
n = int(input())
plan = [0] + list(map(int,input().split())) + [0]
costs = []
for i in range(1,n+1):
    costs.append((abs(plan[i]-plan[i-1]),abs(plan[i]-plan[i+1]),abs(plan[i+1]-plan[i-1])))
total = 0
for i in range(1,n+2):
    total += abs(plan[i]-plan[i-1])
for cost in costs:
    print(total - cost[0] - cost[1] +cost[2])

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

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

s=sum(b)
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(s)
    elif a[i]==max(a[i-1],a[i],a[i+1]):
        print(s-2*(a[i]-max(a[i-1],a[i+1])))
    elif a[i]==min(a[i-1],a[i],a[i+1]):
        print(s-2*(min(a[i-1],a[i+1])-a[i]))

Solution (Python):

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

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

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [0] * (N + 2)
for k in range(N):
    B[k+1] = A[k]
sumofdis = 0
for i in range(N+1):
    sumofdis += abs(B[i+1]-B[i])
for j in range(1, N+1):
    if B[j - 1] <= B[j] <= B[j + 1] or B[j - 1] >= B[j] >= B[j + 1]:
        print(sumofdis)
    elif B[j] <= B[j-1] <= B[j + 1] or B[j] >= B[j-1] >= B[j + 1]:
        print(sumofdis-2*abs(B[j-1]-B[j]))
    else:
        print(sumofdis-2*abs(B[j+1]-B[j]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    A_ = [0] + A +[0]
    ans = []
    p= 0
    for i in range(N+1):
        p += abs(A_[i+1] - A_[i])

    for i in range(1, N+1):
        print(p - (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()))
x,m=0,0
for i in range(n):
    m+=abs(x-a[i])
    x=a[i]
m+=abs(x)
for i in range(n):
    ans=m
    if i==0: ans+=abs(a[i+1])-abs(a[i+1]-a[i])-abs(a[i])
    elif i==n-1:
        ans+=abs(a[i-1])-abs(a[i])-abs(a[i]-a[i-1])
    else:
        ans+=abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])
    print(ans)

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

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



s=[s_all-abs(a[0])-abs(a[1]-a[0])+abs(a[1])]

for j in range(1,n):
    c=abs(a[j-1]-a[j])+abs(a[j]-a[j+1])
    d=abs(a[j+1]-a[j-1])
    s.append(s_all-c+d)
for i in s:
    print(i)

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
s = sum(d)
for i in range(1, n+1):
    if max(a[i-1:i+2]) == a[i] or min(a[i-1:i+2]) == a[i]:
        tmp = abs(d[i]-d[i-1])
        print(s - d[i-1] - d[i] + tmp)
    else:
        print(s)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
dist = 0
for i in range(1,N+1):
    dist += abs(A[i]-A[i-1])
dist += abs(A[0]-A[N])
for i in range(1,N):
    if A[i-1]<=A[i]<=A[i+1] or A[i+1]<=A[i]<=A[i-1]:
        print(dist)
    elif A[i-1]<=A[i+1]<=A[i] or A[i]<=A[i+1]<=A[i-1]:
        print(dist-abs(A[i+1]-A[i])*2)
    elif A[i]<=A[i-1]<=A[i+1] or A[i+1]<=A[i-1]<=A[i]:
        print(dist-abs(A[i]-A[i-1])*2)
if A[N-1]<=A[N]<=A[0] or A[0]<=A[N]<=A[N-1]:
        print(dist)
elif A[N-1]<=A[0]<=A[N] or A[N]<=A[0]<=A[N-1]:
    print(dist-abs(A[0]-A[N])*2)
elif A[N]<=A[N-1]<=A[0] or A[0]<=A[N-1]<=A[N]:
    print(dist-abs(A[N]-A[N-1])*2)

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

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

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

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

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
ls.append(0)
sumls=[abs(ls[i-1]-ls[i]) for i in range(N+1)]
SUM=sum(sumls)
for i in range(N):
  print(SUM-sumls[i]-sumls[i+1]+abs(ls[i-1]-ls[i+1]))

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

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = [0] + string_to_int(inputs[0]) + [0]
    all_cost = 0
    position = 0
    for a in A:
        all_cost += abs(position - a)
        position = a
    all_cost += abs(position)

    costs = []
    
    for i, a in enumerate(A):
        if i == 0 or i == len(A) - 1:
            continue
        cost = all_cost \
            - abs(A[i] - A[i-1]) \
            - abs(A[i+1] - A[i]) \
            + abs(A[i+1] - A[i-1])
        costs.append(cost)
    return costs


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    for r in ret:
        print(r)

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

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

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

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

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

    if i == n-2:
        skip.append(abs(a[i] - a[0]))
    else:
        skip.append(abs(a[i+2] - a[i]))

dist_one.append(abs(a[-1] - a[0]))

base = sum(dist_one)

for i in range(n-1):
    print(base - sum(dist_one[i:i+2]) + skip[i])

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

for x in c:
  print(x+s)

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

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

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

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

    c = 0
    p = 0
    for i in an:
        c += abs(p-i)
        p = i

    for i in range(1, n+1):
        cc = abs(an[i-1]-an[i+1]) - (abs(an[i-1]-an[i]) + abs(an[i]-an[i+1]))
        print(c+cc)

cc092()

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

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

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
    total += abs(p-a)
    p = a
total += abs(p)

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

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

cnt = 0

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

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

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


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


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

A=A[::-1]

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

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

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

ans = msum - abs(0 - a[0]) - abs(a[0] - a[1]) + abs(0 - a[1])
print(ans)
for i in range(1, N - 1):
    ans = msum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])
    print(ans)

ans = msum - abs(a[N - 2] - a[N - 1]) - abs(a[N - 1]) + abs(a[N - 2] - 0)
print(ans)

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

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

A.append(0)
A.insert(0, 0)
L = []
for i in range(N+1):
    L.append(abs(A[i]-A[i+1]))
    
L_a = []
for i in range(N):
    L_a.append(abs(A[i]-A[i+2]))
    
l = 0
for i in range(N+1):
    l += abs(A[i]-A[i+1])
    
for i in range(N):
    print(l-L[i]-L[i+1]+L_a[i])

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

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

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

Solution (Python):

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

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

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):
    if (A[i]-A[i-1])*(A[i]-A[i+1]) < 0:
        print(Cost)
    else:
        print(Cost+abs(A[i+1]-A[i-1])-abs(A[i]-A[i-1])-abs(A[i]-A[i+1]))

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

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

cur = 0
b = []
for i in range(1, len(a)):
    b.append(abs(a[i] - cur))
    cur = a[i]
s = sum(b)

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

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

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

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

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

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

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

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

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]



L = [0] + L + [0]

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

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

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]



su = abs(L[0])
a = [0] * N
for i in range(1, N):
    t = 0
    if L[i - 1] * L[i] < 0:
        t = abs(L[i - 1]) + abs(L[i])
    else:
        t = abs(L[i - 1] - L[i])
    su += t
    a[i] = t
su += abs(L[-1])

if L[0] * L[1] <= 0:
    print(su - abs(L[0]) * 2)
else:
    if L[0] < 0:
        if L[0] > L[1]:
            print(su)
        else:
            print(su - a[1] * 2)
    else:
        if L[0] < L[1]:
            print(su)
        else:
            print(su - a[1] * 2)

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

    t = 0
    if L[i - 1] * L[i + 1] < 0:
        t = abs(L[i - 1]) + abs(L[i + 1])
    else:
        t = abs(L[i - 1] - L[i + 1])

    print(su - c + t)

if L[-2] * L[-1] <= 0:
    print(su - abs(L[-1]) * 2)
else:
    if L[-1] < 0:
        if L[-1] > L[-2]:
            print(su)
        else:
            print(su - a[-1] * 2)
    else:
        if L[-1] < L[-2]:
            print(su)
        else:
            print(su - a[-1] * 2)

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

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

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

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

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

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

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

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

    else: print(dp[-1] +abs(a[i+1]-a[i-1]) - abs(a[i+1]-a[i])- abs(a[i]-a[i-1]))

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

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

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

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

pay = []

for i in range(N):
    a, b, c = A[i], A[i + 1], A[i + 2]
    if a < c:
        if a <= b <= c:
            pay.append(0)
        elif b < a:
            pay.append(2 * abs(a - b))
        elif c < b:
            pay.append((2 * abs(b - c)))
    elif c < a:
        if c <= b <= a:
            pay.append(0)
        elif b < c:
            pay.append(2 * abs(c - b))
        elif a < b:
            pay.append(2 * abs(b - a))
    else:
        if a == b:
            pay.append(0)
        else:
            pay.append(2 * abs(b - a))

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


for p in pay:
    print(ans - p)

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

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

for i in range(1,len(A)-1):
  print(full_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=[int(i) for i in input().split()]
li=[0]
li+=a
li+=[0]


dif1=[]
dif2=[]

for i in range(n+1):
    dif1+=[abs(li[i+1]-li[i])]
for i in range(n):
    dif2+=[abs(li[i+2]-li[i])]

total=sum(dif1)

for i in range(n):
    print(total-dif1[i]-dif1[i+1]+dif2[i])

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):
n = int(input())
ls = [0] + list(map(int, input().split())) + [0]
ds = [abs(a - b) for a, b in zip(ls, ls[1:])]
total = sum(ds)
for i in range(1, n + 1):
    prev = ls[i - 1]
    curr = ls[i]
    next_ = ls[i + 1]
    if prev <= curr <= next_ or prev >= curr >= next_:
        print(total)
    else:
        d = abs(next_ - prev)
        print(total + d - ds[i] - ds[i - 1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.insert(n+1, 0)
kyori=0
for i in range(1,len(a)):
    kyori += abs(a[i]-a[i-1])
for i in range(1, len(a)-1):
    kyori2= kyori
    if a[i-1]<=a[i]<=a[i+1] or a[i-1]>=a[i]>=a[i+1]:
        print(kyori2)
    elif a[i-1]<a[i+1]<a[i] or a[i]<a[i+1]<a[i-1]:
        kyori2 = kyori2 -abs(a[i+1]-a[i])*2
        print(kyori2)
    else:
        kyori2 = kyori2-abs(a[i-1]-a[i])*2
        print(kyori2)

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

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

for i in range(1, N + 1):
    print(money - abs(A[i - 1] - A[i]) - 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]
tc=sum(abs(a[i]-a[i+1]) for i in range(n+1))
for i in range(1,n+1):
    print(tc-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 = [int(a) for a in input().split()]
A.insert(0, 0)
A.append(0)

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

for j in range(1, N+1):
  ans = 0
  A_im1 = A[j-1]
  A_i = A[j]
  A_ip1 = A[j+1]
  ans = total_money - abs(A_im1 - A_i) - abs(A_i - A_ip1) + abs(A_im1 - A_ip1)
  print(ans)

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

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

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

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

B_abs = [abs(b) for b in B]
B_abs_cusum = [0]
cusum = 0
for j in B_abs:
  cusum += j
  B_abs_cusum.append(cusum)

for k in range(1, N+1):
  M1 = B_abs_cusum[k-1]
  M2 = abs(B[k-1] + B[k])
  M3 = B_abs_cusum[-1] - B_abs_cusum[k+1]
  M = M1 + M2 + M3
  print(M)

Solution (Python):
import numpy as np

N = int(input())
a = list(map(int,input().split()))
dp = [0] * (N+1)
dp[0] = abs(a[0])
for i in range(1, N):
    dp[i] = abs(a[i]-a[i-1])
dp[N] = abs(a[-1])
result = sum(dp)
for i in range(N):
    ans = result
    ans -= dp[i]+dp[i+1]
    if i == 0:
        ans += abs(a[i+1])
    elif i == N-1:
        ans += abs(a[i-1])
    else:
        ans += abs(a[i+1] - a[i-1])
    print(ans)

Solution (Python):
def resolve():
    n=int(input())
    A=[int(i) for i in input().split()]
    B=[A[0]]+[A[i+1]-A[i] for i in range(n-1)]+[-A[n-1]]
    abssum=sum(abs(b) for b in B)
    for i in range(n):
        print(abssum-abs(B[i])-abs(B[i+1])+abs(B[i]+B[i+1]))
resolve()

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

b = [0]

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

s = b[-1]

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

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

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

ans = []
for i in range(N):
    if i == 0:
        a = abs(A[i+1] - A[i]) + abs(A[i] - 0)
        b = abs(A[i+1] - 0)
    elif i == N - 1:
        a = abs(0 - A[i]) + abs(A[i] - A[i-1])
        b = abs(0 - A[i-1])
    else:
        a = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
        b = abs(A[i+1] - A[i-1])
    ans.append(D - a + b)

for x in ans:
    print(x)