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


"""
Created on 2019/3/21
Solved on 2019/3/
@author: shinjisu
"""






def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] 

def getIntMat(n, m):  
    
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = zeros(N+2)
    A[1:N+1] = getIntList()
    d.dmp((A), 'A')
    yenAll = 0
    for i in range(1, N+2):
        yenAll += abs(A[i]-A[i-1])
    d.dmp((yenAll), 'A')
    yenOmit = yenAll
    for i in range(1, N+1):
        yenOmit = yenAll - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i])
        yenOmit += abs(A[i+1]-A[i-1])
        print(yenOmit)
    return None


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

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

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
ans = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    ans+=abs(A[i+1]-A[i])
for i in range(N):
    A_1 = A[i]
    if i==0:
        A_0 = 0
        A_2 = A[i+1]
    elif i==N-1:
        A_0 = A[i-1]
        A_2 = 0
    else:
        A_0 = A[i-1]
        A_2 = A[i+1]
    tmp = ans -abs(A_1-A_0) - abs(A_1-A_2) + abs(A_2-A_0)
    print(tmp)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
ans = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    ans+=abs(A[i+1]-A[i])
ans = [ans] * N
for i in range(N):
    A_1 = A[i]
    if i==0:
        A_0 = 0
        A_2 = A[i+1]
    elif i==N-1:
        A_0 = A[i-1]
        A_2 = 0
    else:
        A_0 = A[i-1]
        A_2 = A[i+1]
    ans[i] += -abs(A_1-A_0) - abs(A_1-A_2) + abs(A_2-A_0)
    print(ans[i])

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


Xi.insert(0, 0)
Xi.append(0)

Ci = [0]
total = 0
for i in range(1, N + 2):
    total += abs(Xi[i] - Xi[i - 1])
    Ci.append(total)
for i in range(1, N + 1):
    left = Ci[i - 1]
    right = Ci[-1] - Ci[i + 1]
    ans = left + right + abs(Xi[i + 1] - Xi[i - 1])
    print(ans)

Solution (Python):


import sys


n = int(sys.stdin.readline().rstrip())
An = [0] + list(map(int, sys.stdin.readline().rstrip().split())) + [0]
asum = 0
for i in range(1,n+2):
  asum = asum+abs(An[i]-An[i-1])

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

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

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

for i in range(1, n+1):
    if (s[i] - s[i-1]) * (s[i+1] - s[i]) >= 0:
        print(c)
    else:
        a = min(abs(s[i] - s[i - 1]), abs(s[i + 1] - s[i]))
        print(c - a * 2)

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

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

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

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

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

Solution (Python):
input = open(0).read

N, *A = [int(i) for i in input().split()]


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

    num = sum(l)

    print(num - l[0] + abs(A[1]) + abs(A[-1]))

    if N != 2:
        print("\n".join(
            [str(num - l[i] - l[i + 1]
                 + abs(A[i] - A[i + 2])
                 + abs(A[0]) + abs(A[-1])) for i in range(N - 2)]))

    print(num - l[-1] + abs(A[0]) + abs(A[-2]))
    return


main()

