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

Solution (Python):
import copy
def main():
    N = int(input())
    A = [0] + [int(a) for a in input().split()]

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

    for i in range(1, N + 1):
        S = copy.deepcopy(total)

        if i != N:
            S -= (abs(A[i] - A[i-1]) + abs(A[i] - A[i + 1]))
            S += abs(A[i - 1] - A[i + 1])

        else:
            S -= (abs(A[i] - A[i - 1]) + abs(A[i] - 0))
            S += abs(A[i - 1] - 0)

        print(S)

if __name__ == "__main__":
    main()

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

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

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

for i in range(n):
    if i == 0:
        s = S + abs(A[1]-0) - (abs(0-A[0])+abs(A[0]-A[1]))
        print(s)
    else:
        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 sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
A = LIST()

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

total = sum([abs(A[i]-A[i-1]) for i in range(1, N+2)])
for i in range(1, N+1):
	print(total - 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()))
road = [0] + a + [0]
allcost = 0
for i in range(n+1):
    allcost += abs(road[i+1] - road[i])

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

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

for i in range(n-1):
  lis.append(abs(a[i] - a[i+1]))
  
subsum = sum(lis) + abs(a[0]) + abs(a[-1])  
a = [0] + a + [0]


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(subsum)
  elif a[i-1] <= a[i+1] <= a[i] or a[i] <= a[i+1] <= a[i-1]:
    print(subsum - (2*abs(a[i+1] - a[i])))
  elif a[i] < a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= a[i]:
    print(subsum - (2*abs(a[i] - a[i-1])))

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

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

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

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

all_p = abs(a_list[0]) + abs(a_list[-1])
p_list = [0]*(n+1)
p_list[0] = abs(a_list[0])
p_list[-1] = abs(a_list[-1])
for i in range(len(a_list)-1):
    all_p += abs(a_list[i] - a_list[i+1])
    p_list[i+1] = abs(a_list[i] - a_list[i+1])
    
a_list.insert(0 , 0)
a_list.append(0)
for i in range(len(a_list)-2):
    print(all_p - p_list[i] -p_list[i+1] + abs(a_list[i] - a_list[i+2]))

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

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
tot = sum([abs(A[i] - A[i - 1]) if i != 0 else abs(A[0]) for i in range(n)]) + abs(A[-1])
A = [0, ] + 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(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 = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
ans = []
n = len(A)
S = 0
for i in range(1,n):
    S += abs(A[i]-A[i-1])

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

for i in ans:
    print(i)

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

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

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L = [0] + L + [0]
    default = sum([abs(L[i] - L[i-1]) for i in range(1, n+2)])

    for i in range(1, n+1):
        if L[i-1] <= L[i] <= L[i+1] or L[i-1] >= L[i] >= L[i+1]:
            print(default)
        elif L[i] >= L[i-1] and L[i] >= L[i+1]:
            print(default - 2 * (L[i] - max(L[i-1], L[i+1])))
        else:
            print(default - 2 *  (min(L[i+1], L[i-1]) - L[i]))



if __name__ == "__main__":
    main()

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

total = abs(A[0]) + abs(A[n-1])

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

N = getN()
A = [0] + getList() + [0]


dp = [0]
sta = A[0]
for i in range(1, N + 2):
    dist = abs(A[i] - sta)
    dp.append(dp[-1] + dist)
    sta = A[i]
for i in range(N):
    opt1 = dp[i]
    opt2 = abs(A[i + 2] - A[i])
    opt3 = dp[-1] - dp[i + 2]
    print(opt1 + opt2 + opt3)

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

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

s.insert(0,0)
s.insert(n+1,0)
for i in range(1,n+1):
    tmp_ans = ans
    a = s[i-1]
    tmp = s[i]
    b = s[i+1]
    if (b >= tmp and tmp >= a) or (b <= tmp and tmp <= a):
        pass
    else:
        if (a >= b and tmp > a) or (a <= b and tmp < a):
            tmp_ans -= abs(2*(tmp-a))
        else:
            tmp_ans -= abs(2*(tmp-b))
    print(tmp_ans)

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

dis=0
d=[0]*n

for i in range(1,n+1):
    dis+=abs(a[i]-a[i-1])
    if a[i+1]<a[i] and a[i-1]<a[i]:
        d[i-1]=2*(a[i]-max(a[i-1],a[i+1]))
    if a[i+1]>a[i] and a[i-1]>a[i]:
        d[i-1]=2*(min(a[i-1],a[i+1])-a[i])
dis+=abs(a[n+1]-a[n])

for i in range(n):
    print(dis-d[i])

Solution (Python):






import sys
input = sys.stdin.readline

import math

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






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






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 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])*n**i for i in range(len(str(X))))


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





N = I()
A = IL()

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

S = sum(D)
for i in range(N):
  P(S-D[i]-D[i+1]+C[i])

Solution (Python):
N = int(input())
a = [int(i) for i in 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(1,N+1):
    output = S + abs(a[i+1] - a[i-1]) - abs(a[i]-a[i-1]) - abs(a[i+1] - a[i])
    print(output)

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n=I()
lis=LI()
lis.insert(0,0)
lis.append(0)
ones=[]
twos=[]
for i in range(n+1):
    ones.append(abs(lis[i+1]-lis[i]))
    if i!=n:
        twos.append(abs(lis[i+2]-lis[i]))


u=sum(ones)
for i in range(n):
    ans=u-ones[i]-ones[i+1]+twos[i]
    print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    full = 0
    for i in range(N + 1):
        if i == 0:
            full += abs(A[0])
        elif i == N:
            full += abs(A[-1])
        else:
            full += abs(A[i] - A[i - 1])
    diff = [0 for _ in range(N)]
    for i in range(N):
        if i == 0:
            diff[0] = abs(A[1]) - (abs(A[1] - A[0]) + abs(A[0]))
        elif i == N - 1:
            diff[N - 1] = abs(A[-2]) - (abs(A[-2] - A[-1]) + abs(A[-1]))
        else:
            diff[i] = abs(A[i + 1] - A[i - 1]) - (abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1]))
    for d in diff:
        print(full + d)


