Problem:


Score : 300 points

Problem Statement

There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.

You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.

However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i.
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.

For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Constraints

2 \leq N \leq 10^5

-5000 \leq A_i \leq 5000 (1 \leq i \leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N lines.
In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled.

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively.
For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:

For i = 1, the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.

For i = 2, the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.

For i = 3, the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

6
-679 -2409 -3258 3095 -3291 -4462

Sample Output 3

21630
21630
19932
8924
21630
19288



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    C[i] = C[i+1] + abs(A[i]-A[i+1])
for i in range(1, N+1):
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
# dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    # dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    # dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
# dump(A, B, C)
for i in range(1, N+1):
    # dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

D = []

for n in range(N+1):
    D.append(abs(A[n]-A[n+1]))

tot = sum(D)

for n in range(N):
    ans = tot - abs(D[n]+D[n+1]) + abs(A[n]-A[n+2])
    print(ans)

Submission status: Accepted

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

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

for i in range(1,N+1):
    Si=Sum+abs(As[i-1]-As[i+1])-(abs(As[i-1]-As[i])+abs(As[i]-As[i+1]))
    print(Si)

Submission status: Accepted

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

for i in range(n):
    B[i]=abs(A[i]-A[i+2])
for i in range(n+1):
    C[i]=abs(A[i]-A[i+1])
sumC = sum(C)
for i in range(n):
    print(sumC+B[i]-C[i]-C[i+1])

Submission status: Accepted

Solution code:
def examC():
    N = I()
    A = LI()
    cost1 = [0]*(N+1); cost2 = [0]*(N+1)
    A.append(0)
    for i in range(N+1):
        cost1[i] = abs(A[i]-A[i-1])
        cost2[i] = abs(A[i]-A[i-2])
    ans = []
    cost = sum(cost1)
    for i in range(N):
        cur = cost - cost1[i] - cost1[i+1] + cost2[i+1]
        ans.append(cur)
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

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

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

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

for i in range(1, len(A)-1):
    if A[i-1] < A[i] < A[i+1] or A[i+1] < A[i] < A[i-1]:
        print(sum_dis)
    else:
        print(sum_dis - (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 = [0] + A
A.append(0)

tot = 0
s = 0
for a in A:
    tot += abs(a-s)
    s = a

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

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

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

Submission status: Accepted

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

def cost(x1, x2):
    return abs(x1 - x2)

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

def diff_cost(A, i):
    return cost(A[i-1], A[i]) + cost(A[i], A[i+1]) - cost(A[i-1], A[i+1])

for i in range(1,N+1):
    print(cost_sum - diff_cost(A,i))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import math
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0
lin = li[:]
lin = [0] + lin + [0]
for i in range(1,len(lin)):
    point += abs(lin[i]-lin[i-1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
array = list(map(int,input().split()))
expense = [0] * (N+1)
expense[0] = abs(array[0])
for i in range(N-1):
    expense[i+1] = abs(array[i+1] - array[i])
expense[N] = abs(array[N-1])
total = sum(expense)
for i in range(N):
    tmp = total
    tmp -= expense[i]+expense[i+1]
    tmp += (abs(array[i+1] - array[i-1]) if i != 0 else abs(array[i+1])) if i != N-1 else abs(array[N-2])
    print(tmp)

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(x) for x in input().split())
judge = [0] + a + [0]
key = [0]*n
ans = 0

for i in range(n):
    x, y, z = [judge[i], judge[i+1], judge[i+2]]
    key_list = [x, y, z]
    if max(key_list) == y or min(key_list) == y:
        key[i] = 2 * min(abs(x-y), abs(y-z))
        ans = ans + abs(y-x)
    else:
        ans = ans + abs(y-x)
ans += abs(a[-1])

for i in range(n):
    print(ans-key[i])

Submission status: Accepted

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

for i in range(1,N+1):
    print(usualsum+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 = [0] * (N + 2)
for i, a in enumerate(map(int, input().split())):
    A[i + 1] = a
costs = [0] * (N + 2)
for i in range(1, N + 2):
    costs[i] = abs(A[i] - A[i - 1])
cost = sum(costs)

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

Submission status: Accepted

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

sum_price = 0
list_diff = []
pre = abs(list_a[1] - list_a[0])
for i in range(1, n+1):
  sum_price += pre
  temp = abs(list_a[i+1] - list_a[i])
  list_diff.append(abs(list_a[i+1] - list_a[i-1]) - (temp + pre))
  pre = temp
sum_price += pre

for one_diff in list_diff:
  print(sum_price + one_diff)

Submission status: Accepted

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

a.append(0)
a.insert(0, 0)
s = sum([abs(a[i+1]-a[i]) for i in range(n+1)])

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input().strip())
A = [int(x) for x in input().strip().split()] + [0]
totalcost = 0
a_ = 0
for a in A:
    totalcost += abs(a - a_)
    a_ = a

C = [totalcost] * N
a_ = 0
for i, a in enumerate(A):
    if i == len(A)-1:
        break
    C[i] += -abs(a - a_) -abs(A[i+1] - a) + abs(A[i+1] - a_)
    a_ = a

for c in C:
    print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [abs(a[0])]
for i in range(n-1):
    b.append(abs(a[i+1]-a[i]))
b.append(abs(a[-1]))
#print(b)
sumdis = sum(b)
a.append(0)
for i in range(n):
    print(sumdis + 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(lambda x: int(x), input().split(' ')))
A.append(0)
A.insert(0, 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])
    diff -= abs(A[i] - A[i-1]) + abs(A[i+1] - A[i])
    print(S + diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
b=sum(abs(i-j) for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):
    if i<=j<=k or i>=j>=k:
        print(b)
    elif min(i,j,k)==j:
        print(b-2*(min(i,k)-j))
    else:
        print(b-2*(j-max(i,k)))

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 00:57:57(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n = int(sys.stdin.readline().rstrip())
    a = [0] + [int(x) for x in sys.stdin.readline().split()] + [0]
    way = 0
    for i in range(n+1):
        way += abs(a[i+1] - a[i])
    
    for i in range(1, n+1):
        pre, cur, nex = a[i-1], a[i], a[i+1]
        if pre <= cur <= nex or pre >= cur >= nex:
            ans = way
        elif pre <= nex <= cur or pre >= nex >= cur:
            ans = way - abs(nex - cur) * 2
        elif cur <= pre <= nex or cur >= pre >= nex:
            ans = way - abs(cur - pre) * 2
        
        print(ans)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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] - 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 = [0]+[int(x) for x in input().split()]+[0]
T = 0
for i in range(N+1):
  T += abs(A[i]-A[i+1])
for j in range(1,N+1):
  print(T+abs(A[j+1]-A[j-1])-abs(A[j+1]-A[j])-abs(A[j]-A[j-1]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    d = 0
    for a0, a1 in zip(aa, aa[1:]):
        d += abs(a0 - a1)
    for i in range(1, 1 + n):
        print(d - abs(aa[i - 1] - aa[i]) - abs(aa[i + 1] - aa[i]) + abs(aa[i - 1] - aa[i + 1]))

main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.append(0)
S=0
a=[]
c=[]
f=0

for n in range(N):
    S+=abs(A[n]-f)
    a.append(abs(A[n]-f))
    c.append(abs(A[n+1]-f))
    f=A[n]

S+=abs(A[n])
a.append(abs(A[n]))

for n in range(N):
    print(S-a[n]-a[n+1]+c[n])

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
s=abs(l[0])
for i in range(1,n):
    s+=abs(l[i]-l[i-1])
s+=abs(l[-1])
#print(s)
for i in range(n):
    if i==0: 
        loss=abs(l[1]-l[0]) 
        loss+=abs(l[0])
        gain=abs(l[1])
        print(s-loss+gain)
    elif i==n-1:
        loss=abs(l[-1])
        loss+=abs(l[-1]-l[-2])
        gain=abs(l[-2])
        print(s-loss+gain)
    else: 
        loss=abs(l[i]-l[i-1])
        loss+=abs(l[i]-l[i+1])
        gain=abs(l[i-1]-l[i+1])
        print(s-loss+gain)

Submission status: Accepted

Solution code:

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

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

# iは使わなくなるAの添字
for i in range(1, N+1):
    minus = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i])
    plus = abs(A[i+1] - A[i-1])
    x = full - minus + plus
    print(x)

Submission status: Accepted

Solution code:

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

# NOTE: 間に合わない
# for i in range(N):
#     ans = 0
#     now = 0
#     for j, a in enumerate(A):
#         if i == j:
#             continue
#         ans += abs(now - a)
#         now = a
#     ans += abs(0 - now)
#     print(ans)

HEAD = []
TAIL = []
now = 0
tmp = 0
for ai in A + [0]:
    tmp += abs(ai - now)
    now = ai
    HEAD.append(tmp)

now = 0
tmp = 0
for ai in A[::-1] + [0]:
    tmp += abs(ai - now)
    now = ai
    TAIL.append(tmp)

# print(HEAD)
# print(TAIL)

ans = 0
for i in range(N):
    if i == 0:
        ans = abs(A[1] - 0) + TAIL[N-2]
    elif i == N - 1:
        ans = abs(A[N-2] - 0) + HEAD[N-2]
    else:
        # print(HEAD[i-1], TAIL[N-i-2], abs(A[i+1] - A[i-1]), i, N-i-2)
        ans = HEAD[i-1] + TAIL[N-i-2] + abs(A[i+1] - A[i-1])
    print(ans)

Submission status: Accepted

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

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(1, len(A)):
	total += abs(A[i] - A[i - 1])


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools

    n = int(input())
    as_ = [0] + list(map(int, input().split())) + [0]
    sum_cost = functools.reduce(lambda x, i: x + abs(as_[i] - as_[i - 1]), range(1, n + 2), 0)
    # print(sum_cost)
    for i in range(1, n + 1):
        # print(abs(as_[i] - as_[i - 1]) - abs(as_[i + 1] - as_[i]) + abs(as_[i + 1] - as_[i - 1]))
        print(sum_cost - abs(as_[i] - as_[i - 1]) - abs(as_[i + 1] - as_[i]) + abs(as_[i + 1] - as_[i - 1]))

    

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)

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

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

Submission status: Accepted

Solution code:
import sys
def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    sc = 0
    for i in range(n + 1):
        if i == 0:
            sc += abs(0 - a[i])
        elif i == n:
            sc += abs(0 - a[i-1])
        else:
            sc += abs(a[i] - a[i-1])
    for i in range(n):
        if i == 0:
            print(sc + abs(a[i+1] - 0) - abs(a[i] - 0) - abs(a[i+1] - a[i]))
        elif i == n - 1:
            print(sc + abs(a[i-1] - 0) - abs(a[i] - 0) - abs(a[i] - a[i-1]))
        else:
            print(sc + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i+1] - a[i]))


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

total = abs(a[0])

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

total += abs(a[-1])

#print('total: ' + str(total))

for i in range(n):
    if i == 0:
        org = abs(a[i]) + abs(a[i] - a[i+1])
        skip = abs(a[i+1])
        print(total - org + skip)
        continue
    if i == n - 1:
        org = abs(a[i-1] - a[i]) + abs(a[i])
        skip = abs(a[i-1])
        print(total - org + skip)
        continue

    org = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])
    skip = abs(a[i-1] - a[i+1])
    print(total - org + skip)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
