Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

2 \leq N \leq 10^5

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

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

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

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

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

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

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

Sample Output 3

21630
21630
19932
8924
21630
19288



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Accepted

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

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

d1 = []
d2 = []
for i in range(1,N+2):
    if i != 1:
        d2.append(abs(A[i]-A[i-2]))
    d1.append(abs(A[i]-A[i-1]))
d1_total = sum(d1)

for i in range(N):
    print(d1_total-d1[i]-d1[i+1]+d2[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
original = 0
for i in range(N+1):
    original += 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(original)
    else:
        print(original - 2*min(abs(A[i]-A[i+1]), abs(A[i]-A[i-1])))

Submission status: Accepted

Solution code:
n = int(input())
A = [0] + [int(i) for i in input().split()] + [0]
amt = 0

for i in range(n + 1):
    amt += abs(A[i] - A[i + 1])
    
for i in range(1, n + 1):
     print(amt - 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 = []
A.append(0)
B = [int(i) for i in input().split()]
A.extend(B)
A.append(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]-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

def main():
    N = int(input())
    A = list(map(int, ('0 ' + input() + ' 0').split()))

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(len(s)):
    if i > 0 and i <= len(s)-1:
        sum += abs(s[i]-s[i-1])
    
        
for i in range(1,len(s)-1):
    a = abs(s[i]-s[i-1])
    b = abs(s[i]-s[i+1])
    c = abs(s[i-1]-s[i+1])
    print(sum - a - b + c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

dif_1 = [0] * (N+1)
dif_2 = [0] * N

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

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

num = sum(dif_1)

for i in range(N):
    print(num - (dif_1[i] + dif_1[i+1]) + dif_2[i])

Submission status: Accepted

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

dif_1 = [0] * (N+1)
dif_2 = [0] * N

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

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

num = sum(dif_1)

for i in range(N):
    ans[i] = num - (dif_1[i] + dif_1[i+1]) + dif_2[i]

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
amt1 = 0

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

Submission status: Accepted

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

l.insert(0,0)
l.append(0)
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

for b in B:
    print(C+b)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
amt = 0

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

Submission status: Accepted

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

for i in range(1,n+1):
  # if i==n:
  #   print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  #   exit()
  # elif A[i]<=A[i+1] and ((A[i]>0 and A[i+1]<0) or (A[i]<0 and A[i+1]>0)):
  #   print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  # elif A[i]<=A[i+1]:
  #   print(sums)
  # else:
    print(sums-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())
x=[int(i) for i in input().split()]

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

print(dist-abs(x[0])-abs(x[0]-x[1])+abs(x[1]))

for i in range(1,n-1):
  if x[i-1]<=x[i]<=x[i+1] or x[i+1]<=x[i]<=x[i-1]:
    print(dist)
  else:
    print(dist-abs(x[i-1]-x[i])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1]))

print(dist-abs(x[-1])-abs(x[-1]-x[-2])+abs(x[-2]))

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


abc092_c()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in ("0 "+input()+" 0").split()]
ans=sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
  print(ans-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 itertools import accumulate

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

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

one, two, three = [None] + A[:2]
for i in range(N):
	one, two, three = two, three, A[i+2]
	first, second = two-one, three-two
	cost_to_reduce = 0
	if (first < 0) != (second < 0):
		cost_to_reduce = min(abs(first), abs(second))*2
	print(total_cost - cost_to_reduce)

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
a = deque(map(int, input().split()))
a.append(0)
a.appendleft(0)

s = sum([abs(a[i+1]-a[i]) for i in range(len(a)-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:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ab = abs(a[0])+abs(a[-1])
    for i in range(n-1):
        ab += abs(a[i]-a[i+1])

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

S = abs(A[0]) + abs(A[-1])
for a, b in zip(A[:-1], A[1:]):
    S += abs(b - a)

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
a = [0]
b = [0]
point_list = a + A_list + b
S = 0
for i in range(N+1):
    S += abs(point_list[i]-point_list[i+1])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

tmp = 0
for i in range(1, n+2):
    tmp += abs(arr[i-1] - arr[i])
    
for j in range(1, n+1):
    ans = tmp - (abs(arr[j-1] - arr[j]) + abs(arr[j] - arr[j+1])) + abs(arr[j-1] - arr[j+1])
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))

def mydiff(a, b): return (a - b) if a > b else (b - a)


dist = mydiff(A[0], 0)
diffs = [0] * N
for i in range(N):
    if i == 0:
        diffs[i] =  mydiff(A[i], 0) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], 0)
        dist += mydiff(A[i + 1], A[i])
    elif i == N - 1:
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(0, A[i]) - mydiff(0, A[i - 1])
    else:
        dist += mydiff(A[i + 1], A[i])
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], A[i - 1])
dist += mydiff(0, A[-1])