Solution (Python):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    l = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    num = sum(l)
    print("\n".join(
        [str(num - l[i] - l[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
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 LSR(n): return [LS() for i in range(n)]
mod = 1000000007


"""
a = IR(2)
b = IR(2)
print(min(a)+min(b))
"""


"""
n = I()
d, x = LI()
a = IR(n)
ans = x
for i in a:
    k = 0
    while k * i + 1 <= d:
        ans += 1
        k += 1
print(ans)
"""


n = I()
a = LI()
a.insert(0, 0)
a.append(0)
ans = 0
for i in range(1, n + 2):
    ans += abs(a[i] - a[i - 1])

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

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

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

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

for i in range(1, len(A)-1):
    n_cost = 0
    if A[i-1] <= A[i] and A[i] <= A[i + 1]:
        n_cost = cost
    elif A[i] <= A[i - 1] and A[i] <= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i] >= A[i - 1] and A[i] >= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i-1] >= A[i] and A[i] >= A[i + 1]:
        n_cost = cost

    print(n_cost)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    a,b,c,d = IR(4)
    print(min(a,b)+min(c,d))


def B():
    n = I()
    d,x = LI()
    a = IR(n)
    for i in range(1,d+1):
        for j in a:
            if (i-1)%j == 0:
                x += 1
    print(x)

def C():
    n = I()
    a = LI()
    ans = abs(a[0])
    for i in range(n-1):
        ans += abs(a[i+1]-a[i])
    ans += abs(a[-1])
    a.insert(0,0)
    a.append(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(ans)
        else:
            print(ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

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

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

diff = [abs(a[0])]

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

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

min_cost = 10**10
ori = sum(diff)
a.append(0)
a.insert(0,0)
for i in range(n):
    cost = ori - diff[i] - diff[i+1]
    cost += abs(a[i] - a[i+2])
    print(cost)

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

upplim = N-1
for i in range(upplim):
    print(str(dist[i] + abs(A[i+2] - A[i]) + dist[N] - dist[i+2] + abs(A[N])))
print(str(dist[N-1] + abs(A[N-1])))

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
lis = []
lis.append(0)
for hoge in li:
    lis.append(hoge)
lis.append(0)
sumpo = 0
sumpo += abs(li[0])
for i in range(1,n+1):
    sumpo += abs(lis[i]-lis[i+1])
for i in range(1,n+1):
    print(sumpo + abs(lis[i+1]-lis[i-1]) - (abs(lis[i]-lis[i-1])+abs(lis[i+1]-lis[i])))

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

Solution (Python):
def traveling_plan(N: int, A: list) -> list:
    
    A = [0] + A + [0]
    
    d = [0] * (N + 1)
    
    S = 0

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

    def diff(a: int, b: int) -> int:
        return (a + b) - (max(a, b) - min(a, b))

    return [S - diff(abs(d[i]), abs(d[i + 1])) if d[i] * d[i + 1] < 0 else S
            for i in range(N)]


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = traveling_plan(N, A)
    for a in ans:
        print(a)

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

for j in range(N):
    
    if j == 0:
        if (0 <= An[j] <= An[j + 1]) or (0 >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1]) - abs(An[j]) + abs(An[j + 1]) )
    else:
        print(dis - abs(An[j] - An[j + 1]) - abs(An[j] - An[j - 1]) + abs(An[j - 1] - An[j + 1]) )

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

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

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

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

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

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

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


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

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

base = sum([abs(A[i]-A[i+1]) for i in range(N+1)])

B = [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)]

ans = [x + base for x in B]

for x in ans:
    print(x)

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

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

x1 = [abs(a[0])] + [abs(a[i]-a[i+1]) for i in range(N-1)] + [abs(a[-1])] 
x2 = [abs(a[1])] + [abs(a[i]-a[i+2]) for i in range(N-2)] + [abs(a[-2])] 

res0 = sum(x1)

for i in range(N):
    print(res0 - x1[i] - x1[i+1] + x2[i])

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

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

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
N = int(input())
A = [0] + [int(n) for n in input().split()] + [0]
sumA = 0
for i in range(1,N+2):
    sumA += abs(A[i]-A[i-1])

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    total = 0
    for i in range(len(A)-1):
        total += abs(A[i+1] - A[i])

    for i in range(N):
        print(total - 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]
diffa = [a[i+1] - a[i] for i in range(n+1)]
cost = sum([abs(diffa[i]) for i in range(len(diffa))])
for i in range(n):
    res = cost - abs(diffa[i]) - abs(diffa[i+1])
    res += abs(diffa[i] + diffa[i+1])
    print(res)

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

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N=ri()
A=rl()

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


for i in range(1,N+1):
    if d[i-1]*d[i] >= 0:
        print(sum)
    else:
        print(sum-2*min(abs(d[i-1]),abs(d[i])))

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

for i, a in enumerate(A):
    if i < len(A) - 1:
        L.append(abs(A[i] - A[i+1]))
    if i < len(A) - 2:
        LL.append(abs(A[i] - A[i+2]))

s = sum(L)

for i in range(N):
    ans = s - L[i] - L[i+1] + LL[i]
    print(ans)

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

for i, a in enumerate(A):
    if i < len(A) - 1:
        L.append(abs(A[i] - A[i+1]))
    if i < len(A) - 2:
        LL.append(abs(A[i] - A[i+2]))

s = sum(L)

for i in range(N):
    ans = s - L[i] - L[i+1] + LL[i]
    print(ans)

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


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



for i in range(1,n+1):
    if A[i-1]<=A[i]<=A[i+1] :
        print(su)
    else :
        print(su-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]
for x in list(map(int,input().split())):
	A.append(x)
A.append(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])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))

Solution (Python):
import copy
import numpy as np
n = int(input())
a = list(map(int, input().split()))
S = sum(abs(np.array([0] + a) - np.array(a+[0])))
a = [0] + a + [0]
for i in range(1, len(a)-1):
    cost = S + abs(a[i-1] - a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]))
    print(cost)

Solution (Python):
n,*a=map(int,open(0).read().split());x=abs
c=[0]+a+[0];y=sum(x(c[t]-c[t+1])for t in range(n+1))
for i in range(n):s,t,r=c[i:i+3];print(y+x(r-s)-x(t-s)-x(t-r))

Solution (Python):
n,*a=map(int,open(0).read().split());c=[0]+a+[0]
y=sum(abs(c[t]-c[t+1])for t in range(n+1))
for i in range(n):s,t,r=c[i:i+3];print(y+abs(r-s)-abs(t-s)-abs(t-r))

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

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