aa = [0]+a+[0]
allsum = sum([abs(aa[index+1]-aa[index]) for index in range(n+1)])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printmultiplerow(a):
    for i in a:
        print(i)
def printrow(a):
    for i in range(len(a)-1):
        print(a[i],end = " ")
    print(a[-1])

n = ip()
a = [0]
a.extend(iprow())
a.append(0)
sub = []
jsub = []
n+=2
for i in range(n-1):
    sub.append(abs(a[i+1]-a[i]))
for i in range(n-2):
    jsub.append(abs(a[i+2]-a[i]))
s = sum(sub)
s-=sub[0]
for i in range(n-2):
    s-=sub[i+1]
    print(s+jsub[i])
    s+=sub[i]

Submission status: Accepted

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


if __name__ == "__main__":
    test()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=[0]
A=A+list(map(int,input().split()))
A.append(0)
A.append(0)
dis=[]
sum_dis=[0]
skip=[]
sum_skip=[0]

for i in range(N+1):
    dis.append(abs(A[i+1]-A[i]))
    sum_dis.append(dis[-1]+sum_dis[i])
    skip.append(abs(A[i+2]-A[i]))

for i in range(len(sum_dis)-2):
    print(skip[i]+sum_dis[len(sum_dis)-1]-sum_dis[i+2]+sum_dis[i])