for i in range(N): print(dist - diffs[i])

Submission status: Accepted

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

costmax = abs(A[1])
costskip = []
for i in range(1, N + 1):
    costmax += abs(A[i + 1] - A[i])
    costskip += [abs(A[i+1] - A[i]) + abs(A[i] - A[i-1]) - abs(A[i+1]-A[i-1])]
[print(costmax - _) for _ in costskip]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, len(values) - 1):
    add = abs(values[i + 1] - values[i - 1])
    rem1 = abs(values[i] - values[i - 1])
    rem2 = abs(values[i + 1] - values[i])
    res = total_value + add - rem1 - rem2
    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + [int(x) for x in input().split()] + [0]
m = 0
for i in range(N + 1):
  m += abs(A[i + 1] - A[i])
skip = 0
for i in range(N):
  skip = abs(A[i + 2] - A[i + 1]) + abs(A[i + 1] - A[i]) - abs(A[i + 2] - A[i])
  print(m - skip)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#mapってそんなに速ないんけ？
#for 文と勝負や
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
#iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
iAll = sum([abs(aA[i+1]-aA[i]) for i in range(iN+1)])
#print("\n".join(map(str,map(lambda i:iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]), range(1,iN+1)))))
print("\n".join(map(str,[iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]) for i in range(1,iN+1)])))

Submission status: Accepted

Solution code:
#mapってそんなに速ないんけ？
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(str,map(lambda i:iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]), range(1,iN+1)))))

Submission status: Accepted

Solution code:
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(lambda i:str( iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1])), range(1,iN+1))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import copy
input=sys.stdin.readline

n=int(input())
l=[0]+list(map(int,input().split()))+[0]
#print(l)
dis=copy.deepcopy(l)
a=0
for i in range(1,n+2):
    a+=abs(l[i]-l[i-1])
#print(dis)
for i in range(1,n+1):
    print(a-abs(l[i]-l[i-1])-abs(dis[i+1]-l[i])+abs(l[i-1]-l[i+1]))

Submission status: Accepted

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

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

for i in ans:
    print(i)

Submission status: Accepted

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

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

if( (A[0]-0)*(A[1]-A[0])<0 ):
    print(total-abs(A[0]) - abs(A[1] - A[0]) +abs(A[1]) )
else:
    print(total)


for i in range(1,n-1):
    if( (A[i-1] -A[i])*(A[i] - A[i+1]) <0 ):
        print(total - 2*min([abs(A[i-1]-A[i]),abs(A[i]-A[i+1])]))
    else:
        print(total)

if( (A[n-1] - 0)*(A[n-2]-A[n-1]) <0):
    print(total-abs(A[n-1]) - abs(A[n-1] - A[n-2]) + abs(A[n-2]))
else:
    print(total)

Submission status: Accepted

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

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

sd = sum(b)

for j in range(n):
  if j == 0:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1]))
  elif j == n - 1:
    print(sd - b[j] - b[j + 1] + abs(a[j - 1]))
  else:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1] - a[j - 1]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
asum = abs(a[0])
for i in range(1,len(a)):
    asum += abs(a[i] - a[i - 1])
asum += abs(a[-1])
a.insert(0,0)
a.append(0)
for i in range(1,len(a) - 1):
    ans = asum - 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:
"""
C - Traveling Plan
あらかじめ、beginからnまで、endからnまでを計算しておく
"""

point_n = int(input())

# points 場所nの座標
points = [0]
for point in input().split():
    points.append(int(point))
points.append(0)

# 添字にnで場所nまでの距離
prep_forward = []
pre_point = 0
pre_distance = 0
for point in points:
    pre_distance += abs(pre_point - point)
    prep_forward.append(pre_distance)
    pre_point = point

