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: Time Limit Exceeded

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

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

for i in range(n):
    temp = a[:]
    del temp[i]
    calc(temp)

Submission status: Time Limit Exceeded

Solution code:
from math import fabs
N=int(input())
pos=list(map(int,input().split()))

for i in range(N):
    pos_=pos.copy()
    del pos_[i]
    pos_.insert(0,0)
    pos_.insert(N+1,0)
    x=0
    for j in range(N):
        x+=fabs(pos_[j+1]-pos_[j])
    print(int(x))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    ans = 0
    now = 0
    for j, a in enumerate(A):
        if i == j:
            continue
        ans += abs(a-now)
        now = a
    print(ans + abs(now))

Submission status: Time Limit Exceeded

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

for i in range(n):
    sum = 0
    b = a.copy()
    b.pop(i)
    temp = 0
    for k in range(n-1):
        sum += abs(b[k] - temp)
        temp = b[k]
    sum += abs(temp)
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = map(int, raw_input().split())
for i in xrange(n):
    a2 = a[:i]+a[i+1:]
    s = abs(a2[0])
    for j in xrange(n-2):
        s += abs(a2[j]-a2[j+1])
    s += abs(a2[-1])
    print s

Submission status: Time Limit Exceeded

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)]
for n in range(N):
    print(sum(cost[:n]) + abs(A[n] - A[n + 2]) + sum(cost[n + 2:]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input().strip())
ais = map(int, raw_input().strip().split())

curr = [0 for _ in xrange(n)]
total = [0 for _ in xrange(n)]

for i in xrange(n):
    for j in xrange(n):
        if i == j:
            continue
        total[j] += abs(curr[j] - ais[i])
        curr[j] = ais[i]

for i in xrange(n):
    total[i] += abs(curr[i])
    print total[i]

Submission status: Time Limit Exceeded

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

for i in range(n):
    tmp = list(array)
    tmp.remove(tmp[i])
    res = 0
    ichi = 0
    for j in tmp:
        res += abs(ichi-j)
        ichi = j

    print(res+abs(ichi))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)]
for n in range(N):
    print(sum(cost[:n] + [abs(A[n] - A[n + 2])] + cost[n + 2:]))

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

for i in range(1,N+1):
	result = 0
	B = copy.deepcopy(A)
	del B[i]
	for j in range(1,N):
		result += abs(B[j]-B[j-1])
	result += abs(B[N-1])
	print(result)

Submission status: Time Limit Exceeded

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

for i in range(n):
    cnt = 0
    a_tmp = [0] + a_list[0 : i] + a_list[i + 1 : n] + [0]
    for k in range(n):
        cnt += abs(a_tmp[k] - a_tmp[k + 1])
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = []
cost = 0
now = 0
for po in A[1:]:
    cost += abs(po-now)
    now = po
cost += abs(now)
ans.append(cost)

for i in range(1,N-1):
    cost = 0
    now =  0
    for po in A[:i]+A[i+1:]:
        cost += abs(po-now)
        now = po
    cost += abs(now)
    ans.append(cost)

cost = 0
now =  0
for po in A[:N-1]:
    cost += abs(po-now)
    now = po
cost += abs(now)
ans.append(cost)


print(*ans,sep="\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    temp = []
    for j in range(len(A)):
        if j == i:
            continue
        temp.append(A[j])
        ans = 0
        pos = 0
    for j in temp:
        ans += abs(j-pos)
        pos = j
    ans += abs(temp[-1])
    print(ans)

Submission status: Time Limit Exceeded

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


for skip_num in range(N):
    sum = 0
    pos = 0
    for i in range(N):
        if i == skip_num:
            continue
        sum += abs(pos - As[i])
        pos = As[i]
    sum += abs(pos)
    print(sum)

Submission status: Accepted

Solution code:
import sys

N = int(input())

A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)

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

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

s = 0
diff_lst = []
sign_lst = []
for i in lst + [0]:
    diff = i - s
    diff_lst.append(abs(diff))
    sign_lst.append(1) if diff > 0 else sign_lst.append(-1)
    s = i

