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):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  maes = [(0,0)]
  usiros = [(0,0)]
  
  for i in range(n):
    place = a[i]
    value,preplace = maes[i]
    maes.append((value+abs(preplace-place),place))
  for i in range(n-1,-1,-1):
    place = a[i]
    value,preplace = usiros[(n-i-1)]
    usiros.append((value+abs(preplace-place),place))

  for i in range(n):
    maeval,maeplace = maes[i]
    usival,usiplace = usiros[n-i-1]
    print(maeval+usival+abs(maeplace-usiplace))

solve()

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

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

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

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

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

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

Solution (Python):
import sys
import math
from fractions import gcd


from itertools import accumulate


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

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






L = [0] + L + [0]
A = [abs(x - y) for x , y in zip(L, L[1::])]
SA = sum(A)

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

Solution (Python):
import sys
import math
from fractions import gcd


from itertools import accumulate


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

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






L = [0] + L
A = [abs(x - y) for x , y in zip(L, L[1::])]
SA = sum(A)
ans = 0

for i in range(N):
    if i < N - 1:
        idx = i + 1
        x = L[idx]
        
        right = L[idx + 1] - x
        left = x - L[idx - 1]
        if (left >= 0 and right >= 0) or (left <= 0 and right <= 0):
            ans = SA
        else:
            ans = SA - (abs(x - L[idx - 1]) + abs(x - L[idx + 1])) + abs(L[idx + 1] - L[idx - 1])
        print(ans + abs(L[N]))
    else:
        print(SA - abs(L[N] - L[N - 1]) + abs(L[N - 1]))

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):
def main():
    N = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    max_ = 0
    for i in range(1, N+2):
        max_ += abs(a[i] - a[i-1])
    
    for i in range(1, N+1):
        pre = a[i] - a[i-1]
        nex = a[i+1] - a[i]
        if (pre > 0 and nex < 0) or (pre < 0 and nex > 0):
            abs_pre = abs(pre)
            abs_nex = abs(nex)
            print(max_ - min(abs_nex, abs_pre) * 2)
        else:
            print(max_)


if __name__ == "__main__":
    main()

Solution (Python):



N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = [0] + a_list + [0]
total_cost = 0
for x, y in zip(a_list[:-1], a_list[1:]):
    total_cost += abs(x - y)

diff_list = []

for i in range(1, N + 1): 
    before = abs(a_list[i-1] - a_list[i]) + abs(a_list[i] - a_list[i+1])
    after = abs(a_list[i-1] - a_list[i+1])
    diff_list.append(before - after)

ans = '\n'.join([str(total_cost - d) for d in diff_list])
print(ans)

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

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

Solution (Python):

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


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

def calc(l):
    count = 0
    for i in range(len(l)-1):
        count += abs(l[i]-l[i+1])

    return count


L = [0] + A + [0]
max_L = calc(L)



for i in range(1, N+1):
    diff_minus = abs(L[i-1]-L[i])+abs(L[i]-L[i+1])
    diff_plus = abs(L[i-1]-L[i+1])
    print(max_L-diff_minus+diff_plus)

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

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

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]

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


for i in range(1, N+1):
    skip_cost = (abs(A[i-1] - A[i+1])) - \
        (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(total_cost + skip_cost)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
A = III()

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

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):

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

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


    return



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

import sys


def solve(N: int, A: "List[int]"):

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

    x = sorted(A)

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


    return



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

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

for i in range(1,N+1):
	mae = abs(A[i]-A[i-1]) + abs(A[i+1]-A[i])
	ato = abs(A[i+1]-A[i-1])
	sa = mae - ato

	print(tmpr - sa)

Solution (Python):
import sys
from statistics import *
from collections import *
stdin = sys.stdin

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

n = ni()
li = deque(na())
li.appendleft(0)
li.append(0)
s = 0
for i in range(len(li) - 1):
    s += abs(li[i + 1] - li[i])
for i in range(1, len(li) - 1):
    print(s - abs(li[i+1] - li[i]) - abs(li[i] - li[i-1]) + abs(li[i+1] -li[i-1]))

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


