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



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Accepted

Solution code:
import numpy as np
import math

# class Place():
#     def __init__(self, idx, x, cost):
#         self.idx = idx
#         self.x = x
#         self.cost = cost

# def calc_distance(max_value, min_value):
#     if (max_value < 0):
#         return 2 * abs(max_value) + 2 * abs(max_value - min_value)
#     elif (min_value > 0):
#         return 2 * abs(min_value) + 2 * abs(max_value - min_value)
#     else:
#         return 2 * (abs(min_value) + abs(max_value))


# def calc_cost(X):
#     N = len(X)
#     assert(calc_distance(3, -1) == 8)
#     assert(calc_distance(-1, -3) == 6)
#     assert(calc_distance(5, 3) == 10)
#     for i in range(N):
#         if i == 0:
#             X[i].cost = calc_distance(X[N - 1].x, X[1].x)
#         elif i == N - 1:
#             X[i].cost = calc_distance(X[N - 2].x, X[0].x)
#         else:
#             X[i].cost = calc_distance(X[N - 1].x, X[0].x)
#     return X


def main():
    N = int(input())

    X = [int(c) for c in input().split()]
    X.insert(0, 0)
    X.append(0)
    Y = []
    length = len(X)
    for i in range(length - 1):
        Y.append(X[i + 1] - X[i])
    normal_distance = 0
    for i in range(length - 1):
        normal_distance += abs(Y[i])
    for i in range(N):
        if Y[i + 1] * Y[i] >= 0: 
            print(normal_distance)
        else:
            print(normal_distance - 2 * min(abs(Y[i]), abs(Y[i + 1])))

    # input_lists = [int(c) for c in input().split()]
    # for i in range(N):
    #     x = input_lists[i]
    #     place = Place(i, x, None)
    #     X.append(place)

    # X = sorted(X, key=lambda t: t.x)

    # assert(X[0].x == min(input_lists))

    # X = calc_cost(X)

    # X = sorted(X, key=lambda X: X.idx)

    # for i in range(N):
    #     print(X[i].cost)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.insert(0,0)
A.append(0)
N += 2

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
dd = list(map(int, input().split()))
d = [0]
d.extend(dd)
d.append(0)

diff = [abs(d[i + 1] - d[i]) for i in range(N + 1)]
dd = []
for i in range(N):
    temp = abs(d[i + 1] - d[i]) + abs(d[i + 2] - d[i + 1])
    temp_2 = abs(d[i + 2] - d[i])
    if temp > temp_2:
        dd.append(temp - temp_2)
    else:
        dd.append(0)
s = sum(diff)
for i in range(N):
    print(s - dd[i])

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
arr.append(0)
arr+=list(map(int,input().split()))
arr.append(0)
total=0
for i in range(n+1):
  total+=abs(arr[i+1]-arr[i])
for i in range(1,n+1):
  diff=abs(arr[i+1]-arr[i])+abs(arr[i]-arr[i-1])-abs(arr[i+1]-arr[i-1])
  print(total-diff)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
inter = []

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

SUM = sum(inter)

for j in range(n):
    diff = inter[j]+inter[j+1]-abs(a[j]-a[j+2])
    ans = SUM-diff
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
inter = []

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

SUM = sum(inter)

for j in range(n):
    diff = inter[j]+inter[j+1]-abs(a[j]-a[j+2])
    ans = SUM-diff
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = abs(A[0]) + abs(A[-1])
for i in range(N-1):
  s += abs(A[i+1] - A[i])
#print(s)
for i in range(N):
  b = A[i]
  if i == 0:
    a = 0
  else:
    a = A[i-1]
  if i == N-1:
    c = 0
  else:
    c = A[i+1]
  print(s-abs(b-a)-abs(c-b)+abs(c-a))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = abs(A[0]) + abs(A[-1])
for i in range(N-1):
  s += abs(A[i+1] - A[i])
#print(s)
for i in range(N):
  b = A[i]
  if i == 0:
    a = 0
  else:
    a = A[i-1]
  if i == N-1:
    c = 0
  else:
    c = A[i+1]
  if a <= b and b <= c:
    print(s)
  elif a <= c and c <= b:
    print(s-(b-c)*2)
  elif b <= a and a <= c:
    print(s-(a-b)*2)
  elif b <= c and c <= a:
    print(s-(c-b)*2)
  elif c <= a and a <= b:
    print(s-(b-a)*2)
  else:
    print(s)

Submission status: Accepted

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

#普通に総和を出す
sum = sum(diff)
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= diff[i-1]
  nowsum -= diff[i]
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)

Submission status: Accepted

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

#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)

Submission status: Accepted

