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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) + [0] * 2
rec = []
num, pre = 0, 0
for i in range(n + 1):
    num += abs(a[i] - pre)
    rec.append((abs(a[i] - pre), abs(a[i + 1] - a[i]), abs(a[i + 1] - pre)))
    pre = a[i]

for i in range(n):
    print(num - rec[i][0] - rec[i][1] + rec[i][2])

Submission status: Accepted

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

Submission status: Accepted

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

now = 0
d = []
for p in a + [0]:
    d.append(abs(p - now))
    now = p

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
A=[0]
A.extend([int(i) for i in input().split()])
A.append(0)
Sb=[0 for i in range(n+2)]
t=0

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

for i in range(1,n+1):
  if max(abs(A[i]),abs(A[i-1]),abs(A[i+1])):
    cb=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])
    ca=abs(A[i+1]-A[i-1])
    print(t-cb+ca)
  else:
    print(t)

Submission status: Accepted

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

S = 0
Slist = []
for i in range(len(B)-1):
    distance = abs(B[i] - B[i+1])
    Slist.append(distance)
    S += distance

for j in range(len(A)):
    print(S + abs(B[j]-B[j+2]) - Slist[j] - Slist[j+1])

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
a_list = [0] + a_list + [0]
s = 0
for i in range(len(a_list)-1):
    s += abs(a_list[i+1]-a_list[i])
    
for i in range(0,len(a_list)-2):
    p = s - abs(a_list[i+1] - a_list[i]) - abs(a_list[i+2] - a_list[i+1]) + abs(a_list[i+2] - a_list[i])
    print(p)

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

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

s = sum(d)
for i in range(n):
    ans = s - d[i] - d[i+1] + abs(a[i+2] - a[i])
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sched = abs(A[0])

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

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

print(sched - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]))

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

