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

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+1]-a[i])
   
for i in range(1,n+1):
    si=s+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])
    print(si)

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

S = 0
for i in range(n+1):
    S += abs(a_ls[i] - a_ls[i+1])
for i in range(1,n+1):
    ans = S + abs(a_ls[i+1] - a_ls[i-1]) - (abs(a_ls[i-1] - a_ls[i]) + abs(a_ls[i] - a_ls[i+1]))
    print(ans)

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

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

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

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

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    a = nl()

    arr = [0]
    arr.extend(a)
    arr.append(0)
    total = sum([abs(arr[i-1] - arr[i]) for i in range(1, n+2)])

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

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


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


b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:
        
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

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

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

def main():
    N = int(readline())
    A = [0] + list(map(int, readline().rstrip().split())) + [0]
    s = sum([abs(A[i]-A[i-1]) for i in range(1, N+2)])
    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])))
    

if __name__ == '__main__':
    main()

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

q = [0] * (n + 2)
SUM = 0
for i in range(n + 1):
    temp = abs(cost[i + 1] - cost[i])
    SUM += temp
    q[i] += temp
    q[i + 1] += temp


for i in range(n):
    temp = abs(cost[i + 2] - cost[i])
    print(SUM + temp - q[i + 1])

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

q = [0] * (n + 2)
SUM = 0
for i in range(n + 1):
    temp = abs(cost[i + 1] - cost[i])
    SUM += temp
    q[i] += temp
    q[i + 1] += temp


for i in range(n):
    temp = abs(cost[i + 2] - cost[i])
    print(SUM + temp - q[i + 1])

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

    t += abs(a[i] - a[i-1])


t += abs(a[-1])


before = 0
for i,now in enumerate(a):

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


    if before <= now <= after or after <= now <= before:
        dis.append(0)
    elif before <= after <= now or now <= after <= before:
        dis.append(2 * abs(now - after))
    else:
        dis.append(2 * abs(now - before))
    before = now

for i, d in enumerate(dis):
    print(t-d)

Solution (Python):
def main():
  N = int(input())
  A = [0] + [int(_) for _ in 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]))

if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
l = [0]+list(map(int,input().split()))+[0]
s = 0
for j in range(len(l)-1):
    s += abs(l[j+1]-l[j])
for i in range(1,n+1):
  a = l[i-1]
  b = l[i]
  c = l[i+1]
  if a<=b<=c:
    print(s)
  elif a<=c<=b:
    print(s-2*(b-c))
  elif b<=a<=c:
    print(s-2*(a-b))
  elif b<=c<=a:
    print(s-2*(c-b))
  elif c<=a<=b:
    print(s-2*(b-a))
  elif c<=b<=a:
    print(s)

Solution (Python):


import io
import sys

data = int(input())
array = [0] + [int(x) for x in input().split()] + [0]

cnt = sum(abs(array[i+1] - array[i]) for i in range(data+1))

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

Solution (Python):






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

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

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

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

    print(S[N-2]+abs(A[N-2]))


main()

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

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

al=0


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

for j in range(n):
    t=(abs(a[j]-a[j+1])+abs(a[j+1]-a[j+2]))-(abs(a[j]-a[j+2]))
    print(al-t)

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

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

tmp = abs(a[0])

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

for i in range(1,n+1):
  print(tmp - (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.append(0)

total = 0
now = 0
skip = {}

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

for i in range(N):
    

    print(total+skip[i])

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]-a[i+1])
for i in range(1,n+1):
  s=sorted(a[i-1:i+2])
  if a[i]==s[0]:
    print(ans-(s[1]-s[0])*2)
  elif a[i]==s[2]:
    print(ans-(s[2]-s[1])*2)
  else:
    print(ans)

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

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):
    if (A[i] - A[i-1]) * (A[i+1] - A[i]) >= 0:
        ans = SUM
    else:
        ans = SUM - 2 * min(abs(A[i] - A[i-1]), abs(A[i+1] - A[i]))
    print(ans)

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

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

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

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

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    r = 0
    r += abs(A[0])
    for i in range(N - 1):
        r += abs(A[i] - A[i + 1])
    r += abs(A[-1])
    for i in range(N):
        pp = (0 if i == 0 else A[i - 1])
        np = (0 if i == N - 1 else A[i + 1])
        print(r - abs(A[i] - pp) - abs(A[i] - np) + abs(pp - np))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

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


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


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

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


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


for i in range(N):
  if a2list[i+1]-a2list[i]>=0 and a2list[i+2]-a2list[i+1]>=0:
    print(alldist)
  elif a2list[i+1]-a2list[i]<=0 and a2list[i+2]-a2list[i+1]<=0:
    print(alldist)
  else:
    dist=alldist-abs(a2list[i+1]-a2list[i])-abs(a2list[i+2]-a2list[i+1])+abs(a2list[i+2]-a2list[i])
    print(dist)

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

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

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

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

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

