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 sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    alist = intina()

    blist = [0]
    blist.extend(alist)
    blist.append(0)

    dlist = [abs(blist[i] - blist[i+1]) for i in range(n + 1)]
    ddlist = [abs(blist[i] - blist[i+2]) for i in range(n)]

    tsum = sum(dlist)

    for i in range(n):
        if blist[i] <= blist[i+1] and blist[i+1] <= blist[i+2]:
            print(tsum)
        elif blist[i] >= blist[i+1] and blist[i+1] >= blist[i+2]:
            print(tsum)
        else:
            print(tsum - dlist[i] - dlist[i+1] + ddlist[i])


if __name__ == '__main__':
    main()

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

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

for i in range(1,N+1):
  X = abs(A[i+1] - A[i-1])
  M = abs(A[i] - A[i-1])
  L = abs(A[i+1] - A[i])
  total += X -M - L
  print(total)
  total += M + L - X

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=[0]+IL()+[0]
s=0
for i in range(n+1):
    s+=abs(A[i+1]-A[i])
for i in range(1,n+1):
    ans=s
    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 = list(map(int, input().split()))

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

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

Solution (Python):

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data = [0] + data + [0]

    count = 0
    for i in range(num + 1):
        count += abs(data[i + 1] - data[i])

    for i in range(1, num + 1):
        print(count - abs(data[i] - data[i - 1]) - abs(data[i] - data[i + 1]) + abs(data[i - 1]- data[i + 1]))


if __name__ == '__main__':
    main()

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

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

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

for i in range(1, n + 1):
    l, r = min(a[i - 1], a[i + 1]), max(a[i - 1], a[i + 1])
    if l <= a[i] <= r:
        print(s)
    elif a[i] <= l:
        print(s-2*(l-a[i]))
    else:
        print(s-2*(a[i]-r))

Solution (Python):


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def submit():
    n, alist = read_input()

    dist_list  = []
    alist_se = [0] + alist + [0]

    for s,e in zip(alist_se, alist_se[1:]):
        dist_list.append(abs(e - s))

    origin = sum(dist_list)

    for i in range(1, n+1):
        
        
        diff = abs(alist_se[i-1] - alist_se[i]) + abs(alist_se[i] - alist_se[i+1]) - abs(alist_se[i-1] - alist_se[i+1])
        print(origin - diff)

if __name__ == '__main__':
    submit()

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):