print(sched - abs(A[N - 1]) - abs(A[N - 1] - A[N - 2]) + abs(A[N - 2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
sum_before = 0
for i in range(n-1):
    sum_before += abs(a[i] - a[i+1])
sum_before += abs(a[0])+abs(a[n-1])
for i in range(n):
    if i == 0:
        print(sum_before-(abs(a[0])+abs(a[1]-a[0])) + abs(a[1]))
    elif i == n-1:
        print(sum_before - (abs(a[n-2]-a[n-1])+abs(a[n-1]))+abs(a[n-2]))
    else:
        print(sum_before-(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 = input()
a = [0] + map(int, raw_input().split()) + [0]
l = sum([abs(a[i+1]-a[i]) for i in range(n+1)])
for i in range(1,n+1):
    print(l + 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()))

A = [0] + A + [0]
S = 0
k = 0
for a in A:
    S += abs(a-k)
    k = a

for i in range(1, N+1):
    a, b, c = A[i-1], A[i], A[i+1]
    d = abs(b-a) + abs(c-b) - abs(c-a)
    print(S-d)

Submission status: Accepted

Solution code:
n = int(input())    # 観光スポットの数
a = list(map(int, input().split())) # 観光スポットの座標
a.insert(0, 0)
a.append(0)
sum = 0
for i in range(0, n+1):
    sum += abs(a[i] - a[i+1])
for i in range(1, n+1):
    head = abs(a[i-1] - a[i])
    tail = abs(a[i] - a[i+1])
    mid = abs(a[i-1] - a[i+1])
    print(sum + mid - head - tail)

Submission status: Accepted

Solution code:
n = int(input())
As = input().split()
aa = 0
for i in range(n):
    a = int(As[i])
    As[i] = a
    if i == 0:
        aa += abs(a)
    else:
        aa += abs(a - As[i - 1])
aa += abs(As[n - 1])
for i in range(n):
    ans = aa
    if i == 0:
        ans  = ans - abs(As[0]) - abs(As[1] - As[0]) + abs(As[1])
    elif i == n- 1:
        ans  = ans - abs(As[n - 1]) - abs(As[n - 1] - As[n - 2]) + abs(As[n- 2])
    else:
        ans = ans - abs(As[i + 1] - As[i]) - abs(As[i] - As[i - 1]) + abs(As[i + 1] - As[i - 1])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

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

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


for i in range(len(nal)):
    print(nal[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# PROBLEM C
n = int(input())
As = [int(s) for s in input().split()]
As = [0] + As + [0]
full_cost = sum(abs(a - As[idx - 1]) for idx, a in enumerate(As) if idx - 1 >= 0)
for idx in range(1, len(As) - 1):
    a = As[idx]
    if any([
            As[idx - 1] <= a <= As[idx + 1],
            As[idx - 1] >= a >= As[idx + 1]]):
        ci = full_cost
    elif any([
            a > As[idx + 1] >= As[idx - 1],
            a < As[idx + 1] <= As[idx - 1]]):
        ci = full_cost - 2 * abs(a - As[idx + 1])
    elif any([
            a < As[idx - 1] <= As[idx + 1],
            As[idx + 1] <= As[idx - 1] < a]):
        ci = full_cost - 2 * abs(a - As[idx - 1])
    else:
        assert(False)
    print(ci)

Submission status: Accepted

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

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

for i in range(1, n+1):
    print(total - (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())
list = list(int(i) for i in input().split())
list.insert(0, 0)
list.insert(N+1, 0)
total = 0


for i in range(N+1):
    total += abs(list[i]-list[i+1])
for i in range(N):
    print(total - abs(list[i+1]-list[i+2]) - abs(list[i]-list[i+1]) + abs(list[i]-list[i+2]))

Submission status: Accepted

Solution code:
n = int(input())
arr = [0] + list(map(int,input().split())) + [0]
tmp= [ abs(arr[i] - arr[i + 1]) for i in range(len(arr) - 1)]
_sum = sum(tmp)
for i in range(n):
    ans = _sum - tmp[i] - tmp[i + 1] + abs(arr[i + 2] - arr[i])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [0]+A[:]+[0]
s = 0
for i in range(N+1):
    s += abs(B[i]-B[i+1])

for i in range(N):
    t = abs(B[i+1]-B[i])+abs(B[i+2]-B[i+1])-abs(B[i+2]-B[i])
    print(s-t)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [0]+A[:]+[0]
s = 0
for i in range(N+1):
    s += abs(B[i]-B[i+1])

for i in range(N):
    if B[i] < B[i+1] and B[i+1] <B[i+2]:
        print(s)
    else:
        t = abs(B[i+1]-B[i])+abs(B[i+2]-B[i+1])-abs(B[i+2]-B[i])
        print(s-t)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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(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())
A=list(map(int,input().split()))

A.insert(0,0)
A.insert(N+1,0)
sum=0


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


for j in range(1,N+1):
    tmp=0
    tmp=abs(A[j-1]-A[j+1])-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])
    print(sum+tmp)

Submission status: Accepted

Solution code:
n = int(input())
X = map(int, input().split())
X = list(X)
# n = 3
# X = [3, 5, -1]

X.insert(0,0)
X.append(0)
Y = []
for i, x in enumerate(X[1:]):
    Y.append(abs(x-X[i]))
sumY = sum(Y)

for i, x in enumerate(X):
    if i not in [0,len(X)-1]:
        ans = sumY - (Y[i-1] + Y[i]) + abs(X[i+1]-X[i-1])
        print(ans)

Submission status: Accepted

Solution code:

n = int(input())
spot_list = list(map(int,input().split()))
max_cost = 0

#maxの計算
for i in range(1,len(spot_list)):
    max_cost += abs(spot_list[i]-spot_list[i-1])
max_cost += abs(spot_list[0])+abs(spot_list[len(spot_list)-1])

spot_list = [0] + spot_list + [0]
for i in range(1,len(spot_list)-1):
    d_pay = abs(spot_list[i-1]-spot_list[i+1]) - (abs(spot_list[i]-spot_list[i-1])+abs(spot_list[i+1]-spot_list[i]))
    print(max_cost+d_pay)

Submission status: Accepted

Solution code:
N = int(input())
A_list = [0]
A_list.extend(list(map(int, input().split())))
A_list.append(0)
previous_val = 0
S = 0
for i in A_list[1:]:
    S += abs(previous_val - i)
    previous_val = i

for idx, val in enumerate(A_list):
    if idx == 0 or idx == (len(A_list) - 1):
        continue
    else:
        new_dif = abs(A_list[idx - 1] - A_list[idx + 1])
        old_dif = abs(A_list[idx - 1] - A_list[idx]) + abs(A_list[idx] - A_list[idx + 1])
        print(S + new_dif - old_dif)

Submission status: Accepted

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

i = 0
j = a[0]
s = abs(a[0])
for x in range(1, n+1):
    k = a[x]
    s += abs(j-k)
    if i<=j<=k or k<=j<=i:
        m.append(0)
    else:
        ij = abs(i-j)
        jk = abs(j-k)
        if ij<jk:
            m.append(-2*ij)
        else:
            m.append(-2*jk)
    i = j
    j = k
for x in m:
    print(s+x)

Submission status: Accepted

Solution code:
import copy

"""
def sumPrice(N, B):
    sum = 0
    for i in range(1, N):
        sum += abs(B[i] - B[i - 1])
    sum += abs(B[N-1] - B[0])
    return sum


N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
for i in range(1, N + 1):
    B = copy.deepcopy(A)
    del B[i]
    print(sumPrice(N, B))
"""
N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.insert(N+1, 0)

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

for i in range(1, N + 1):  # A[i] に行かない
    sumPrice = 0
    if (A[i - 1] < A[i] and A[i+1] < A[i])or(A[i - 1] > A[i] and A[i+1] > A[i]):
        if abs(A[i] - A[i - 1]) > abs(A[i] - A[i + 1]):
            sumPrice = defSumPrice - 2 * abs(A[i] - A[i + 1])
        else:
            sumPrice = defSumPrice-2*abs(A[i]-A[i-1])
    else:
        sumPrice = defSumPrice
    print(sumPrice)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        tmp_1 = 0
        tmp_2 = A[i+1]
    elif i == N-1:
        tmp_1 = A[i-1]
        tmp_2 = 0
    else:
        tmp_1 = A[i-1]
        tmp_2 = A[i+1]

    if (tmp_2 - A[i]) * (A[i] - tmp_1) >= 0:
        print(ans_def)
    elif (A[i] - tmp_2) * (tmp_2 - tmp_1) >= 0:
        print(ans_def - abs(tmp_2 - A[i]) * 2)
    else:
        print(ans_def - abs(tmp_1 - A[i]) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque
import numpy as np

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

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

def main():
    #1. make master list
    N = int(input())
    A = list(map(int, input().split()))

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

    A = np.array(A)
    
    cost = np.abs(A[1:] - A[:-1])    
    total = sum(cost)    
    #2. remove i-th componet
    for i in range(N):

        #3. output
        print(total - cost[i] - cost[i+1] + abs(A[i+2]-A[i]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Sum = 0
Ans = 0

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

for i in range(N):
    Ans = Sum
    Ans = Ans - abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1]) + abs(A[i+2] - A[i])
    print("%d" % (Ans))

Submission status: Accepted

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

s = 0
for i in a:
    s += abs(i-x)
    x = i
s += abs(0-x)

b, f = 0, 0

for i in range(len(a)):
    if i == 0:
        f, b = 0, a[i+1]
    elif i == len(a)-1:
        f, b = a[i-1], 0
    else:
        f, b = a[i-1], a[i+1]

    c = s + abs(b-f) - (abs(a[i]-f)+abs(b-a[i]))
    c_lst.append(c)

for i in c_lst:
    print(i)

Submission status: Accepted

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

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

for i in range(1, n + 1):
  #sum = total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a [i]) + abs(a[i - 1] - a[i + 1])
  sum = total - b[i - 1] - b[i] + abs(a[i - 1] - a[i + 1])

  print(sum)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import copy

def calcAbs(a, i):
	return abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]))

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, 0)
	a.insert(len(a), 0)
	#a.append(0)

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

	for i in range(1, n+2-1):
		ans = total + calcAbs(a, i) 

		print(ans)


main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

total_price=0
#No.1
negative=abs(A[0]-0)+ abs(A[1]-A[0])-abs(A[1]-(0))
total_price=full_price-negative
print(total_price)

for j in range (1,N-1):
    negative=abs(A[j]-A[j-1])+ abs(A[j+1]-A[j])-abs(A[j+1]-(A[j-1]))
    total_price=full_price-negative
    print(total_price)
    
#No.Last
negative=abs(0-A[N-1])+ abs(A[N-1]-A[N-2])-abs(0-A[N-2]) 
total_price=full_price-negative
print(total_price)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
place_count = int(input())
position_list = [0] + list(map(int, input().split()))
position_list.append(0)

all_sum = 0

for i in range(0, place_count+1):
	all_sum += abs(position_list[i+1] - position_list[i])

for x in range(1, place_count+1):
	print(all_sum - abs(position_list[x-1] - position_list[x]) - abs(position_list[x+1] - position_list[x]) + abs(position_list[x+1] - position_list[x-1]))

Submission status: Accepted

Solution code:
N = int(input())
spot = list(map(int, input().split()))
spot.insert(0, 0)  # リストの先頭と最後に0を挿入
spot.append(0)

allsum = 0
for i in range(N + 1):
    allsum = allsum + abs(spot[i] - spot[i + 1])
# print(allsum)

for i in range(1, N + 1):
    # print("%d,%d,%d" % (abs(spot[i - 1] - spot[i]), abs(spot[i] - spot[i + 1]), abs(spot[i - 1] - spot[i + 1])))
    ans = allsum - abs(spot[i - 1] - spot[i]) - abs(spot[i] - spot[i + 1]) + abs(spot[i - 1] - spot[i + 1])
    print(str(ans))

Submission status: Accepted

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

def diffWithoutNum( num):
    return B[num + 1] + B[num] - abs(A[i + 1] -A[i - 1])

for i in range( 1, N + 1):
    print( allPath - diffWithoutNum(i))

Submission status: Accepted

Solution code:
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
money=0
for i in range(N+1):
  money+=abs(list_A[i+1]-list_A[i])
for i in range(1,N+1):
  Money=money-abs(list_A[i]-list_A[i-1])-abs(list_A[i+1]-list_A[i])+abs(list_A[i+1]-list_A[i-1])
  print(Money)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]

    # See:
    # https://www.youtube.com/watch?v=WFg2yJGZ2Cw
    # https://img.atcoder.jp/arc093/editorial.pdf
    total_distance = 0
    total_cost = 0

    for i in range(spot_count + 1):
        total_distance += abs(spots[i + 1] - spots[i])

    for j in range(1, spot_count + 1):
        shortcut_cost = (abs(spots[j - 1] - spots[j]) + abs(spots[j] - spots[j + 1]))
        total_cost = total_distance + abs(spots[j - 1] - spots[j + 1]) - shortcut_cost
        print(total_cost)

Submission status: Accepted

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

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

for i in range(n):
    if i == 0:
        print(s + abs(0 - a[i + 1]) - (abs(0 - a[i]) + abs(a[i] - a[i + 1])))
    elif i == n - 1:
        print(s + abs(a[i - 1] - 0) - (abs(a[i - 1] - a[i]) + abs(a[i])))
    else:
        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:
N = int(input())
A = list(map(int,input().split()))
A = [0] + A + [0]
B  = [abs(A[i] - A[i+1]) for i  in range(len(A)-1)]
sum = sum(B)
for i in range(N):
    ans = sum - B[i] - B[i+1] + abs(A[i+2]-A[i])
    print(ans)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
x = deque(int(i) for i in input().split())
x.appendleft(0)
x.append(0)

d1=[]
d2=[]
for i in range(0,len(x)-1):
    d1.append(abs(x[i+1]-x[i]))
for i in range(0,len(x)-2):
    d2.append(abs(x[i+2]-x[i]))
d1sum=sum(d1)

for i in range(0,i+1):
    ans = d1sum + d2[i] - d1[i] -d1[i+1]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = []

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

for i in range(N):
    if i == 0:
        temp = s  - abs(a[i]) - abs(a[i+1]-a[i]) + abs(a[i+1])
    elif i < N-1:
        temp = s - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
    else:
        temp = s - abs(a[i]) - abs(a[i]-a[i-1]) + abs(a[i-1])
    ans.append(temp)
for x in range(N):
    print(ans[x])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())
A = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))

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

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

for i in range(1, N + 1):
	currentCost = totalCost
	currentCost -= abs(A[i] - A[i -1]) + abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i - 1])
	print (str(currentCost))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)

Submission status: Accepted

Solution code:
N = int(input())
a = list(int(i) for i in input().split())
A =[]
A.append(0)
A.extend(a)
A.append(0)
s = 0
for j in range(N+1):
    s += abs(A[j+1]-A[j])
for i in range(1, N+1):
    ans = s -(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1])
    print(ans)

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin:
    if line == None or line == '\n':
        break
    line = line.rstrip()
    line = line.split(" ")
    if len(line) == 1:
        N = int(line[0])
        continue
    else:
        coordinates = line

        coordinates.insert(0, 0)
        coordinates.append(0)

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

        for i in range(1, len(coordinates) - 1):
            print(total_cost - abs(int(coordinates[i]) - int(coordinates[i - 1])) - abs(int(coordinates[i]) - int(coordinates[i + 1])) + abs(int(coordinates[i + 1]) - int(coordinates[i - 1])))

Submission status: Accepted

Solution code:
import math
n = int(input())
arr = input().split(' ')
arr = [0] + [int(a) for a in arr] + [0]

cost = 0
for j in range(1, len(arr)):
	cost += math.fabs(arr[j] - arr[j - 1])

