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())
visit_list = list(map(int, input().split()))
visit_list.append(0)
visit_list.insert(0, 0)

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

for i in range(1,N+1):
    diff = - abs(visit_list[i] - visit_list[i-1]) - abs(visit_list[i+1] - visit_list[i]) +\
        abs(visit_list[i+1]-visit_list[i-1])
    new_visit_cost = total_visit_cost + diff
    print(new_visit_cost)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    A.append(0)
    # print(A)
    sum_A = 0
    for i in range(N + 1):
        sum_A += abs(A[i + 1] - A[i])

    # print(sum_A)

    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(sum_A)
            continue

        print(sum_A - (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()))
X=[]
X.append(abs(A[0]))
for I in range(N-1):
	X.append(abs(A[I]-A[I+1]))
X.append(abs(A[N-1]))
SUM=sum(X)
for K in range(N):
	if K==0:
		print(SUM+abs(A[K+1])-X[0]-X[1])
	elif K==(N-1):
		print(SUM+abs(A[K-1])-X[N-1]-X[N])
	else:
		print(SUM+abs(A[K-1]-A[K+1])-X[K]-X[K+1])

Submission status: Accepted

Solution code:
N = int(input())
A = [0]

Astr = input().split()

for i in Astr:
    A.append(int(i))

A.append(0)

ans = 0
pos = 0
for i in range(len(A)):
    if i == 0:
        continue
    ans += abs(A[i]-pos)
    pos = A[i]

for i in range(len(A)):
    if i == 0 or i == len(A)-1:
        continue
    print(ans-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=[int(x) for x in input().split()]
ans=abs(A[-1])
A=[0]+A+[0]
diff=[0 for x in range(N)]
for i in range(1,N+1):
  dif=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1])
  ans+=abs(A[i]-A[i-1])
  diff[i-1]=dif

for i in range(N):
  print(ans-diff[i])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x,b = [0]+a+[0],0
for i in range(1,n+2):
  b += abs(x[i]-x[i-1])
for i in range(n):
	if x[i]<=x[i+1]<=x[i+2] or x[i]>=x[i+1]>=x[i+2]: print(b)
	else: print(b-(abs(x[i]-x[i+1])+abs(x[i+2]-x[i+1]))+abs(x[i+2]-x[i]))

Submission status: Accepted

Solution code:
N = int(input())
root = list(map(int,input().split()))
root.append(0)
total = [0]*(N+2)
total[0] = abs(root[0])
for i in range(1,N+1):
    total[i] += abs(root[i]-root[i-1])
sumN = sum(total)
for j in range(N):
    tmp = sumN - (total[j] + total[j+1]) + abs(root[j+1] - root[j-1])
    print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
start = 0
end = sum(cost[2:])
for n in range(N):
    print(start + abs(A[n] - A[n + 2]) + end)
    if n != N - 1:
        start += cost[n]
        end -= cost[n + 2]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a1 = list(map(int,input().split()))
ai = [0]
ai.extend(a1)
ai.append(0)
summ = 0;
array = []
#print (ai)

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

for i in range(N):
	array.append(summ);

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

for i in range(N):
	print (array[i])

Submission status: Accepted

Solution code:
N = int(input())
xlist = list(map(int,input().split()))
xlist = [0]+xlist+[0]
div = []
n = len(xlist)-1
for i in range(n):
    div.append(abs(xlist[i+1]-xlist[i]))