Solution code:
n = int(input())
tmpa = list(map(int, input().split()))
A = [0] * (n+2)
A[0] = 0
A[n+1] = 0
for i in range(1,n+1,1): A[i] = tmpa[i-1]


#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)

Submission status: Accepted

Solution code:
N=int(input())
ai=list(map(int,input().split()))

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

print(sum - abs(0-ai[0]) - abs(ai[0]-ai[1]) + abs(0-ai[1]))

for i in range(N-2):
    m = sum - abs(ai[i]-ai[i+1]) - abs(ai[i+1]-ai[i+2]) + abs(ai[i]-ai[i+2])
    print(m)

print(sum - abs(ai[N-2]-ai[N-1]) - abs(ai[N-1]-0) + abs(ai[N-2]-0))

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(1,N+1):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]
a.extend([int(i) for i in input().split()])
a.append(0)
b = [0]*(n+2)
for i in range(n+1):
    b[i+1] = b[i] + abs(a[i+1] - a[i])
for i in range(n):
    ans = b[-1] + abs(a[i+2] - a[i]) - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1])
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=[0]+list(map(int,input().split()))+[0]
ans=0
l1=[]
l2=[]
for i in range(n+1):
  ans+=abs(m[i+1]-m[i])
for i in range(1,n+1):
  l1.append(abs(m[i]-m[i-1])+abs(m[i]-m[i+1]))
  l2.append(abs(m[i+1]-m[i-1]))
for i in range(n):
  print(ans-l1[i]+l2[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0]+[int(_) for _ in stdin.readline().rstrip().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])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))

Submission status: Accepted

Solution code:
import math
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
a = LI()
a.insert(0,0)
a.append(0)
diff = [abs(a[i] - a[i-1]) for i in range(1,len(a))]
money = sum(diff)
# print(a)
# print(diff)
for i in range(1,len(a)-1):
    if a[i-1] <= a[i] <= a[i+1]:
        print(money)
    elif a[i+1] <= a[i] <= a[i-1]:
        print(money)
    elif a[i] <= a[i-1] <= a[i+1]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i+1] <= a[i-1] <= a[i]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i-1] <= a[i+1] <= a[i]:
        print(money-2*abs(a[i+1]-a[i]))
    else:
        # a[i] <= a[i+1] <= a[i-1]
        print(money-2*abs(a[i+1]-a[i]))

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
dd = {}
for i in range(N+1):
    d[i] = abs(A[i+1] - A[i])
for i in range(N):
    dd[i] = abs(A[i+2] - A[i])

sA = sum(d.values())
for i in range(N):
    ans = sA - d[i+1] - d[i] + dd[i]
    print(ans)

Submission status: Accepted

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

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

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

for i in range(1, n+1):
    # delete the i-th spot
    total = total_tmp - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1])
    print(total)

Submission status: Accepted

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

total = 0
costs = []
for i in range(1, N+1):
    total += abs(As[i] - As[i-1])
    x1 = As[i] - As[i-1]
    x2 = As[i+1] - As[i-1]
    if x1 * x2 >= 0 and abs(x1) <= abs(x2):
        costs.append(0)
    elif x1 * x2 >= 0 and abs(x1) > abs(x2):
        costs.append(2 * abs(x2 - x1))
    elif x1 * x2 < 0:
        costs.append(2 * abs(x1))
total += abs(As[N+1] - As[N])

for i in range(N):
    print(total - costs[i])

Submission status: Accepted

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

sum_all = 0
for i in range(N+2):
 if(i != 0):
  sum_all += abs(A[i]-A[i-1])

#消えた部分の前後の部分コストのみ再計算
#(ex) a b c 
#-> cost_prev = abs(a-b) + abs(b-c)
#b消し
#-> a c
#-> cost_after = abs(a-c)
#ans = sum_all - cost_prev + cost_after
for i in range(N+2):
  if((i != 0)and(i != N+1)):
    cost_prev = abs(A[i-1]-A[i])+abs(A[i]-A[i+1])
    cost_after = abs(A[i-1]-A[i+1])
    ans = sum_all - cost_prev + cost_after
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()] + [0]
dist = []
tmp = 0
alldist = 0

for i in A:
    dist.append(i-tmp)
    tmp = i

for i in dist:
     alldist += abs(i)

for i in range(N):
    print(alldist - (abs(dist[i])+abs(dist[i+1])-abs(dist[i]+dist[i+1])))

Submission status: Accepted

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

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

Submission status: Accepted

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

x=[0]
x[0]=A[0]
for i in range(2,N+3):
    x.append(x[i-2]+abs(A[i-1]-A[i-2]))

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