if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
  N = int(input())
  A = [0]
  A.extend(list(map(int, input().split())))
  A.append(0)
  ans_def = 0
  for i in range(1, N+2):
    ans_def += abs(A[i]-A[i-1])
  for i in range(1, N+1):
    print(ans_def-abs(A[i-1]-A[i])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
if __name__ == "__main__":
  main()

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

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))

def main():
    n=int(input())
    A=inputintlist()
    ssum=abs(0-A[0])+abs(0-A[-1])
    for a in range(n-1):
        ssum+=abs(A[a]-A[a+1])
    A=[0]+A+[0]
    for a in range(1,n+1):
        ans=ssum-(abs(A[a]-A[a-1])+abs(A[a]-A[a+1]))+abs(A[a-1]-A[a+1])
        print(ans)
main()

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
D=[abs(A[0])]
for i in range(n-1):
    D.append(abs(A[i+1]-A[i]))
D.append(abs(A[-1]))
s=sum(D)
for i in range(n):
    c=s
    c-=D[i]+D[i+1]
    if i==0:
        c+=abs(A[1])
    elif i==n-1:
        c+=abs(A[-2])
    else:
        c+=abs(A[i+1]-A[i-1])
    print(c)

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

Solution (Python):
from itertools import chain


def cost(p1, p2):
    return abs(p1 - p2)


input()
points = tuple(chain.from_iterable(([0], tuple(map(int, input().split(' '))), [0])))

base_cost = sum([cost(p, pre_p) for pre_p, p in zip(points, points[1:])])

for pre_p, p, next_p in zip(points, points[1:], points[2:]):
    diff = cost(pre_p, next_p) - cost(pre_p, p) - cost(p, next_p)
    print(base_cost + diff)

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

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

Solution (Python):
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
D = B[1:] + B[:-1]
total = B.sum()
for i in range(N):
    print(total - D[i] + C[i])

Solution (Python):
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
total = B.sum()
for i in range(N):
    print(total - B[i:i + 2].sum() + C[i])

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

distances = []

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

S = sum(distances)

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
B = [0]
b = 0
for i in range(1,N+2):
    B.append(B[i-1]+abs(b-A[i]))
    b = A[i]
for i in range(1,N+1):
    x,y = B[i]-B[i-1],B[i+1]-B[i]
    z = abs(A[i+1]-A[i-1])
    print(B[N+1]-x-y+z)

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

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
pre = 0
yen = sum(abs(i - j) for i, j in zip(A, A[1:]))
ans = [yen] * N
for i in range(N):
    ans[i] += -abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2])
print(*ans, sep='\n')

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

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

S = 0

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

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

Solution (Python):
def main():
    m, *a = map(int, open(0).read().split())
    a = [0] + a + [0]
    s = 0
    p = [abs(i - j) for i, j in zip(a, a[1:])]
    s = sum(p)
    t = [str(s - abs(i - j) - abs(j - k) + abs(k - i)) for i, j, k in zip(a, a[1:], a[2:])]
    ans = "\n".join(t)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

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

    max = 0

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

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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

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

cost = []

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

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

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

lst = []
before = 0
for num in a:
    lst.append(abs(num - before))
    before = num
total = sum(lst)
for i in range(n):
    if i == 0:
        print(total - lst[i] - lst[i + 1] + abs(a[i+1]))
    else:
        print(total - lst[i] - lst[i + 1] + abs(a[i - 1] - a[i + 1]))

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

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

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

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

for i in range(1, n + 1):
    ans = total - 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]
 
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):
n = int(input())

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

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

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

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

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

    ans = []
    for i in range(1,N+1):
        res = sm - (abs(A[i]-A[i-1])+abs(A[i+1]-A[i])) + abs(A[i+1]-A[i-1])
        ans.append(res)

    print(*ans,sep='\n')

if __name__ == '__main__':
    solve()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

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

    for i in range(N):
        l1=A[i+1]-A[i]
        l2=A[i+2]-A[i]
        l3=A[i+2]-A[i+1]
        print(S-abs(abs(l2)-(abs(l3)+abs(l1))))
if __name__=="__main__":
    main()

Solution (Python):
import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1]))

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

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0,0)
A.append(0)
S = 0
for i in range(1,N+2):
  S += abs(A[i] - A[i-1])
for i in range(1,N+1):
  tmp = [A[i-1],A[i],A[i+1]]
  tmp.sort()
  ans = 0
  if tmp[1] == A[i]:
    ans = S
  elif tmp[2] == A[i]:
    ans = S- (tmp[2]-tmp[1])*2
  else:
    ans = S - (tmp[1]-tmp[0])*2
  print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
total = np.abs(np.diff(A)).sum()
saved = np.abs(A[1:-1]-A[:-2])+np.abs(A[1:-1]-A[2:])-np.abs(A[:-2]-A[2:])
answer = total - saved
print(*answer, sep='\n')