import sys
INF = float("inf")


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

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

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

    buf = []
    for i in range(1, N+1):
        print(forward[i-1] + backward[i+1] + abs(A[i-1] - 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
INF = float("inf")


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

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

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

    
    
    
    
    

    
    

    
    
    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
input = sys.stdin.readline

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

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

for i in range(1,N):
    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(sm)
    else:
        print(sm - abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
print(sm if (0> A[-1] and A[-1]> A[-2]) or (0< A[-1] and A[-1]< A[-2]) else sm-abs(A[-1])-abs(A[-1]-A[-2])+abs(A[-2]))

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

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

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

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

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

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

Solution (Python):
N=int(input())
x=[0]+list(map(int,input().split()))+[0]
s=0
for i in range(N+1):
	s+=abs(x[i+1]-x[i])
for i in range(1, N+1):
	d1=x[i]-x[i-1]
	d2=x[i+1]-x[i]
	print(s - (2*min(abs(d1), abs(d2)) if d1<0 and d2>0 or d1>0 and d2<0 else 0))

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

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

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

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

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

now = 0
for i in range(N):
    add = 0
    add -= abs(now - A[i])
    if i < N-1:
        add -= abs(A[i] - A[i+1])
        add += abs(now - A[i+1])
    else:
        add -= abs(A[i])
        add += abs(now)
    now = A[i]
    print(money + add)

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

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


print(L-abs(a[0])-abs(a[0]-a[1])+abs(a[1]))

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

print(L-abs(a[N-1])-abs(a[N-2]-a[N-1])+abs(a[N-2]))

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
A.append(0)
D=[abs(A[0])]
for i in range(n-1):
  D+=[abs(A[i]-A[i+1])]
D.append(abs(A[n-1]))
d=sum(D)
for i in range(n):
  print(d+abs(A[i-1]-A[i+1])-D[i]-D[i+1])

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    A = [0] + A + [0]
    all = 0
    for i in range(1, len(A)):
        all += abs(A[i-1] - A[i])
    for i in range(1, len(A)-1):
        print(all + abs(A[i+1] - A[i-1]) -
              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):
from numpy import cumsum
N, *A = map(int, open(0).read().split())
A_dif = [abs(A[i] - A[i - 1]) if i != 0 else abs(A[i]) for i in range(N)]
cum_A = cumsum(A_dif)


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

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

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

    
for i in range(N):
    act = plan
    if not ((B[i] <= B[i+1] <= B[i+2]) or (B[i] >= B[i+1] >= B[i+2])):
        act -= 2*min(abs(B[i+1]-B[i]), abs(B[i+1]-B[i+2]))
    print(act)

Solution (Python):
N = int(input())
Alist = [int(x) for x in input().split()]
Alist.append(0)
full = 0
place = 0
for x in Alist:
    full += abs(max(place ,x) - min(place,x))
    place = x

place = 0
for i, j in zip(range(N+1),range(1,N+1)):
    if i > 0:
        place = Alist[i-1]
    through = Alist[i]
    nex = Alist[j]

    t = abs(max(place ,nex) - min(place,nex)) - (abs(max(place ,through) - min(place,through)) + abs(max(nex ,through) - min(nex,through)))
    print(full + t)

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

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

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

s = 0
for i in range(len(lst)-1):
    s += abs(lst[i+1]-lst[i])
    
for i in range(1, len(lst)-1):
    a = lst[i-1]
    b = lst[i]
    c = lst[i+1]
    if (b - a > 0 and c - b > 0) or (b - a < 0 and c - b < 0):
        print(s)
    else:
        print(s - abs(b-a) - abs(c-b) + abs(c-a))

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

for i in range(N):
  t = abs(A[i + 2] - A[i + 1])
  k = abs(A[i + 1] - A[i])
  p = abs(A[i + 2] - A[i])
  All += k
  L[i] = p - (t + k)
All += abs(A[-2])

for i in range(N):
  print(All + L[i])

Solution (Python):

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

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

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

t = 0
for n in range(0,N-1):
    t += abs(An[n] - An[n+1])
t += abs(An[0]) + abs(An[N-1])

for n in range(0, N):
    if n == 0:
        old_cost = abs(An[0]) + abs(An[1] - An[0])
        new_cost = abs(An[1])
    elif n == N-1:
        old_cost = abs(An[N-2] - An[N-1]) + abs(An[N-1])
        new_cost = abs(An[N-2])
    else:
        old_cost = abs(An[n-1] - An[n]) + abs(An[n] - An[n+1])
        new_cost = abs(An[n-1] - An[n+1])
    print(t - old_cost + new_cost)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



N = 0
A = []


def set_inputs():
    global N, A
    N = get_int()
    A = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    B = [0] + A + [0]
    total = sum(abs(x - y) for x, y in zip(B, B[1:]))
    distances = [abs(x - y) + abs(y - z) for x, y, z in zip(B, B[1:], B[2:])]
    skip_distances = [abs(x - y) for x, y in zip(B, B[2:])]
    for i in range(N):
        print(total - distances[i] + skip_distances[i])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

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

cost, place = 0, 0
for item in a:
  cost += abs(place - item)
  place = item
  
for i in range(1,n+1):
  print(cost + abs(a[i+1] - a[i-1]) - abs(a[i]-a[i-1]) - abs(a[i+1] -a[i]))

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

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

diff = [abs(i-j) for i, j in zip(a, a[1:])]
sum = sum(diff)

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

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

d = [0]*(n)

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

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

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

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

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

def a_i(p):
    global a
    if p < 0:
        return 0
    elif n <= p:
        return 0
    return a[p]

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

for i in range(0, n):
    p = a_i(i - 1) - a[i]
    q = a[i] - a_i(i + 1)
    m = p * q
    if m < 0:
        print(s - 2 * min(abs(p), abs(q)))
    else:
        print(s)

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

Solution (Python):
def main():
    n = int(input())
    a = [0] + [int(s) for s in input().split()] + [0]
    for x in solve(n, a):
        print(x)

def solve(n, a):
    s = [0]
    p = 0

    for x in a[1:]:
        s.append(s[-1] + abs(x - p))
        p = x
    
    r = []
    for i in range(1, n + 1):
        x = s[i-1] + (s[-1] - s[i+1]) + abs(a[i+1] - a[i-1])
        r.append(x)

    return r

main()

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

li_aw = [0] + li_a + [0]


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

for i in range(n):
    
    delete_index = i + 1
    delete_cost = abs(li_aw[delete_index - 1] - li_aw[delete_index]) + abs(li_aw[delete_index] - li_aw[delete_index + 1])
    add_cost = abs(li_aw[delete_index - 1] - li_aw[delete_index + 1])
    print(total_cost - delete_cost + add_cost)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A = LI()
"""
i番目を抜く時、iとi-1,iとi+1の距離を全体から引いて、そこにi-1とi+1の距離を足す
"""
A = [0] + A + [0]
total = 0
diff1 = []
diff2 = []
for aidx in range(len(A)):
    if aidx == 0:
        continue
    total += abs(A[aidx]-A[aidx-1])
    if aidx == len(A)-1:
        break
    diff1.append(abs(A[aidx] - A[aidx-1])+abs(A[aidx+1] - A[aidx]))
    diff2.append(abs(A[aidx-1] - A[aidx+1]))

for aidx in range(N):
    print(total-diff1[aidx]+diff2[aidx])

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A = LI()
"""
i番目を抜く時、iとi-1,iとi+1の距離を全体から引いて、そこにi-1とi+1の距離を足す
"""
A = [0] + A + [0]
total = 0
diff1 = []
diff2 = []
for aidx in range(len(A)):
    if aidx == 0:
        continue
    total += abs(A[aidx]-A[aidx-1])
    if aidx == len(A)-1:
        break
    diff1.append(abs(A[aidx] - A[aidx-1])+abs(A[aidx+1] - A[aidx]))
    diff2.append(abs(A[aidx-1] - A[aidx+1]))

for aidx in range(N):
    print(total-diff1[aidx]+diff2[aidx])

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

cost[N]=abs(A[N-1])+cost[N-1]

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

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
S = sum(abs(A[i]-A[i+1]) for i in range(len(A)-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):
def solve(string):
    n, *a = map(int, string.split())
    a = [0] + a + [0]
    diff = [abs(j - i) for i, j in zip(a, a[1:])]
    base = sum(diff)
    ans = [str(base - diff[i] - diff[i + 1] + abs(a[i + 2] - a[i])) for i in range(n)]
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = [0] + a + [0]
    base = sum([abs(j - i) for i, j in zip(a, a[1:])])
    ans = []
    for a0, a1, a2 in zip(a, a[1:], a[2:]):
        if min(a0, a1, a2) == a1:
            ans.append(str(base - 2 * abs(a1 - min(a0, a2))))
        elif max(a0, a1, a2) == a1:
            ans.append(str(base - 2 * abs(a1 - max(a0, a2))))
        else:
            ans.append(str(base))
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = [0] + a + [0]
    base = sum([abs(j - i) for i, j in zip(a, a[1:])])
    ans = []
    for i in range(1, n + 1):
        if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
            ans.append(str(base))
        elif max(a[i - 1], a[i + 1]) < a[i]:
            ans.append(str(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))
        else:
            ans.append(str(base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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

Solution (Python):
def calc_fee(l):
    s = 0
    for i in range(len(l)-1):
        s += abs(l[i+1] - l[i])
    return s

n = int(input())
A = [0] + [int(n) for n in input().split()] + [0]


total_fee = calc_fee(A)

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

Solution (Python):
import itertools
import collections
import bisect

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

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

    for i in range(1, N + 1):
        org = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])
        skip = abs(A[i+1] - A[i - 1])
        diff = org - skip
        print(total - diff)


if __name__ == '__main__':
    main()

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

l = list(map(int,input().split()))
l = [0]+l+[0]
dis = 0
for i in range(len(l)-1):
    dis += abs(l[i]-l[i+1])

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

Solution (Python):

import sys



def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    A.insert(0,0)
    A.append(0)
    cost = 0
    for i in range(N + 1):
        cost += abs(A[i] - A[i+1])

    for i in range(N):
        tcost = cost - abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2])
        print(tcost)
lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

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

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

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