Solution (Python):
def main():
    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(1,n+1):
        print(S - abs(A[i-1]-A[i])-abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = [abs(aa[i+1]-aa[i]) for i in range(n+1)]
    sumv = sum(g)
    g = dict(zip(range(n+1), g))
    ng = [abs(aa[i+2]-aa[i]) for i in range(n)]
    ng = dict(zip(range(n), ng))
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(n+1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(n)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(len(aa)-1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(len(aa)-2)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = [0]
    for i in range(1, n+2):
        g.append(abs(aa[i]-aa[i-1]))
    ng = [0, 0]
    for i in range(2, n+2):
        ng.append(abs(aa[i]-aa[i-2]))
    sumv = sum(g)
    for i in range(1, n+1):
        print(sumv - (g[i] + g[i+1]) + ng[i+1])

if __name__ == '__main__':
    main()

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())
a = [0] + a + [0]

def main():
    s = sum([abs(a[i+1] - a[i]) for i in range(n + 1)])
    for i in range(1, n + 1):
        if a[i-1] <= a[i] <= a[i+1]: res = s
        elif a[i-1] >= a[i] >= a[i+1]: res = s
        else: res = s - 2 * min(abs(a[i] - a[i-1]), abs(a[i+1] - a[i]))
        print(res)
            
if __name__ ==  '__main__':
    main()

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

Solution (Python):




mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = [0] + readInts() + [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])))
    


if __name__ == '__main__':
  main()

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    A = [0] + A + [0]
    Diff = [0]
    for i in range(1, N+2):
        Diff.append(abs(A[i] - A[i-1]))
    
    total = sum(Diff)
    for i in range(1, N+1):
        print(total + abs(A[i-1] - A[i+1]) - Diff[i] - Diff[i+1])

    
if '__main__' == __name__:
    resolve()

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

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

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

Solution (Python):
url = "https://atcoder.jp/contests/abc092/tasks/arc093_a"
import copy
def main():
    n = int(input())
    tmp = list(map(int, input().split()))
    ma = [0]
    ma.extend(tmp)
    ma.append(0)
    all_num = 0
    for i in range(len(ma) - 1):
        all_num += abs(ma[i] - ma[i + 1])
    for i in range(1, len(ma) - 1):
        print(all_num - abs(ma[i - 1] - ma[i]) - abs(ma[i] - ma[i + 1]) + abs(abs(ma[i - 1] - ma[i + 1])))


if __name__ == '__main__':
    main()

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

diff.append(abs(A[-1]))

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

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

Solution (Python):
from collections import deque
n = int(input())
A = deque(map(int, input().split()))
A.appendleft(0)
A.append(0)
ans = 0
for i in range(1, n+2):
    ans+=abs(A[i]-A[i-1])
for i in range(1, n+1):
    d = abs(A[i]-A[i-1])+abs(A[i+1]-A[i])
    print(ans-d+abs(A[i-1]-A[i+1]))

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

Solution (Python):

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

d=[]
skip_d=[]

for i in range(N):
    d.append(abs(A[i+1]-A[i]))
    if i<N-1:
        skip_d.append(abs(A[i+2]-A[i]))
    else:
        skip_d.append(abs(A[0]-A[i]))

d.append(abs(A[-1]))

sum_d=sum(d)

for i in range(N):
    ans=sum_d-(d[i]+d[i+1])+skip_d[i]
    
    print(ans)

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

for i in range(N):
    print(sum - dif1[i] - dif1[i+1] + dif2[i])

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

for i in range(1,N+1):
    if (a[i]-a[i-1])*(a[i+1]-a[i]) < 0:
        if (a[i]-a[i-1])*(a[i+1]-a[i-1]) >= 0:
            print(cost-(abs(a[i+1]-a[i])*2))
        else:
            print(cost-(abs(a[i]-a[i-1])*2))
    else:
        print(cost)

Solution (Python):
N = int(input())
from collections import deque
a = deque(list(map(int, input().split())))
a.append(0)
a.appendleft(0)
s = 0
for i in range(N + 1):
    s += abs(a[i + 1] - a[i]) 
for i in range(1, N + 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):
import sys
input = sys.stdin.readline

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(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):
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
s = 0
for i in range(n+1):
    s += abs(A[i+1]-A[i])
for i in range(1, n+1):
    print(s-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]
work = [0 for i in range(n)]
count = 0
for i in range(1, n+1):
    if (A[i]-A[i-1])*(A[i+1]-A[i]) < 0:
        work[i-1] = min(abs(A[i+1] - A[i])*2, abs(A[i] - A[i-1])*2)
    count += abs(A[i]-A[i-1])
count += abs(A[n]-0)
for el in work:
    print(count-el)

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

aa = [0]
a = aa + a
a.append(0)

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

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

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

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

ans = 0
for i in range(1, n+1):
    min_value = min(list_A[i+1], list_A[i-1])
    max_value = max(list_A[i+1], list_A[i-1])
    if min_value <= list_A[i] <= max_value:
        ans = sum_value
        print(ans)
    else:
        ans = sum_value + abs(max_value-min_value) - abs(list_A[i]-max_value) - abs(list_A[i]-min_value)
        print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