a = [0] + a + [0]
sum_a = 0
for i in range(len(a)-1):
    sum_a += abs(a[i+1] - a[i] )
    
for i in range(n):
    print(sum_a + abs(a[i+2]-a[i]) - abs(a[i+1]- a[i])  -abs(a[i+2]-a[i+1]))

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

for i in range(1,n+1):
    if (A[i-1]-A[i])*(A[i]-A[i+1])>=0:
        print(cnt)
    else:
        print(cnt-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 = [0] + list(map(int,input().split())) + [0]
sa = [abs(a[i]-a[i+1]) for i in range(n+1)]
sum_sa = sum(sa)

for i in range(n):
    yen = sum_sa + abs(a[i+2]-a[i]) - sa[i] - sa[i+1]
    print(yen)

Solution (Python):


import sys

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

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = [0] + LI() + [0]
C = [0]
for a1, a2 in zip(A[:-1], A[1:]):
    C.append(C[-1] + abs(a2 - a1))

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

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

Solution (Python):
import copy

n=int(input())
a=list(map(int,input().split()))
x=abs(a[0])+abs(a[-1])
for i in range(n-1):
  x+=abs(a[i+1]-a[i])
for i in range(n):
  dp=copy.deepcopy(x)
  if i==0:
    dp=dp-abs(a[1]-a[0])-abs(a[0])+abs(a[1])
  if i==n-1:
    dp=dp-abs(a[-1])-abs(a[-1]-a[-2])+abs(a[n-2])
  elif 0<i<n-1:
    dp=dp-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])
  print(dp)

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

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


main()

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

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

Solution (Python):
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

n = int(input())

a = [0] + input_numbers() +[0]

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

sum = 0

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

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

Solution (Python):

n = int( input() )

A = [0]*(n+2)
B = [0]*(n+1)
t = list(map(int,input().split()))

S_Bn = 0
for i in range(1,n+2):
    A[i] = t[i-1] if i<n+1 else 0
    B[i-1] = abs( A[i] - A[i-1] )
    S_Bn += B[i-1]






for i in range(n):
    ans_i = S_Bn - ( B[i] + B[i+1] ) + abs( A[i+2] - A[i] )
    print(ans_i)

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

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

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

Solution (Python):
def solve(A):
    N = len(A)
    A = [0] + A + [0]

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

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    solve(A)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)

lis = [a[0], a[1], a[2]]
S = abs(a[2])+sum([abs(a[k]-a[k+1]) for k in range(2, n+1)])
print(S)

for k in range(2, n+1):
    S += abs(lis[0]-lis[1])+abs(lis[1]-lis[2])-abs(lis[0]-lis[2])
    lis.pop(0)
    lis.append(a[k+1])
    S -= abs(lis[0]-lis[1])+abs(lis[1]-lis[2])-abs(lis[0]-lis[2])
    print(S)

Solution (Python):
def solve(N, As):
    costs = [abs(As[0])]
    costs.extend([abs(s - d) for s, d in zip(As, As[1:])])
    s = sum(costs) + abs(As[-1])

    skipcosts = [abs(As[1])]
    skipcosts.extend([abs(s - d) for s, d in zip(As, As[2:])])
    skipcosts.append(0)
    ans = []
    for i, c in enumerate(skipcosts):
        if i < N - 1:
            ans.append(str(s - costs[i] - costs[i + 1] + c))
        else:
            ans.append(str(s - costs[i] - abs(As[-1]) + abs(As[-2])))
    return "\n".join(ans)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

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

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

d1 = []
d2 = []
for i in range(1,N+2):
    if i != 1:
        d2.append(abs(A[i]-A[i-2]))
    d1.append(abs(A[i]-A[i-1]))
d1_total = sum(d1)

for i in range(N):
    print(d1_total-d1[i]-d1[i+1]+d2[i])

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

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

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

for i in range(1,N+1):
    print(dis + abs(L[i-1]-L[i+1]) - abs(L[i-1]-L[i]) - abs(L[i]-L[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(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 = [0] + list(map(int, input().split())) + [0]
original = 0
for i in range(N+1):
    original += 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(original)
    else:
        print(original - 2*min(abs(A[i]-A[i+1]), abs(A[i]-A[i-1])))

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

for i in range(n + 1):
    amt += abs(A[i] - A[i + 1])
    
for i in range(1, n + 1):
     print(amt - 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 = []
A.append(0)
B = [int(i) for i in input().split()]
A.extend(B)
A.append(0)

s = sum([abs(A[i]-A[i+1]) for i in range(N+1)])

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

Solution (Python):


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

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

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


if __name__ == '__main__':
    main()

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

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

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

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

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