Problem:
 Score : 300 points    Problem Statement There are N sightseeing spots on the x -axis, numbered 1, 2, ..., N .
Spot i is at the point with coordinate A_i .
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0 , then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0 .  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i .
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N , find the total cost of travel during the trip when the visit to Spot i is canceled.      Constraints  2 \leq N \leq 10^5  -5000 \leq A_i \leq 5000 ( 1 \leq i \leq N )  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print N lines.
In the i -th line, print the total cost of travel during the trip when the visit to Spot i is canceled.        Sample Input 1 3
3 5 -1      Sample Output 1 12
8
10  Spot 1 , 2 and 3 are at the points with coordinates 3 , 5 and -1 , respectively.
For each i , the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:   For i = 1 , the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.  For i = 2 , the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.  For i = 3 , the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.        Sample Input 2 5
1 1 1 2 0      Sample Output 2 4
4
4
2
4       Sample Input 3 6
-679 -2409 -3258 3095 -3291 -4462      Sample Output 3 21630
21630
19932
8924
21630
19288

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

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

for i in range(1,N+1):
    print(dist[i])

Solution (Python):
n = int(input())
a = [0] + list(map(int,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):
    result = S + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i+1] - a[i])
    print(result)

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

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

X=0
for i in range(1,N+2):
    X+=abs(A[i]-A[i-1])
    
S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=X-(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1])
print("\n".join(map(str,S[1:])))

Solution (Python):



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

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












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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = [0] + readInts() + [0]
pa = 0
for i in range(n+1):
    pa += abs(A[i+1] - A[i])

for i in range(n):
    print(pa - 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()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
print(tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2]))
for i in range(2,N):
    print(tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
print(tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1]))

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

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

A = [0]+A+[0]

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

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

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

rlt = 0
lst = []

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

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

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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    a = [0] + [int(x) for x in input().split()] + [0]
    sm = 0
    for i in range(n+1):
        sm += abs(a[i] - a[i+1])

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

t = 1

for case in range(1,t+1):
    ans = solve()


"""



"""

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [0] + [int(item) for item in input().split()] + [0]
    
    all_sum = 0
    prev = 0
    for i in range(N+2):
        all_sum += abs(As[i] - prev)
        prev = As[i]

    prev = As[0]
    for i in range(N):
        print(all_sum + abs(As[i] - As[i+2]) - (abs(As[i]-As[i+1]) + abs(As[i+1] - As[i+2])))

if __name__ == "__main__":
    resolve()

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

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

B = [0] + A + [0]

diff_1 = [abs(B[i+1] - B[i]) for i in range(N+1)]
diff_2 = [abs(B[i+2] - B[i]) for i in range(N)]
ans = sum(diff_1)

for i in range(N):
    tmp = ans + diff_2[i] - (diff_1[i] + diff_1[i+1])
    print(tmp)

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

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

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

max_s = S[-1]
for i in range(1, N+1):
    ans = 0
    ans += S[i-1]
    ans += abs(B[i-1]-B[i+1])
    ans += max_s - S[i+1]
    print(ans)

Solution (Python):






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





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

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


A = [0] + A
A.append(0)

diff = [abs(A[i] - A[i+1]) for i in range(len(A)-1)]
diff2 = [abs(A[i] - A[i+2]) for i in range(len(A)-2)]
total = sum(diff)

for i in range(n):
    ans = total - sum(diff[i:i+2]) + diff2[i]
    print(ans)

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


A = [0] + A
A.append(0)

diff = [abs(A[i] - A[i+1]) for i in range(len(A)-1)]
diff2 = [abs(A[i] - A[i+2]) for i in range(len(A)-2)]
total = sum(diff)

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

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


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

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

g = [0]*(N+1)

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

s = sum(g)

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

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

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


if min(0,A[1]) <=  A[0] <= max(0, A[1]):
    print(S)
elif A[0] < min(0,A[1]):
    print(S+2*(A[0] - min(0,A[1])))
elif max(0, A[1]) < A[0]:
    print(S+2*(max(0, A[1]) - A[0]))
    
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)
    elif A[i] < min(A[i-1],A[i+1]):
        print(S+2*(A[i] - min(A[i-1],A[i+1])))
    elif max(A[i-1], A[i+1]) < A[i]:
        print(S+2*(max(A[i-1], A[i+1]) - A[i]))

if min(A[-2],0) <=  A[N-1] <= max(A[-2], 0):
    print(S)
elif A[N-1] < min(A[-2],0):
    print(S+2*(A[N-1] - min(A[-2],0)))
elif max(A[-2], 0) < A[N-1]:
    print(S+2*(max(A[-2], 0) - A[N-1]))

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = [0];a.extend(readInts());a.append(0)
base = sum([abs(a[i]-a[i+1]) for i in range(n+1)])

for i in range(1,n+1):
	print(base-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]), end=" ")

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()

POS = 0
SUM = 0
for a in A:
  SUM += abs(POS-a)
  POS = a