from collections import deque
a = deque(a)
a.appendleft(0)
a.append(0)

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

for i in range(1, N + 1):
    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(0,0)
a.append(0)
cnt = 0
for i in range(n+1):
  cnt += abs(a[i]-a[i+1])
for i in range(1,n+1):
  ans = cnt
  if a[i-1] <= a[i] <= a[i+1]:
    print(ans)
  elif a[i+1] <= a[i] <= a[i-1]:
    print(ans)
  else:
    ans -=2*min(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.insert(0,0)
a.append(0)
cnt = 0
for i in range(n+1):
  cnt += abs(a[i]-a[i+1])
for i in range(1,n+1):
  ans = cnt
  if a[i-1] <= a[i] <= a[i+1]:
    print(ans)
  elif a[i+1] <= a[i] <= a[i-1]:
    print(ans)
  else:
    if a[i] >= 0:
      ans -=2*min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))
      print(ans)
    else:
      ans -=2*min(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()))

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

def calc(a, i, total):
    if i == 0:
        pre = 0
    else:
        pre = a[i - 1]

    if i != len(a) - 1:
        return total - (abs(a[i] - pre) + abs(a[i] - a[i + 1])) + abs(pre - a[i + 1])
    else:
        return total - (abs(pre - a[i]) + abs(a[i])) + abs(pre)

for i in range(n):
    print(calc(a, i, total))

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

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

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

Solution (Python):
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd


n = int(input())

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

a = np.array(a)

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

org = 0
dis = []
for i in range(1,n+2):
    org += abs(a[i]-a[i-1])
    dis.append(abs(a[i]-a[i-1]))





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

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

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

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

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

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

Solution (Python):
n, *a = map(int, open(0).read().split())
a = [0] + a + [0]
cost = [abs(a[i]-a[i+1]) for i in range(n+1)]
sum_cost = sum(cost)
next_cost = [abs(a[i]-a[i+2]) for i in range(n)]
for i in range(n):
    print(sum_cost-cost[i]-cost[i+1]+next_cost[i])

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

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

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

Solution (Python):
from sys import stdin
inp = stdin.readline

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

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


def money(a, b):
    return (abs(a - b))


sumall = 0

for i in range(len(A) - 1):
    sumall += money(A[i], A[i + 1])

for i in range(1, len(A) - 1):
    ans = sumall
    ans -= (money(A[i - 1], A[i]) + money(A[i], A[i + 1]))
    ans += money(A[i - 1], A[i + 1])
    print(ans)

Solution (Python):
import sys













readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = [0] + list(map(int, readline().split())) + [0]
    cost = 0

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

    for j in range(1, n + 1):
        omit = abs(a[j] - a[j - 1]) + abs(a[j + 1] - a[j])
        new = abs(a[j + 1] - a[j - 1])
        print(cost - omit + new)


if __name__ == '__main__':
    main()

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

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


total=sum(dist)

for i in range(1,N+1):
    if zero_A[i-1]<=zero_A[i]<=zero_A[i+1] or zero_A[i-1]>=zero_A[i]>=zero_A[i+1]:
        print(total)
    else:
        print(total-2*min(dist[i-1], dist[i]))

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

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

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

for i in range(1,n+1):
    x,y=a[i-1],a[i+1]
    if min(x,y)<=a[i] and a[i]<=max(x,y):
        print(su)
    else:
        d1=abs(a[i-1]-a[i])
        d2=abs(a[i]-a[i+1])
        print(su-2*min(d1,d2))

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

front = [0]*(n+2)
back = [0]*(n+2)
delta = [0]*(n+1)
delta2 = [0]*n


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


for i in range(n):
    delta2[i] = abs(A[i]-A[i+2])


for i in range(1,n+2):
    front[i] = front[i-1]+delta[i-1]
    back[i] = back[i-1]+delta[(n+1)-i]
back.reverse()



for i in range(n):
    print(front[i]+delta2[i]+back[i+2])

Solution (Python):

N = int(input()) 
A_list = [0] + [int(e) for e in input().split()] + [0]

fare = [abs(A_list[i]-A_list[i-1]) for i in range(1,N+2)]
sum_fare = sum(fare)




for i in range(1,N+1):
    print(sum_fare - (fare[i-1]+fare[i]) + abs(A_list[i+1] - A_list[i-1]))

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

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



resolve()

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

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

d = sum(costs)

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

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




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

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

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

for i in range(1,len(a)-1):
    dis1 = abs(a[i-1] - a[i]) + abs(a[i+1] - a[i])
    dis2 = abs(a[i-1] - a[i+1])
    print(sm - dis1 + dis2)

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(n):
  print(s-abs(a[i]-a[i+1])-abs(a[i+1]-a[i+2])+abs(a[i]-a[i+2]))