su = sum(diff_lst)
for i in range(n):
    if sign_lst[i] * sign_lst[i+1] > 0:
        print(su)
    else:
        print(su - diff_lst[i] - diff_lst[i+1] + abs(diff_lst[i] - diff_lst[i+1]))

Submission status: Accepted

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

# 0 3 5 -1  0
# 0 3 5 11 12
#cum 0 3 8 14 15
# 0   5 11 12
# 0 3    7  8
# 0 3 5    10

# (cumi+1)-(cumi-1) - (i+1 - i-1)
# 8-0 - 5-0
# 14-3 - 7-3
# 2 6 8
# 3 2 5

a.insert(0,0)
a.append(0)
def cumulative_sum(collection):
    result = [0]
    for i in range(1, len(collection)):
        item = abs(collection[i] - collection[i-1])
        result.append(result[-1] + item)
    return result
cuma = cumulative_sum(a)

lp=cuma[-1]

for i in range(n):
    gap=abs(cuma[i+2]-cuma[i])-abs(a[i+2]-a[i])
    print(lp-gap, flush=True)

Submission status: Accepted

Solution code:
n = int(input())
A = [0]
a = list(map(int, input().split()))
for a_ in a:
    A.append(a_)
s = 0
A.append(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())
N_List = [0] +list(map(int,input().split())) + [0]
N_Diff_List = []

for i in range(N+1):
    N_Diff_List.append(abs(N_List[i+1]-N_List[i]))

sumans = sum(N_Diff_List)
for i in range(N):
    ans = sumans -(N_Diff_List[i] + N_Diff_List[i+1])
    ans += abs(N_List[i+2]-N_List[i])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 16:34:00 2020