# 添字にnで場所nまでの距離
prep_backward = []
pre_point = 0
pre_distance = 0
for point in reversed(points):
    pre_distance += abs(pre_point - point)
    prep_backward.append(pre_distance)
    pre_point = point
prep_backward

"""
print(points)
print(prep_forward)
print(prep_backward)
"""

# 場所nを抜かして計算してみる
for n in range(1, point_n+1):
    travel_distance = prep_forward[n-1] + abs(points[n-1] - points[n+1]) + prep_backward[point_n - n]
    #print(prep_forward[n-1])
    #print(abs(points[n-1] - points[n+1]))
    #print(prep_backward[point_n - n])
    print(travel_distance)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

dl = [0]
x = 0
for a in A:
    dl.append(dl[-1] + abs(a-x))
    x = a
dl.append(dl[-1] + abs(a))

A = [0] + A + [0]

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = [0] + list(li()) + [0]

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

for i in range(1,len(a)-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 = [int(i) for i in input().split()]
Total = abs(A[0]) + abs(A[N-1])
for i in range(1, N):
    Total += abs(A[i]-A[i-1])

start = 0
for i in range(N-1):
    cut = abs(A[i+1] - A[i]) + abs(A[i]-start) - abs(A[i+1] - start)
    print(Total - cut)
    start = A[i]
cut = abs(0 - A[N-1]) + abs(A[N-1] - start) - abs(0 - start)
print(Total - cut)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
ans = []
i = 1
s = [abs(a[1])] + [None for _ in range(n)]
d = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    s[i] = abs(a[i + 1] - a[i])
    if (a[i - 1] - a[i]) * (a[i] - a[i + 1]) >= 0:
        d[i] = 0
    else:
        d[i] = s[i] + s[i - 1] - abs(a[i + 1] - a[i - 1])
ss = sum(s)
for i in range(1, n + 1):
    print(ss - d[i])

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
An = list(map(int, input().split()))

#総和
all_sum = 0
for i in range(N):
    if i == 0:
        all_sum += abs(An[i])
    else:
        all_sum += abs(An[i] - An[i-1])

#0戻り分
all_sum += abs(An[-1])

for i in range(N):
    if i == 0:
        ans = all_sum - abs(An[i]) - abs(An[i] - An[i+1]) + abs(An[i+1])
    elif i == N-1:
        ans = all_sum - abs(An[i-1] - An[i]) - abs(An[i]) + abs(An[i-1])
    else:
        ans = all_sum - abs(An[i-1] - An[i]) - abs(An[i] - An[i+1]) + abs(An[i-1]-An[i+1])

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

d, d_skip = [0], [0]
for i in range(n):
    if i == 0:
        d.append(abs(a[i]))
    else:
        d.append(abs(a[i]-a[i-1]))
d.append(abs(a[-1]))

for i in range(n):
    if i == 0:
        d_skip.append(abs(a[i+1]))
    elif i < n-1:
        d_skip.append(abs(a[i+1] - a[i-1]))
    else:
        d_skip.append(abs(a[i-1]))

d_cumsum = [0]
for d_i in d[1:]:
    d_cumsum.append(d_i+d_cumsum[-1])
# print(d_cumsum, d_skip)
for i in range(1, n+1):
    ans = d_cumsum[i-1] + d_skip[i] + (d_cumsum[-1] - d_cumsum[i+1])
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


N = int(input())
A = inpl()
A = [0] + A + [0]
B = [0]
for i in range(len(A) - 1):
    B.append(A[i + 1] - A[i])
del B[0]

total = 0
for b in B:
    total += abs(b)

for i in range(1, N + 1):
    if B[i - 1] * B[i] >= 0:
        print(total)
    elif abs(B[i - 1]) < abs(B[i]):
        print(total - 2 * abs(B[i - 1]))
    else:
        print(total - 2 * abs(B[i]))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = 0
ma = max(A)
mi = min(A)

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

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

Submission status: Accepted

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

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

amounts = [0] * N
for i in range(N):
    left = 0
    right = 0
    if i > 0:
        left = A[i - 1]
    if i < N - 1:
        right = A[i + 1]
    amounts[i] = total + abs(left - right) - (abs(left - A[i]) + abs(A[i] - right))

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