Submission status: Accepted

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    N = II()
    A = [0] + MIL() + [0]
    d = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
    cost = sum(d)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j==0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-2*abs(B[0]))
        else:
            print(S-2*abs(B[1]-B[0]))
    elif j==len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-2*abs(B[-1]))
        else:
            print(S-2*abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-2*abs(B[j-1]-B[j]))
        else:
            print(S-2*abs(B[j+1]-B[j]))

Submission status: Accepted

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


sums = abs(a[0])
flags = [0 for _ in range(n+1)]

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

a.insert(0,0)

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

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
ar.insert(0,0)
ar.append(0)
count = 0
for i in range(1,a+2):
    count += abs(ar[i]-ar[i-1])
for i in range(1,a+1):
    b = abs(ar[i-1]-ar[i+1])
    c = abs(ar[i-1]-ar[i])
    d = abs(ar[i]-ar[i+1])
    print(count + b - c - d)

Submission status: Accepted

Solution code:
N = input()
A = [0] + map(int, raw_input().split()) + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    print cost - abs(a - b) - abs(b - c) + abs(a - c)

Submission status: Accepted

Solution code:
N = input()
A = map(int, raw_input().split())
A = [0] + A + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    if max(a, b, c) == b or min(a, b, c) == b:
        diff = - abs(a - b) - abs(b - c) + abs(a - c)
    else:
        diff = 0
    print cost + diff

Submission status: Accepted

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

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

Submission status: Accepted

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

AA = [0]
AA.extend(A)
AA.append(0)

Adif1 = []

for i in range(1, N + 2):
	x = abs(AA[i] - AA[i - 1])
	Adif1.append(x)

s = sum(Adif1)

Adif2 = []

for i in range(2, N + 2):
	x = abs(AA[i] - AA[i - 2])
	Adif2.append(x)

for i in range(N):
	print(s + Adif2[i] - Adif1[i] - Adif1[i + 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = [0]+inpl()+[0]
sumtr = 0
for i in range(N+1):
    sumtr += abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(sumtr +abs(A[i+1]-A[i-1]) -abs(A[i]-A[i-1]) -abs(A[i+1]-A[i]))

Submission status: Accepted

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

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

for i in range(n):
    mae = 0 if i == 0 else a[i-1]
    ato = 0 if i == n-1 else a[i+1]
    q = abs(a[i] - mae) + abs(ato - a[i])
    w = abs(ato - mae)
    print(s - q + w)

Submission status: Accepted

Solution code:
N=int(input().strip())
a=[0]
b=list(map(int, input().split()))
for i in range(N):
    a.append(b[i])
a.append(0)

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(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]:
        sub = 0
    elif A[i-1] <= A[i+1] <= A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] <= A[i-1] <= A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] <= A[i-1] <= A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] <= A[i+1]<= A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(cost - sub)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

for i in range(1, N + 1):
    d1 = abs(A[i - 1] - A[i])
    d2 = abs(A[i + 1] - A[i])
    d3 = abs(A[i - 1] - A[i + 1])
    print(sum - d1 - d2 + d3)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
n = int(input())
va = [0] + list(map(int, input().split())) + [0]
diffs = []

total = 0
for i, j in zip(va, va[1:]):
    total += abs(j-i)

for i, j, k in zip(va, va[1:], va[2:]):
    print(total-(abs(j-i)+abs(k-j)-abs(k-i)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])
ans_pre = 0
for i in range(0,n+1):
    ans_pre += abs(list_memo[i])
for i in range(0,n):
    ans = ans_pre - abs(list_memo[i]) - abs(list_memo[i+1]) + abs(list_memo[i] + list_memo[i+1])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

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

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



for i in range(N):
  if i==0:
    #0,2,5や0,-2,-3の場合は移動距離は変わらない
    if (0<=A[i] and A[i]<=A[i+1]) or (0>=A[i] and A[i]>=A[i+1]):
      print(distance)
    #0,2,1や0,-3,-2の場合はabs(a[i]-a[i+1])分移動距離が短くなる
    else:
      print(distance-(abs(A[i])+abs(A[i+1]-A[i]))+abs(A[i+1]))
  elif i==N-1:
    #-3,-2,0や5,3,0
    if (A[i-1]<=A[i] and A[i]<=0) or (A[i-1]>=A[i] and A[i]>=0):
      print(distance)
    #2,5,0や-2,-3,0
    else:
      print(distance-(abs(A[i]-A[i-1])+abs(A[i]))+abs(A[i-1]))
  else:
    #2,3,5や-3,-5,-9
    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(distance)
    #3,5,-1や-2,-4,1や3,5,4や-2,-4,-3
    #iと前後の項の距離を抜いて前後の項同士の距離を足す
    #iが0やNの時はどちらかが0の場合で同じように考える
    else:
      print(distance-(abs(A[i]-A[i-1])+abs(A[i+1]-A[i]))+abs(A[i+1]-A[i-1]))