for i in range(len(arr) - 2):
	print(int(cost - math.fabs(arr[i + 1] - arr[i]) - math.fabs(arr[i + 2] - arr[i + 1]) + math.fabs(arr[i + 2] - arr[i])))

Submission status: Accepted

Solution code:
x = int(raw_input())
s = raw_input().split(" ")
s.insert(0, "0")

def cost(a, b):
 return abs(int(a)-int(b))

totalCost = cost(s[-1], s[0])
skipGain = [None] * (x+1)

costPrev = cost(s[0], s[1])
for i in range(0, x):#i=0 skipping 1st one, prev=0-1, post=1-2
 costThisOne = cost(s[i+1], s[0 if i==x-1 else i+2])
 totalCost += costPrev
 skipGain[i+1] = cost(s[i], s[0 if i==x-1 else i+2]) - costPrev - costThisOne
 costPrev = costThisOne

for i in range(1, x+1):
 print totalCost + skipGain[i]

Submission status: Accepted

Solution code:
N = int(input())
As = [0] + [int(a) for a in input().split()] + [0]

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

for i in range(1,N+1):
    if As[i-1] == As[i] or As[i] == As[i+1] or \
            (As[i-1] < As[i]) == (As[i] < As[i+1]):
        print(total)
    else:
        da = abs(As[i-1]-As[i])
        db = abs(As[i]-As[i+1])
        print(total-2*min(da,db))