al = sum(div)
for i in range(n-1):
    print(al-div[i]-div[i+1]+abs(xlist[i+2]-xlist[i]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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


for j in range(N):
    if j == 0:
        x = abs(abs(A[j]-0)+abs(A[j+1]-A[j])-abs(A[j+1]-0))
    elif j < N-1:
        x = abs(abs(A[j]-A[j-1])+abs(A[j+1]-A[j])-abs(A[j+1]-A[j-1]))
    else:
        x = abs(abs(A[j]-A[j-1])+abs(0-A[j])-abs(0-A[j-1]))
    print(z-x)

Submission status: Accepted

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

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    A.append(0)
    # 本来のコスト計算
    honrai_cost = 0
    for i in range(N+1):
        honrai_cost += abs(A[i]-A[i+1])
    # iを訪れるのをやめたときのコストを計算して出力
    for i in range(1, N+1):
        minus_cost = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])
        plus_cost  = abs(A[i-1] - A[i+1])
        print(honrai_cost - minus_cost + plus_cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
s = input().split(" ")
route = [int(i) for i in s]

price_of_route = []
for i in range(N + 1 ) :
    if i == 0 : 
        price_of_route.append( abs(route[i] - 0) )
    elif i == N : 
        price_of_route.append( abs(route[i-1] - 0) )
    else:
        price_of_route.append( abs(route[i] - route[i-1]) )

X = sum(price_of_route)

for i in range(N) : 
    if i == 0 :
        rst = X - price_of_route[0] - price_of_route[1] + abs(route[1] - 0) 
    elif i == N-1 : 
        rst = X - price_of_route[len(price_of_route) - 1] - price_of_route[len(price_of_route) - 2] + abs(route[N - 2] - 0) 
    else : 
        rst = X - price_of_route[i] - price_of_route[i + 1]  + abs(route[i + 1 ] - route[i-1]) 
        
    print(rst)

Submission status: Accepted

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

Submission status: Accepted

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

all_price = 0
pre1 = 0
pre2 = 0
B = []

for ai in A:
    all_price += abs(pre1 - ai)
    B += [abs(ai - pre2) - abs(pre1 - pre2) - abs(ai - pre1)]
    pre2, pre1 = pre1, ai

all_price += abs(pre1 - 0)
B += [abs(0 - pre2) - abs(pre1 - pre2) - abs(0 - pre1)]
B = B[1:]

for bi in B:
    print(all_price + bi)

Submission status: Accepted

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    N = int(read_func().strip().split()[0])
    input_raw = read_func().strip().split()
    
    A = [0]
    for i in range(N):
        A.append(int(input_raw[i]))
    A.append(0)

    D = {}
    cost_sum = 0
    for i in range(N + 1):
        cost = abs(A[i] - A[i + 1])
        D[(i, i+1)] = cost
        cost_sum += cost

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n=int(input())
a=list(map(int,input().split()))
s=0
now=0
for i in range(n):
    s+=abs(a[i]-now)
    now=a[i]
s+=abs(now)
a.insert(0,0)
a.append(0)
for i in range(1,n+1):
    mon=s
    mon-=(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]))
    mon+=abs(a[i+1]-a[i-1])
    print(mon)

Submission status: Accepted

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

A = {}

sumup = abs(Ai[0])

count = 0
while count < len(Ai)-1:
    A[(count,count+1)]=abs(Ai[count]-Ai[count+1])
    sumup += A[(count,count+1)]
    count += 1

A[(count,0)]=abs(Ai[count])
sumup += abs(Ai[-1])

temp = sumup - abs(Ai[0]) - A[(0,1)] + abs(Ai[1])
print(temp)

count = 1
while count < len(A)-1:
    temp = sumup - A[(count,count+1)]-A[(count-1,count)]+abs(Ai[count+1]-Ai[count-1])
    print(temp)
    count+=1

temp = sumup - A[(count,0)]-A[(count-1,count)]+abs(Ai[count-1])
print(temp)

Submission status: Accepted

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

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

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

  print(fee_sum + diff)

Submission status: Accepted

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

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

for i in range(n):
    before_p = a[i - 1] if i != 0 else 0
    next_p = a[i + 1] if i != n - 1 else 0


    loss = abs(a[i] - before_p) + abs(next_p - a[i])
    add = abs(next_p - before_p)
    ans = money - loss + add
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
point = [0]
price = 0
point += list(map(int,input().split()))
point.append(0)
for j in range(len(point)):
  price += abs(point[j-1] - point[j])
for k in range(1,len(point)-1):
  pp = price - abs(point[k-1]-point[k]) - abs(point[k]-point[k+1]) + abs(point[k-1]-point[k+1])
  print(pp)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.insert(0,0)
a.append(0)

def weight(i,j):
    global a
    return abs(a[i]-a[j])


nomiss = 0

for i in range(len(a)-1):
    nomiss+=weight(i,i+1)

def course(miss):
    skipDist = weight(miss-1,miss+1)
    curDist = weight(miss,miss+1)+weight(miss,miss-1)
    return (nomiss-curDist)+skipDist

for i in range(1,len(a)-1):
    print(course(i))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

res = original_price + abs(A[1]) - abs(A[0]) - abs(A[1]-A[0])
print(res)

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

res = original_price + abs(-A[N-2]) - abs(A[N-1]-A[N-2]) - abs(-A[N-1])
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1,n+1):
	if i != n:
		print(all - (abs(a[i+1]-a[i]) + abs(a[i] - a[i-1])) + abs(a[i+1]-a[i-1]) + abs(a[n]))
	else:
		print(all - abs(a[i]-a[i-1]) + abs(a[n-1]))

Submission status: Accepted

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

sum = 0
pos = 0
for i in range(1, N + 2):
    sum += abs(pos - As[i])
    pos = As[i]