Submission status: Accepted

Solution code:
n = int(input())


arr = []
arr.append(0) 
arr.extend(map(int,raw_input().split()))
arr.append(0)

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

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

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  t = input().split(" ")
  a = [0] + [int(i) for i in t] + [0]
  
  d = []
  dd = []
  sum = 0
  for i in range(N+1):
    d.append(abs(a[i] - a[i+1]))
    if i != 0:
      dd.append(abs(a[i-1] - a[i+1]))
    sum += d[i]
  for i in range(N):
    print(sum - d[i] - d[i+1] + dd[i])
main()

Submission status: Accepted

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

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

route_sum += abs(a[n - 1])

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

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

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

N = read()
A = [0] + reads() + [0] # len(A) = N + 2
planned = sum(abs(A[i+1] - A[i]) for i in range(N+1))
for i in range(1, N+1):
  diff = abs(A[i+1]-A[i]) + abs(A[i]-A[i-1]) - abs(A[i+1]-A[i-1])
  print(planned - diff)

Submission status: Accepted

Solution code:
def solve(n, xs):
    ss = [0] + [abs(a - b) for (a, b) in zip(xs + [0], [0] + xs)]
    for i in range(1, n + 1):
        ss[i + 1] += ss[i]
    cost2 = [abs(a - b) for (a, b) in zip(xs[1:] + [0], [0] + xs[:n - 1])]
    for k in range(n):
        yield ss[n + 1] - ss[k + 2] + ss[k] + cost2[k]

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    for ans in solve(n, xs):
        print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

N = int(input())

spot = np.zeros(N + 1)
spot[1:] = np.array(list(map(int, input().split())))

tot = int(np.abs(np.roll(spot, 1) - spot).sum())

for i in range(1, N+1):
    print(int(tot - math.fabs(spot[i] - spot[i-1]) - math.fabs(spot[(i+1) % (N+1)] - spot[i])\
            + math.fabs(spot[(i+1) % (N+1)] - spot[i-1])))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A+[0]
travel=0
for i in range(N+1):
    travel+=abs(A[i+1]-A[i])
ans =[]
for i in range(1,N+1):
    ans.append(travel-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.empty(n+2, dtype=np.int)
a[0] = 0
a[n+1] = 0
a[1:n+1] = np.int64(input().split())
da = np.absolute(a[1:] - a[:-1])
gain = da[1:] + da[:-1]
loss = np.absolute(a[2:] - a[:-2])
s = da.sum()
for i in range(n):
    print(s+loss[i]-gain[i])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lis = [0] + list(map(int, input().split())) + [0]
tmp = []
for j in range(len(lis)-1):
    tmp.append(lis[j+1] - lis[j])
lis = list(map(abs,tmp))
preans = sum(lis)
for i in range(len(tmp)-1):
    print(preans - lis[i] - lis[i+1] + abs(tmp[i] + tmp[i+1]))

Submission status: Accepted

Solution code:
n = int(input())
points = [0] + list(map(int,input().split())) + [0]
time = [0]
for a, b in zip(points, points[1:]):
    time.append(time[-1] + abs(a - b))
for i in range(n):
    ans = time[i] + abs(points[i] - points[i+2]) - time[i+2] + time[-1]
    print(ans)

Submission status: Accepted

Solution code:
num = input()
num_list = [int(i) for i in input().split(' ')]

from collections import deque

def cal_minus(three_pos):
    p = three_pos[0]
    c = three_pos[1]
    n = three_pos[2]
    dic = {'p':p, 'c': c, 'n':n}
    sorted_dict = sorted(dic.items(), key=lambda x : x[1])
    name = sorted_dict[1][0]
    if name == 'p':
        return 2 * abs(p-c)
    elif name == 'c':
        return 0
    else:
        return 2 * abs(c-n)
        

minus_list = []
three_pos = deque([0, num_list[0], num_list[1]])
for i in range(0, len(num_list)):
    minus = cal_minus(three_pos)
    minus_list.append(minus)
    if i < len(num_list)-2:
        next_ = num_list[i + 2]
    else:
        next_ = 0
    three_pos.append(next_)
    three_pos.popleft()
    
all_ = 0
pre = 0
for i in range(len(num_list)):
    plus = abs(num_list[i] - pre)
    pre = num_list[i]
    all_ += plus
all_ += abs(num_list[-1])

for i in minus_list:
    print(all_-i)