#なぜかめちゃくちゃ苦労した
#台風19号記念パピコ

Submission status: Accepted

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

A = [0] + A + [0]

n_full_trip_cost = 0
for i in range(1,N+2):
    n_full_trip_cost += abs(A[i] - A[i-1])
    
# スポットA[i]への訪問を取りやめたとき、コストが変化するのはその前後だけ
for i in range(1,N+1):
    ans = n_full_trip_cost
    ans -= abs(A[i] - A[i-1]) + abs(A[i+1] - A[i])
    ans += abs(A[i+1] - A[i-1]) 
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [0] * (N + 2)
for k in range(N):
    B[k+1] = A[k]
sumofdis = 0
for i in range(N+1):
    sumofdis += abs(B[i+1]-B[i])
for j in range(1, N+1):
    if B[j - 1] <= B[j] <= B[j + 1] or B[j - 1] >= B[j] >= B[j + 1]:
        print(sumofdis)
    elif B[j] <= B[j-1] <= B[j + 1] or B[j] >= B[j-1] >= B[j + 1]:
        print(sumofdis-2*abs(B[j-1]-B[j]))
    else:
        print(sumofdis-2*abs(B[j+1]-B[j]))
# print(B)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

for i in range(N):
	if A[i]<=A[i+1]<=A[i+2] or A[i+2]<=A[i+1]<=A[i]:  # 消すところが真ん中
		print(ans) 
	else:
		print(ans-2*
			min(
				abs(A[i+2]-A[i+1]), 
				abs(A[i+1]-A[i])
				)
			)