SUM += abs(POS)

for i in range(N):
  if i!=0 and i!=N-1:
    print(SUM-abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
  if i == 0:
    print(SUM-abs(A[i])-abs(A[i]-A[i+1])+abs(A[i+1]))
  if i == N-1:
    print(SUM-abs(A[i]-A[i-1])-abs(A[i])+abs(A[i-1]))

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

full_cost = 0

a_list = [0] + a_list + [0]

for i in range(n+1):
    full_cost += abs(a_list[i] - a_list[i+1])

for i in range(1, n+1):
    cost_diff = abs(a_list[i-1] - a_list[i+1]) - \
        abs(a_list[i] - a_list[i+1]) - abs(a_list[i-1] - a_list[i])
    print(full_cost + cost_diff)

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

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

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

Solution (Python):
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = li()
    a.insert(0, 0)
    a.append(0)
    rin = []

    for i in range(n + 1):
        rin.append(abs(a[i] - a[i + 1]))
    drin = []
    for i in range(n):
        drin.append(abs(a[i] - a[i + 2]))
    tmpall = sum(rin)

    for i in range(n):
        print(tmpall - rin[i] - rin[i + 1] + drin[i])


main()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = [0] + l() + [0]
sa = []

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

asum = sum(sa)
for i in range(1,len(a)-1):
    print(asum-sa[i-1]-sa[i]+abs(a[i-1]-a[i+1]))

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


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

s = sum(dist)
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+1] - a[i]))
  print(si)

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

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

for i in range(1,len(A)-1):
    minus=abs(A[i-1]-A[i])+abs(A[i]-A[i+1])
    plus=abs(A[i-1]-A[i+1])
    ans=all_cost-minus+plus
    print(ans)

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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
a = [0] + a + [0]
sum_a = sum([abs(a[i] - a[i - 1]) for i in range(1, n + 2)])
ans = []
for i in range(1, n + 1):
    diff = - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + \
        abs(a[i + 1] - a[i - 1])
    cost = sum_a + diff
    ans.append(cost)
print(*ans, sep='\n')

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

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

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

print(sm-abs(a[n-1]-a[n])-abs(a[n])+abs(a[n-1]))

Solution (Python):
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
a.insert(0,0)
a.append(0)
cost = 0
for i in range(1,n+2):
        cost += abs(a[i]-a[i-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):
n = int(input())
*a, = map(int, input().split())
a = [0] + a + [0]
S = sum(abs(i-j) for i, j in zip(a, a[1:]))
for i in range(1, n+1):
    s = S + abs(a[i-1]-a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]))
    print(s)

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

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

A.insert(0,0)
A.append(0)
_A = []

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


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

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

A.insert(0,0)
A.append(0)
_A = []

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


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

Solution (Python):
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    max_val = 0
    A = [0] + A + [0]
    for i in range(len(A)):
        max_val += abs(A[i]-A[i-1])
    for i in range(1,len(A)-1):
        print(max_val + 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()))

all_price = 0
now = 0
for i in range(N + 1):
    if (i == N):
        all_price += abs(A[i - 1])
        break
    all_price += abs(A[i] - now)
    now = A[i]


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

    elif (i == N - 1):
        print(all_price + abs(A[i - 1] - 0) -
              (abs(A[i] - A[i - 1]) + abs(abs(A[i] - 0))))

    else:
        print(all_price + abs(A[i - 1] - A[i + 1]) -
              (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])))

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

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce

N = a_int()
A = [0] + ints() + [0]
d_nx = [abs(x - y) for x, y in zip(A, A[1:])]  

d_nnx = [abs(x - y) for x, y in zip(A, A[2:])]  

total = sum(d_nx)
ans = []
for i in range(N):
    ans.append(total - (d_nx[i] + d_nx[i + 1]) + d_nnx[i])
print(*ans, sep='\n')

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

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

Solution (Python):
import numpy as np

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

difA = np.diff(A)
dis = abs(difA)
PM = difA//dis
S = sum(dis)

for i in range(N):
  if PM[i] == PM[i+1]:
    print(S)
  else:
    print(S - (dis[i] + dis[i+1]) + abs(difA[i] + difA[i+1]))

Solution (Python):
N=int(input())
c=list(map(int, input().split()))
C=[0]
C.extend(c)
C.append(0)
sa=[]
for i in range(1,N+2):
  sa.append(abs(C[i]-C[i-1]))
moto=sum(sa)
for i in range(1,N+1):
  c1=C[i-1]<=C[i] and C[i]<=C[i+1]
  c2=C[i-1]>=C[i] and C[i]>=C[i+1]
  if c1 or c2:
    print(moto)
  else:
    sub=abs(C[i]-C[i-1])+abs(C[i+1]-C[i])
    print(moto-sub+abs(C[i-1]-C[i+1]))

Solution (Python):
from functools import reduce
from decimal import *
from operator import mul