for i in range(1, N + 1):
    skip_pos = As[i]
    pre_pos = As[i - 1]
    post_pos = As[i + 1]

    if (pre_pos - skip_pos) * (post_pos - skip_pos) <= 0:
        print(sum)
    else:
        print(sum - abs(pre_pos - skip_pos) - abs(post_pos - skip_pos) + abs(pre_pos - post_pos))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for k in range(n):
    if lis[k+2]>lis[k+1] and lis[k+1]>lis[k]:
        print(cou)
    elif lis[k+2]<=lis[k+1] and lis[k+1]<=lis[k]:
        print(cou)
    else:
        print(cou-(abs(lis[k+2]-lis[k+1])+abs(lis[k+1]-lis[k])-abs(lis[k+2]-lis[k])))

Submission status: Accepted

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

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

for i in range(N):
    if i==0:
        prev = 0
    else:
        prev = A[i-1]
    if i==N-1:
        next = 0
    else:
        next = A[i+1]

    print(S-abs(A[i]-prev)-abs(A[i]-next)+abs(prev-next))

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]-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=[0]
B=map(int,input().split())
for i in B:
  A.append(i)
A.append(0)
A2=[]
total=0
for i in range(len(A)-1):
  A2.append(abs(A[i]-A[i+1]))
  total+=A2[i]