total = sum(abs(a[i+1]-a[i]) for i in range(n+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())
As = list(map(int, input().split()))
As = [0]+As+[0]
s = 0
for i in range(N+1):
  s += abs(As[i]-As[i+1])

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

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

for i in range(n):
    b.append(abs(a[i] - a[i + 1]))
    if i < n - 1:
        c.append(abs(a[i] - a[i + 2]))

sum_b = sum(b)
for i in range(n):
    print(sum_b + c[i] - b[i] - b[i + 1])

Solution (Python):
N,*A=map(int,open(0).read().split())
A=[0]+A+[0]
f=abs
s=sum(f(i-j)for i,j in zip(A,A[1:]))
print(*[s-f(i-j)-f(j-k)+f(i-k)for i,j,k in zip(A,A[1:],A[2:])])

Solution (Python):
N,*A=map(int,open(0).read().split())
A=[0]+A+[0]
f=lambda i:abs(A[i]-A[i+1])
s=sum(f(i)for i in range(N+1))
print(*[s-f(i)-f(i+1)+abs(A[i]-A[i+2])for i in range(N)])

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

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

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

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

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

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

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

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

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

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

for j in range(1, n+1):
    print(cost+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 = [int(i) for i in input().split()]
a.append(0)
b = [abs(a[0])]
c = [abs(a[1])]

for i in range(n):
    b.append(abs(a[i] - a[i+1]))
    if i < n-1:
        c.append(abs(a[i] - a[i+2]))
sum_b = sum(b)
for i in range(n):
    print(sum_b + c[i] - b[i] - b[i+1])

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


if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
A = [0] + [int(_) for _ in 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):
    if A[i - 1] <= A[i] <= A[i + 1] or A[i + 1] <= A[i] <= A[i - 1]:
        print(ALL)
        continue

    ans = ALL + abs(A[i - 1] - A[i + 1]) - 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()))
plan = abs(a[-1]) + abs(a[0])
for i in range(1,n):
    plan += abs(a[i] - a[i-1])

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

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    dist = []
    prev = 0
    for i in range(N):
        dist.append(abs(A[i]-prev))
        prev = A[i]
    dist.append(abs(A[N-1]-0))
    plan_tot = sum(dist)
    for i in range(N):
        v = plan_tot - dist[i] - dist[i+1]
        if i == 0:
            v += abs(A[1])
        elif i == N-1:
            v += abs(A[N-2])
        else:
            v += abs(A[i+1]-A[i-1])
        print(v)

if __name__ == '__main__':
    main()

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):
  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=[0]+[int(i) for i in input().split()]+[0]
total=0
for i in range(n+1):
  total+=abs(a[i+1]-a[i])
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])))

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    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+1]-a[i]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1]))

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



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




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

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

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

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

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+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.insert(0,0)
A.append(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+1]-A[i])-abs(A[i+2]-A[i+1])+abs(A[i+2]-A[i]))

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

ans = 0
now = 0
next = 0
next2 = 0
for i in range(N):
    next = A[i]
    if i == 0:
        now = 0
    else:
        now = A[i-1]
    
    if i == N-1:
        next2 = 0
    else:
        next2 = A[i+1]
    
    if now <= next <= next2 or now >= next >= next2:
        ans = total
    elif now <= next2 <= next or now >= next2 >= next:
        ans = total - abs(next2-next)*2
    elif next2 <= now <= next or next2 >= now >= next:
        ans = total - abs(now - next)*2
    
    print(ans)

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

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

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

list_sum = sum(diff)

for i in range(n):
    x = diff[i] + diff[i+1] - diff_2[i]
    print(list_sum - x)

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

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

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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
s = 0

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

print(s-abs(l[0]-0)-abs(l[1]-l[0])+abs(l[1]-0))
for j in range(1, n-1):
  print(s-abs(l[j-1]-l[j])-abs(l[j]-l[j+1])+abs(l[j-1]-l[j+1]))
print(s-abs(l[-1]-0)-abs(l[-1]-l[-2])+abs(l[-2]-0))

Solution (Python):
"""
観光スポット    1   2   3   4   ... N
座標           A1  A2  A3  A4  ... An

-O-+--+-+---+
観光スポットiを回るのをやめたときの、移動金額の総和

3-O----1--2

0 3 5 -1 0


"""


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


cnt = 0
prev = 0
for a in As:
    cnt += abs(a-prev)
    prev = a
cnt += abs(a)



for i in range(N):
    l = As[i]
    m = As[i+1]
    r = As[i+2]
    diff1 = abs(r-m)+abs(m-l)
    diff2 = abs(r-l)
    print(cnt-(diff1-diff2))

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

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

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

lst = list(map(int, input().split()))
lst.insert(0,0)
lst.insert(len(lst),0)

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