def main():
    n = int(input())
    a = input_list()
    a.insert(0, 0)
    a.append(0)
    total = 0
    for i in range(1, n+2):
        total += abs(a[i] - a[i-1])
    for i in range(1, n+1):
        tobashi = abs(a[i+1] - a[i-1])
        skip = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i])
        print(total - skip + tobashi)

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
num=[abs(a[0])]
def ab(num1):
    return abs(num1)
def ap(num2):
    num.append(num2)
for i in range(n-1):
    ap(ab(a[i]-a[i+1]))
ap(ab(a[-1]))
num4=sum(num)
print(num4-num[0]-num[1]+ab(a[1]))
for i in range(n-2):
    print(num4-num[i+1]-num[i+2]+ab(a[i+2]-a[i]))
print(num4-num[-1]-num[-2]+ab(a[-2]))

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

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

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

Solution (Python):



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

A = [0]+A+[0]
sun = 0
pre = 0
for i, a in enumerate(A):
    sun += abs(a-pre)
    pre = a

pre = 0
for i, a in enumerate(A[:-1]):
    if i == 0:
        continue
    print(sun - abs(pre - a) - abs(a - A[i+1]) + abs(pre - A[i+1]))
    pre = a

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
a.insert(0, 0)
a.append(0)

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

for i in range(1, len(a)-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.append(0)
now = 0
d = 0
for e in A[:-1]:
    d += abs(now-e)
    now = e
d += abs(now)

ans = []
prev = 0

for k in range(N):
    if prev <= A[k] <= A[k+1] or A[k+1] <= A[k] <= prev:
        ans.append(d)
    elif A[k] < prev < A[k+1] or A[k+1] < prev < A[k]:
        ans.append(d-2*abs(A[k]-prev))
    else:
        ans.append(d-2*abs(A[k]-A[k+1]))

    prev = A[k]

for e in ans:
    print(e)

Solution (Python):






from collections import deque,defaultdict











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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = [0] + readInts() + [0]
all = 0
for i in range(1,n+2):
    all += abs(A[i-1] - A[i])

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

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

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

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

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

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

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

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

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

ans = []
for i in range(1,N+1):
    if A[i-1]<=A[i]:
        if A[i]<=A[i+1]:
            ans.append(total)
        else:
            minus = (A[i]-max(A[i-1],A[i+1]))*2
            ans.append(total-minus)
    else:
        if A[i]>=A[i+1]:
            ans.append(total)
        else:
            minus = (min(A[i-1],A[i+1])-A[i])*2
            ans.append(total-minus)
print(*ans, sep='\n')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.reverse()
a.append(0)
a.reverse()
a.append(0)
totalprice=0
for i in range(n+2):
  totalprice+=abs(a[i]-a[i-1])
for i in range(1,n+1):
  print(totalprice-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 = list(map(int, input().split()))
ans = [-1]*n
A = [0]+A+[0]
s = 0
for i in range(1, n+2):
    s += abs(A[i]-A[i-1])

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

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

l = [0]
l.extend(list(map(int, input().split())))
l.append(0)

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

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

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

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


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

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



dis=[0]*(N+1)
for i in range(N+1):
    if i==N:
        
        dis[i]=abs(0-A[i-1])
    elif i==0:
        dis[i]=abs(A[0]-0)
    else:
        
        dis[i]=abs(A[i]-A[i-1])
SUM=sum(dis)
A=A+[0]
for i in range(N):
    ans=SUM-dis[i+1]-dis[i]+(abs(A[i-1]-A[i+1]))
    print(ans)

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

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


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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[0]+list(map(int,input().split()))+[0]
    max=0
    for i in range(n+1):
        max+=abs(l[i+1]-l[i])
    for j in range(1,n+1):
        x=abs(l[j+1]-l[j])
        y=abs(l[j]-l[j-1])
        z=abs(l[j+1]-l[j-1])
        print(max-x-y+z)
resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[0]+list(map(int,input().split()))+[0]
    max=0
    for i in range(n+1):
        max+=abs(l[i+1]-l[i])
    for j in range(1,n+1):
        if l[j-1]<l[j]<l[j+1] or l[j-1]>l[j]>l[j+1]:
            print(max)
        else:
            x=abs(l[j+1]-l[j])
            y=abs(l[j]-l[j-1])
            z=abs(l[j+1]-l[j-1])
            print(max-x-y+z)
resolve()

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

Solution (Python):
import itertools

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

acc = []
prev = 0
t = 0
for i in range(N+2):
  if i == 0:
    continue
  a = A[i]
  t += abs(a - prev)
  acc.append(t)
  prev = a
  
ans = []
for i in range(N+1):
  if i == 0:
    continue
  t = 0

  if 1 < i:
    t += acc[i-2]
  if i < N:
    t += acc[N] - acc[i]
  t += abs(A[i+1] - A[i-1])
    
  ans.append(t)
  
print("\n".join(map(str,ans)))