@author: liang
"""

N = int(input())
A = [0]+[int(x) for x in input().split()]+[0]
ans = 0
for i in range(N+1):
    ans += abs(A[i+1] - A[i])

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

Submission status: Accepted

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

D1.append(abs(A[0]))
D2.append(abs(A[1]))

for i in range(1,N):
  D1.append(abs(A[i]-A[i-1]))
D1.append(abs(A[N-1]))

for i in range(1,N-1):
  D2.append(abs(A[i+1]-A[i-1]))
D2.append(abs(A[N-2]))

S = sum(D1)

for i in range(N):
  print(S-D1[i]-D1[i+1]+D2[i])

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = sum(abs(A[i+1] - A[i]) for i in range(N+1))
for i in range(1, N+1):
    print(cost + 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]
cnt=0
for i in range(1,n+2):
  cnt+=abs(a[i]-a[i-1])

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

cost = abs(a[0])
for i in range(1,n):
    cost += abs(a[i]-a[i-1])
#print(cost)
cost+=abs(a[-1])
ans = [0]*n
#print(cost)
#ans[0] = cost - abs(a[1]-a[0])-abs(a[0])+abs(a[1])
an =  cost - abs(a[1]-a[0])-abs(a[0])+abs(a[1])
#ans[n] = cost - abs(a[n])
print(an)
for i in range(1,n-1):
    key = cost-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])
    #ans[i] = key
    print(key)
print(cost-abs(a[-1])+abs(a[-2])-abs(a[-1]-a[-2]))

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(len(A)-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())
s = [0] + list(map(int, input().split()))
s.append(0)
forward = []
backward = []
jump = []
for a, b, c in zip(s, s[1:], s[2:]):
    forward.append(abs(b - a))
    backward.append(abs(c - b))
    jump.append(abs(c - a))
res = sum(forward) + backward[-1]
for i in range(n):
    print(res + jump[i] - forward[i] - backward[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    total = 0
    now = 0
    for i in a:
        total += abs(now-i)
        now = i
    total += abs(i)
    a.insert(0,0)
    a.append(0)

    ans = []

    for i,k in enumerate(a[1:-1], start=1):
        # print(i,k)

        if a[i-1] <= k and k <= a[i+1] or a[i-1] >= k and  k >= a[i+1]:
            ans.append(total)
        else:
            ans.append(total - abs(k-a[i-1]) - abs(k-a[i+1]) + abs(a[i-1]-a[i+1]))

    for i in ans:
        print(i)




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)
x=0
for i in range(0,N+1):
    x+=abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(x-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.insert(0,0)
A.append(0)
x=0
for i in range(0,N+1):
    x+=abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(x-abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i+1]-A[i-1]))

Submission status: Accepted

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N=int(input())
    A=list(map(int,input().split()))
    A.append(0)
    len =0
    previous=0

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


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







if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = sum(len)
ans = sum

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

Submission status: Accepted

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

    a_lst.insert(0, 0)
    a_lst.append(0)
    lst = []
    for i in range(n + 1):
        lst.append(abs(a_lst[i + 1] - a_lst[i]))

    tmp = sum(lst)
    tmp1 = sum(lst)
    answer_lst = []
    for i in range(n):
        for j in range(2):
            tmp1 -= lst[i + j]

        tmp1 += abs(a_lst[i + 2] - a_lst[i])
        answer_lst.append(tmp1)
        tmp1 = tmp

    for i in range(n):
        print(answer_lst[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

totCost = sum(iCost)

modCost = [0]*n # cost of when i-1th connected to i+1th point
modCost[1] = abs(a[2])
for i in range(2, n-1):
    modCost[i] = abs(a[i+1]-a[i-1])

for i in range(1, n-1):
    print(totCost - iCost[i-1] - iCost[i] + modCost[i])

Submission status: Accepted

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

cost = [0] * (N + 2)
for i in range(N+1):
  cost[i] += abs(A[i+1] - A[i])
  
sum_money = sum(cost)
  
skip = [0] * N
for j in range(N):
  skip[j] += abs(A[j+2] - A[j])
  
for k in range(N):
  print(sum_money - (cost[k] + cost[k+1]) + skip[k])

Submission status: Accepted

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

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(sum_arr - diff)

Submission status: Accepted

Solution code:
N = 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: Accepted

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

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

main()

Submission status: Accepted

Solution code:
N = int(input())
lsA = [0]+list(map(int,input().split()))+[0]
sum1 = 0
for i in range(1,N+2):
    sum1 += abs(lsA[i]-lsA[i-1])
lsans = []
for i in range(1,N+1):
    if lsA[i-1] <= lsA[i] and lsA[i] <= lsA[i+1]:
        lsans.append(sum1)
    elif lsA[i-1] >= lsA[i] and lsA[i] >= lsA[i+1]:
        lsans.append(sum1)
    else:
        div = min(abs(lsA[i-1]-lsA[i]),abs(lsA[i+1]-lsA[i]))
        lsans.append(sum1-2*div)
for i in lsans:
    print(i)

Submission status: Accepted

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

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

a = [0] + a + [0]

diff = []
for i in range(1, len(a)):
    diff.append(abs(a[i-1]-a[i]))

ans = sum(diff)

# print(diff)
for i in range(1, len(diff)):
    tmp = abs(a[i+1]-a[i-1])-abs(a[i]-a[i+1])-abs(a[i-1]-a[i])
    print(ans+tmp)

Submission status: Accepted

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

def change(i):
    global A
    return -abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])

for i in range(1,N+1):
    print(cost+change(i))

Submission status: Accepted

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

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

def herasu(i):
    ans=total-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])
    return ans


for i in range(1,n+1):
    print(herasu(i))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A = [0]+A+[0]
cum = [0]*(N+2)
for i in range(1, N+2):
    cum[i] = cum[i-1] + abs(A[i]-A[i-1])
for i in range(1, N+1):
    print(cum[N+1]-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 = [0]+list(map(int, input().split()))+[0]
res = 0
for i in range(1,N+2):
    res += abs(A[i]-A[i-1])
for i in range(1,N+1):
    print(res - 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 = [0] + A  #単純にリスト横につなげる
A.append(0)

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

for i in range(1,N+1):  #iが取りやめた奴
    dam = ini
    dam -= cost[i-1]
    dam -= cost[i]
    dam += abs(A[i+1] - A[i-1])
    print(dam)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def cost(i, j=1):
    return abs(a[i] - a[i+j])

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

c = sum([cost(i) for i in range(n+1)])
for i in range(1, n+1):
    print(c - cost(i-1) - cost(i) + cost(i-1, 2))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

s = sum(d)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

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):
  a=A[i-1]
  b=A[i]
  c=A[i+1]
  if b<a and b<c:
    ans=s-abs(b-min(a,c))*2
  elif b>a and b>c:
    ans=s-abs(b-max(a,c))*2
  else:
    ans=s
  print(ans)

Submission status: Accepted

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

sum = 0

for i in range(N+1):
  sum += abs(B[i+1] - B[i])
  
for i in range(N):
  #立ち寄る
  x = abs(B[i+1] - B[i]) + abs(B[i+2] - B[i+1])
  #立ち寄らない
  y = abs(B[i+2] - B[i])
  print(sum - x + y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

lc = []
for i in range(n):
    if i==0:
        c = abs( a[i] )
    else:
        c = abs( a[i] - a[i-1] )
    lc.append(c)
# print(lc)
s = sum(lc)

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

Submission status: Accepted

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

hon = sum(b)

for i in range(n):
    print(hon-b[i]-b[i+1]+c[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
tnp = 0
for i in range(1,n+2):
    tnp += abs(a[i]-a[i-1])
for i in range(n):
    ans = tnp - 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 copy
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):
    ans = copy.deepcopy(cost)
    if a[i-1] <= a[i] and a[i+1] <= a[i]:
        ans -= 2*abs(a[i]-max(a[i-1], a[i+1]))
    elif a[i-1] >= a[i] and a[i+1] >= a[i]:
        ans -= 2*abs(a[i]-min(a[i-1], a[i+1]))
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
B = [0] * (N+1)
total = 0
for i in range(N+1):
    B[i] = A[i+1]-A[i]
    total += abs(B[i])
for i in range(N):
    print(total - (abs(B[i])+abs(B[i+1])) + abs(B[i]+B[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(len(a)-1):
    s += abs(a[i]-a[i+1])
for h in range(1,n+1):
    t = abs(a[h+1]-a[h-1])-abs(a[h]-a[h-1])-abs(a[h+1]-a[h])
    print(s+t)

Submission status: Accepted

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

A = [0] + A + [0]
sum_all = 0

for i, a in enumerate(A[1:N + 2], start=1):
    sum_all += abs(a - A[i - 1])

for i, a in enumerate(A[1:N + 1], start=1):
    print(sum_all - abs(a - A[i - 1]) - abs(a - A[i + 1]) + abs(A[i + 1] - A[i - 1]))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
    d = abs(c[i+1]-c[i])+ abs(c[i+2]-c[i+1])
    e = abs(c[i+2]-c[i])
    print(ans - d + e)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

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

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

Submission status: Accepted

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

res = [0]*(n+1)
for i in range(n+1):
  res[i] = abs(a[i]-a[i+1])
  
t = sum(res)
for i in range(1, n+1):
  ans = t - (res[i-1]+res[i]) + abs(a[i-1]-a[i+1])
  print(ans)

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    total = sum([abs(A[i + 1] - A[i]) for i in range(n - 1)])
    for i in range(n):
        if i == 0:
            start = abs(A[1])
            end = abs(A[-1])
            print(total - abs(A[1] - A[0]) + start + end)
        elif i == n - 1:
            start = abs(A[0])
            end = abs(A[-2])
            print(total - abs(A[-2] - A[-1]) + start + end)
        else:
            start = abs(A[0])
            end = abs(A[-1])
            print(total - abs(A[i - 1] - A[i]) -
                  abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1])
                  + start + end)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

dist=[]

for i in range(len(a)-1):
  dist.append(abs(a[i+1]-a[i]))
  
xxx=sum(dist)

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