for i in range(1,N+1):
  a = lst[i-1]
  b = lst[i]
  c = lst[i+1]
  if (a <= b and b <= c or a >= b and b >= c):
    print(money)
  elif (a <= c and c <= b):
    print(money - abs(2 * (c - b)))
  elif (b <= a and a <= c):
    print(money - abs(2 * (a - b)))
  elif (b <= c and c <= a):
    print(money - abs(2 * (b - c)))
  elif (c <= a and a <= b):
    print(money - abs(2 * (a - b)))

Solution (Python):
n = int(raw_input())
A = map(int, raw_input().split())
c = 0
absA = [abs(0-A[0])]
jumpA = []
for i in range(n-1):
    absA.append(abs(A[i+1]-A[i]))
    jumpA.append(abs(c-A[i+1]))
    c = A[i]
absA.append(abs(A[-1]-0))
jumpA.append(abs(A[-2]-0))
total = sum(absA)
for i in range(n):
    print total - absA[i] - absA[i+1] + jumpA[i]

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(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]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

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

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

main()

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

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

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

total = sum(B)

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] + data + [0]
ab = [0] * (N+1)
for i in range(0,N+1):
    ab[i] = abs(data[i] - data[i+1])

S = sum(ab)

for j in range(0,N):
    print(S - ab[j] - ab[j+1] + (abs(data[j] - data[j+2])))

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

distSum = [0 for _ in range(N + 3)]

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

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

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

for i in range(0,len(a)-1):
    dis1.append(abs(a[i+1]-a[i]))
s = sum(dis1)
for i in range(0,len(a)-2):
    dis2.append(abs(a[i+2]-a[i]))

for i in range(n):
    print(s-dis1[i]-dis1[i+1]+dis2[i])

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


li = [abs(a[i] - a[i+1]) for i in range(N + 1)]
sumli = sum(li)


for i in range(1, N + 1):
  print(sumli - (li[i-1] + li[i]) + abs(a[i-1]-a[i+1]))

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

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

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

L = []
pos = 0
for i in range(N):
    x = abs(pos-A[i])
    pos = A[i]
    L.append(x)
L.append(abs(A[-1]))

cs = [0]
for i in range(N+1):
    x = L[i]+cs[-1]
    cs.append(x)
m = cs[-1]


for i in range(N):
    x = m - L[i]-L[i+1]
    if i == 0:
        x += abs(0-A[i+1])
    elif i == N-1:
        x = cs[-3] + abs(A[N-2])
    else:
        x += abs(A[i-1]-A[i+1])
    print(x)

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

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

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

acum = []


for i in range(1, len(A)):
    acum.append(abs(A[i-1] - A[i]))

S = sum(acum)

ans = [0] * N
for skip_i in range(N):
    print(S - (acum[skip_i] + acum[skip_i+1]) + abs(A[skip_i] - A[skip_i+2]))

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

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

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

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

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

li1 = []
li1.append(a[0])

long = len(a)

for i in range(long - 1):
    S = a[i+1] - a[i]
    li1.append(S)

li1.append(-a[-1])

li2 = [abs(li1[i+1] + li1[i]) for i in range(long)]
li3 = [abs(li1[i+1]) + abs(li1[i]) for i in range(long)]

ab_li1 = map(lambda x:abs(x), li1)

S = sum(ab_li1)

for i in range(long):
    print(S - li3[i] + li2[i])

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

li1 = []
li1.append(a[0])

for i in range(len(a) - 1):
    S = a[i+1] - a[i]
    li1.append(S)

li1.append(-a[-1])

li2 = [abs(li1[i+1] + li1[i]) for i in range(len(a))]
li3 = [abs(li1[i+1]) + abs(li1[i]) for i in range(len(a))]

ab_li1 = map(lambda x:abs(x), li1)

S = sum(ab_li1)

for i in range(len(li3)):
    print(S - li3[i] + li2[i])

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

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

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

Solution (Python):
n=int(input());*a,=map(int,input().split())
if n!=2:
	b=[abs(a[0])]+[abs(i-j)for i,j in zip(a,a[1:])]+[abs(a[-1])]
	c=[abs(a[1])]+[abs(i-j)for i,j in zip(a,a[2:])]+[abs(a[-2])]
	s=sum(b)
	for i,j,k in zip(b,b[1:],c):
		print(s-i-j+k)
else:
	print(2*abs(a[1]),2*abs(a[0]))

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

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

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

for i in range(n):
    if li_cost[i] == 0:
        print(cost_sum)
    else:
        print(cost_sum - li_cost[i] - li_cost[i+1] + abs(li[i] - li[i+2]))

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

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

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

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

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

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

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

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