for i in range(N):
  i+=1
  print(total-A2[i-1]-A2[i]+abs(A[i-1]-A[i+1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
a.append(0)
a.insert(0, 0)
s = [abs(j - i) for i, j in zip(a, a[1:])]
base = sum(s)
for i in range(1, n + 1):
    if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
        print(base)
    elif max(a[i - 1], a[i + 1]) < a[i]:
        print(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1])))
    else:
        print(base - 2 * abs(a[i] - min(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) #len(a)==n+2
n=len(a)
tot=0
for i in range(n-1):
    tot+=abs(a[i]-a[i+1])
tot2=0
for i in range(1,n-1):
    tot2+=abs(a[i]-a[i-1])+abs(a[i]-a[i+1])-abs(a[i-1]-a[i+1])
    print(tot-tot2)
    tot2=0

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def calc(N, A, i):
    x = 0
    r = 0
    for j, a in enumerate(A):
        if j == i:
            continue
        r += abs(x - a)
        x = a
    r += abs(x)
    return r

def calc0(N, A):
    x = 0
    r = 0
    for a in A:
        r += abs(x - a)
        x = a
    return r

def calc1(N, A, ra, i):
    x0 = A[i - 1]
    x1 = A[i]
    x2 = A[i + 1]
    return ra - abs(x0 - x1) - abs(x1 - x2) + abs(x0 - x2)

#N = 1000
#A = list(range(N))

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

ra = calc0(N, A)

for i in range(N):
    print(calc1(N, A, ra, i))

Submission status: Accepted

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

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

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

print(All - (abs(A[-1])+abs(A[-1]-A[-2])) + abs(A[-2]))

Submission status: Accepted

Solution code:
n = int(input())
data = list(map(int, input().split(" ")))
data.insert(0,0)
data.append(0)
allans = 0
for i in range(0, len(data)-1):
    allans += abs(data[i+1]-data[i])
for i in range(1, len(data)-1):
    temp=abs(data[i]-data[i-1])
    temp2=abs(data[i+1]-data[i])
    temp3=abs(data[i+1]-data[i-1])
    print(allans-temp-temp2+temp3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

a.append(0)

def all_path(a):
    res = 0
    now = 0
    for p in a:
        res += abs(now - p)
        now = p
    return res

def remove(a, i):
    if i == 0:
        prev = 0
    else:
        prev = a[i - 1]
    post = a[i + 1]
    now = a[i]
    orig = abs(now - prev) + abs(now - post)
    skip = abs(prev - post)
    return orig - skip

ap = all_path(a)

for i in range(n):
    print(ap - remove(a, i))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans=0
x=0

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

for i in range(1,len(a)-1):
  pin=ans
  if a[i-1]<=a[i]<=a[i+1] or a[i-1]>=a[i]>=a[i+1]:
      print(pin)

  else:
      pin-=abs(a[i]-a[i-1])
      pin-=abs(a[i+1]-a[i])
      pin+-abs(a[i+2]-a[i])
  
      print(pin)

Submission status: Runtime Error

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

d_1 = []
for i in range(1, n+2):
  d_1.append(abs(a[i]-a[i-1]))
d_2 = [0]
for i in range(1, n+1):
  d_2.append(abs(a[i+1]-a[i-1]))

s_d = sum(d_1)
for i in range(1, n+1):
  print(s_d - d_1[i] - d_1[i+1] + d_2[i])

Submission status: Runtime Error

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

d_1 = []
for i in range(1, n+2):
  d_1.append(abs(a[i]-a[i-1]))
d_2 = []
for i in range(1, n+1):
  d_2.append(abs(a[i+1]-a[i-1]))

s_d = sum(d_1)
for i in range(1, n+1):
  print(s_d - d_1[i] - d_1[i+1] + d_2[i])

Submission status: Runtime Error

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


for i in range(n):
    delete=A[i]
    A.pop(i)
    cost=0
    for j in range(n-1):
        if j==0:
            cost+=abs(A[j])
        elif j==n-2:
            cost+=abs(A[j]-A[j-1])+abs(A[j])
        else:
            cost+=abs(A[j]-A[j-1])
    
    print(cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


input()
points = (0, *map(int, input().split(' ')), 0)

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

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

Submission status: Runtime Error

Solution code:
import copy

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

a = [0] + a + [0]

for i in range(n):
  my_sum = 0
  l = copy.copy(a)
  del l[i+1]
  for j in range(n):
    my_sum += abs(l[j] - l[j+1])
   print(my_sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
  del a[i]
  print(2*max((max(a),0))+2*abs(min(min(a),0)))

Submission status: Runtime Error

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

tmp = a[0]

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

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

Submission status: Runtime Error

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

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

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def resolve():
    N,M=map(int,input().split())
    if N==1 or M==1:
        print(N*M-2)
    else:
        print((N-2)*(M-2))

resolve()

Submission status: Runtime Error

Solution code:
import sys
read_=sys.stdin.buffer.readline

N=int(input())
A=[0]
a=list(map(int,read_().split()))
a.append(0)
A.extend(a)

res=0

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

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

Submission status: Runtime Error

Solution code:
'''
Created on 2020/02/24

@author: fanta
'''
N = int(input())
X = [int(x) for x in input().split()]
X.insert(0,0)
X.append(0)

for n in range(N+1):
    sum += abs(X[n] - X[n+1])


for n in range(N):
    l = abs(X[n] - X[n+1])
    r = abs(X[n+1] - X[n+2])

    if X[n] < X[n+1] and X[n+1] < X[n+2]:
        print(sum)
    elif X[n] > X[n+1] and X[n+1] > X[n+2]:
        print(sum)

    elif l < r:
        sep = 2*abs(X[n] - X[n+1])
        print(sum - sep)
    else:
        sep = 2*abs(X[n+2] - X[n+1])
        print(sum - sep)

Submission status: Runtime Error

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+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int x[MAX];
int acs(const void *a, const void *b) { 
  return x[*(int*)a] - x[*(int*)b];
} /* 1,2,3,4.. */

int main(void) {
  int n;
  scanf("%d", &n);
  rep(i, 0, n) scanf("%d", &x[i]);

  int idx[MAX]; 
  rep(i, 0, n) idx[i] = i;
  qsort(idx, n, sizeof(int), acs);

  int ans[MAX];
  ans[idx[0]] = x[idx[n-1]] - min(0, x[idx[1]]);
  rep(i, 1, n-1) {
    ans[idx[i]] = x[idx[n-1]] - min(0, x[idx[0]]);
  }
  ans[idx[n-1]] = x[idx[n-2]] - min(0, x[idx[0]]);
  rep(i, 0, n) printf("%d\n", 2 * ans[i]);
  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())

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

list = [0] + list + [0]

total = 0

# まずはすべての地点を経由する場合(最大値)にどれくらいコストがかかるのか計算する
for i in range(n+1):
    total += abs(list[i + 1] - list[i])

# 最大値から地点i-1から地点iまでの距離、地点iから地点i+1までの距離を引き、地点i-1から地点i+1までの距離を足してあげる
for i in range(1, n+1):
    print(total - abs(list[i-1] - list[i]) - abs(list[i] - list[i+1]) + abs(list[i-1] + list[i+1]))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[0]
a.append(map(int,input().split()))
a.append(0)
s=abs(a[0])+abs(a[n-1])
for i in range(n-1):
  s+=abs(a[i]-a[i+1])
for i in range(1,n):
  if min(a[i+1],a[i-1])<=a[i]<=max(a[i-1],a[i+1]):
    print(s)
  elif a[i]<=min(a[i-1],a[i+1])<=max(a[i-1],a[i+1]):
    print(s-2*abs(a[i]-min(a[i+1],a[i-1])))
  else:
    print(s-2*abs(max(a[i-1],a[i+1])-a[i]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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