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 copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]>=0 and a[i+1]>=0 and a[i+1]<=a[i] or a[i]<=0 and a[i+1]<=0 and a[i]<=a[i+1]:#ok
   print(cnt-2*(abs(a[i])-abs(a[i+1])))
  elif a[i]>=0 and a[i+1]>=0 and a[i+1]>=a[i] or a[i]<=0 and a[i+1]<=0 and a[i]>=a[i+1]:#ok
   print(cnt)
  else:
   print(cnt-2*abs(a[i]))
 elif i<=n-2: #ok
  if a[i-1]>=a[i] and a[i]>=a[i+1] or a[i-1]<=a[i] and a[i]<=a[i+1]:
   print(cnt)
  elif a[i]>=a[i-1]>=a[i+1] or a[i+1]>=a[i-1]>=a[i]:
   print(cnt-2*abs(a[i]-a[i-1]))
  elif a[i]>=a[i+1]>=a[i-1] or a[i-1]>=a[i+1]>=a[i]:
   print(cnt-2*(abs(a[i]-a[i+1])))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<=a[i-1]:#ok
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  elif a[i]>=0 and a[i-1]>=0 and a[i-1]>a[i] or a[i]<=0 and a[i-1]<=0 and a[i]>=a[i-1]:#ok
   print(cnt)
  else:
   print(cnt-2*abs(a[i]))

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[a[0]]
    ans=abs(a[0])
    for i in range(n-1):
        b.append(a[i+1]-a[i])
        ans+=abs(a[i+1]-a[i])
    b.append(-1*a[n-1])
    ans+=abs(a[n-1])
    for i in range(n):
        if b[i]*b[i+1]>=0:
            print(ans)
        else:
            print(ans-abs(b[i])-abs(b[i+1])+abs(b[i]+b[i+1]))
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
f = [x[0]]
for i in range(n-1):
    f.append(abs(x[i+1]-x[i]))
c = [0]
for i in range(n):
    c.append(abs(f[i]+c[i]))
c.append(abs(x[-1])+c[-1])
d = c[-1]
x.insert(0,0)
x.append(0)
for i in range(n):
    if x[i] < x[i+1] and x[i+2] < x[i+1]:
        print(d-2*abs(x[i+1] - max(x[i],x[i+2])))
    elif x[i+1] < x[i] and x[i+1] < x[i+2]:
        print(d-2*abs(x[i+1] - min(x[i],x[i+2])))
    else:
        print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
q = deque(list(map(int, input().split())))
q.appendleft(0)
q.append(0)

cost = [0] * (len(q) - 1)

for i in range(n + 1):
    cost[i] = abs(q[i] - q[i + 1])

costs = sum(cost)

for i in range(1, len(q) - 1):
    temp = costs + abs(q[i - 1] - q[i + 1]) - (abs(q[i - 1] - q[i]) + abs(q[i + 1] - q[i]))
    print(temp)

Submission status: Accepted

Solution code:
N = int(input())
A = [0]
A = A + list(map(int, input().split()))
A.append(0)
sumOfRoute = 0
tmp = 0
for a in A:
    sumOfRoute += abs(tmp-a)
    tmp = a

prev = 0
for i in range(1, N+1):
    nexti = A[i+1]
    print(sumOfRoute + abs(prev - nexti) - abs(A[i] - nexti) - abs(prev - A[i]))
    prev = A[i]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

#print(a)

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

#print(sub_a)
total = sum(sub_a)

for k in range(n):
    # もともとの差の総和から該当部分を引いて、iを飛ばした場合のに転換の距離を足す
    print(total - sub_a[k]-sub_a[k+1] + abs(a[k]-a[k+2]))

Submission status: Accepted

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

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

c = sum(B)


for i in range(1, N+1):
    print(c - B[i-1]-B[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])
for i in range(N-1):
    total += abs(A[i+1]-A[i])
total += abs(A[N-1])
print(total+abs(A[1])-abs(A[1]-A[0])-abs(A[0]))
for i in range(1,N-1):        
    print(total+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))    
print(total+abs(A[N-2])-abs(A[N-2]-A[N-1])-abs(A[N-1]))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
  a = abs(C[i] - prev) + abs(C[i + 1] - C[i])
  b = abs(C[i + 1] - prev)
  print(total - a + b)
  prev = C[i]

Submission status: Accepted

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

for i in range(n):
  v=abs(l[i+2]-l[i+1])+abs(l[i+1]-l[i])
  v2=abs(l[i+2]-l[i])
  print(tmp-abs(v2-v))

Submission status: Accepted

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

n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
l.append(0)
costs = []


def log(v):
    print(v, file=sys.stderr)


for l2 in [l[i:i+2] for i in range(0, len(l)-1, 1)]:
    costs.append(abs(l2[0] - l2[1]))
all_cost = sum(costs)
print(all_cost, file=sys.stderr)
for i in range(1, n+1):
    print(all_cost - (abs(l[i - 1] - l[i]) +
                      abs(l[i] - l[i + 1]) - abs(l[i - 1] - l[i + 1])))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

for i in range(n+2):
    if i == 0 or i == n+1: continue
    if a[i-1] < a[i] < a[i+1] or a[i-1] > a[i] > a[i+1]:
        print(cost)
    else:
        m = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])
        p = abs(a[i-1] - a[i+1])
        print(cost - m + p)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1,n+1,1):
        c1 = abs(a[i+1]-a[i]) + abs(a[i]-a[i-1])
        c2 = abs(a[i+1] - a[i-1])
        print(val_sum - c1 + c2)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    totalL = abs(A[0])
    for i in range(1, N):
        totalL += abs(A[i] - A[i-1])
    totalL += abs(A[N-1])
    pre = 0
    A.append(0)
    Ans = [totalL] * N
    for i in range(N):
        if pre <= A[i] <= A[i+1]: pre = A[i]
        elif A[i+1] <= A[i] <= pre: pre = A[i]
        else:
            Ans[i] += abs(A[i+1] - pre) - abs(A[i] - pre) - abs(A[i+1] - A[i])
            pre = A[i]


    print("\n".join(map(str, Ans)))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

if 0<=A[0]<=A[1] or A[1]<=A[0]<=0:
    print(ans)
elif A[0]>=0 and A[1]<=0:
    print(ans-2*abs(A[0]))
elif A[0]<=0 and A[1]>=0:
    print(ans-2*abs(A[0]))
else:
    print(ans-2*abs(A[0]-A[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(ans)
    elif A[i+1]<=A[i-1]<=A[i] or A[i]<=A[i-1]<=A[i+1]:
        print(ans-2*abs(A[i]-A[i-1]))
    else:
        print(ans-2*abs(A[i]-A[i+1]))


if 0<=A[n-2]<=A[n-1] or A[n-1]<=A[n-2]<=0:
    print(ans-2*abs(A[n-2]-A[n-1]))
elif A[n-1]>=0 and A[n-2]<=0:
    print(ans-2*abs(A[n-1]))
elif A[n-1]<=0 and A[n-2]>=0:
    print(ans-2*abs(A[n-1]))
else:
    print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = [0]+list(map(int,input().split()))+[0]
b = []
for i in range(n+1):
    b.append(abs(a[i]-a[i+1]))
c = sum(b)
for j in range(0,n):
    print(c - b[j] - b[j+1] + abs(a[j]-a[j+2]))

Submission status: Accepted

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

total = [0]*n
total[0] = abs(a[0])
fee = [0]*n
fee[0] = abs(a[0])

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

dist = total[-1]

print(total[-1] - fee[0] - fee[1] + abs(a[1]) + abs(a[-1]))

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

print(total[-2] + abs(a[-2]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

a.insert(0, 0)
a.append(0)
tmp = 0
for i in range(n + 1):
    tmp += abs(a[i + 1] - a[i])
#print(tmp)

for i in range(1, n + 1):
    #print(abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]) , abs(a[i + 1] - a[i - 1]))
    ans = tmp - 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()))
p = 0
ls = []
for i in range(n):
    ls.append(abs(A[i]-p))
    p = A[i]
ls.append(abs(A[-1]))
p = 0
ls2 = []
for i in range(1,n):
    ls2.append(abs(A[i] - p))
    p = A[i-1]
ls2.append(abs(A[n-2]))
s = sum(ls)

for i in range(n):
    print(s - ls[i] - ls[i+1] + ls2[i])

Submission status: Accepted

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

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

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

R = R[::-1]

ans = []
for i in range(1, N + 1):
    ans.append(L[i - 1] + R[i + 1] + abs(A[i - 1] - A[i + 1]))
print(*ans, sep='\n')

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+1]-a[i])
for i in range(n):
    ans = s+ abs(a[i+2]-a[i])-(abs(a[i]-a[i+1])+abs(a[i+1] - a[i+2]))
    print(ans)

Submission status: Accepted

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

s = 0 #全体の合計値
for i in range(1, n+2):
  s += abs(A[i-1] - A[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():

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

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

resolve()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = tuple(map(int,input().split()))
    front = [0]*(n+10)
    back = [0]*(n+10)
    front[1] = abs(a[0])
    for i in range(1,n):
        front[i+1]=front[i]+abs(a[i]-a[i-1])
    back[n] = abs(a[n-1])
    for i in range(2,n+1):
        back[n-i+1] = back[n-i+2]+abs(a[n-i+1]-a[n-i])
    for i in range(n):
        if i==0:
            print(abs(a[1])+back[2])
        elif i==n-1:
            print(front[n-1]+abs(a[n-2]))
        else:
            print(front[i]+back[i+2]+abs(a[i-1]-a[i+1]))
if __name__ == "__main__":
    solve()

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-1]-A[i])

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
a.insert(0, 0)
a.append(0)
pre = 0
ans = 0
for i in range(n + 2):
    ans += abs(a[i] - pre)
    pre = a[i]
for i in range(1, n + 1):
    pans = ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1])
    print(pans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    n = int(input())
    a = list(map(int, input().split()))
    b = np.array([0] + a + [0])
    c = np.abs(np.diff(b))
    s = np.sum(c)
    t = np.array([-(c[i - 1] + c[i]) + abs(b[i + 1] - b[i - 1]) for i in range(1, n + 1)])
    u = s + t
    v = list(map(str, u))
    ans = '\n'.join(v)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = [0]
    a.extend(list(map(int, input().split())))
    a.append(0)

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))

pay = [abs(a[0])]
dis = [a[0]]
for i in range(len(a) - 1):
    pay.append(abs(a[i + 1] - a[i]))
    dis.append(a[i + 1] - a[i])
pay.append(abs(0 - a[-1]))
dis.append(0 - a[-1])
summ = sum(pay)

for i in range(n):
    ans = summ - (pay[i] + pay[i + 1]) + abs(dis[i] + dis[i + 1])
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[0]
for a in input().split():
  A.append(int(a))
A.append(0)
ALL=0
for i in range(len(A)-1):
  ALL+=abs(A[i]-A[i+1])
for i in range(len(A)):
  if i in (0,len(A)-1):
    continue
  ans=0
  ans+=ALL
  ans-=abs(A[i]-A[i+1])+abs(A[i]-A[i-1])
  ans+=abs(A[i-1]-A[i+1])
  print(ans)

Submission status: Accepted

Solution code:
n, *A = map(int, open(0).read().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0]*(n+1)

spots = [0]
spots = spots + list(map(int, input().split())) + spots
sum_cost = 0
for i in range(n+2):
  if i+1 > n+1:
    break
  sum_cost += abs(spots[i+1] - spots[i])
for i in range(1,n+1):
  d = sum_cost - abs(spots[i]-spots[i+1]) - abs(spots[i-1]-spots[i]) + abs(spots[i-1] - spots[i+1])
  print(d)

Submission status: Accepted

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

D1 = [0]*(N+1)
D2 = [0]*N

s = 0
last = 0
for i in range(N):
    a = A[i]
    d = abs(last - a)
    D1[i] = d
    s += d
    last = a
D1[N] = abs(last)
s += abs(last)

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

# print(D1, D2)
for i in range(N):
    ans = s - (D1[i] + D1[i+1]) + D2[i]
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
sumA = 0
A_ = [0] + A + [0]
for i in range(1, n+2):
    sumA += abs(A_[i]-A_[i-1])
for i in range(1, n+1):
    if (A_[i] - A_[i-1])*(A_[i+1]-A_[i])<0:
        print(sumA-abs(A_[i] - A_[i-1])-abs(A_[i+1]-A_[i])+abs(A_[i+1]-A_[i-1]))
    else:
        print(sumA)

Submission status: Accepted

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

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

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

anss = []

for i in range(1, N+1):
    amount = total - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1])
    anss.append(amount)

for ans in anss:
    print(ans)

Submission status: Accepted

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

D = 0

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().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):
  print(S - 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())
n+=1
a = [0]+ list(map(int, input().split( )))
al = 0
for i in range(1,n+1):
    al += abs(a[i-1]-a[i%n])

for i in range(1,n):
    al2 = al
    al2 -= abs(a[i]-a[(i+1)%n])
    al2 -= abs(a[i]-a[(i-1)%n])
    al2 += abs(a[i-1]-a[(i+1)%n])
    print(al2)

Submission status: Accepted

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

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

l = sum(c)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    A.insert(0, 0)
    A.append(0)
    sum = 0
    for i in range(N+1):
        sum += abs(A[i] - A[i+1])
    for i in range(1, N+1):
        ans = sum - abs(A[i] - A[i-1]) - abs(A[i] -
                                             A[i+1]) + abs(A[i-1] - A[i+1])
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sm=0
current=0

for a in A:
    sm+=abs(current - a)
    current=a

sm+=abs(current)

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

for i in range(1,len(A)-1):
    if A[i-1] <= A[i] and A[i] <= A[i+1]: # no effect to total cost
        print(sm)
    elif A[i+1] <= A[i] and A[i] <= A[i-1]: # no effect to total cost
        print(sm)
    else:
        mx = max(A[i-1],A[i+1])
        mn = min(A[i-1],A[i+1])

        if mx < A[i]:
            print(sm - 2*(A[i] - mx))
        else:
            print(sm - 2*(mn - A[i]))

Submission status: Accepted

Solution code:
# ARC093c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = [0]
    a.extend(list(map(int, input().split())))
    a.append(0)
    # print(a)

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

    for j in range(1, n+1):
        if a[j-1] <= a[j] <= a[j+1] or a[j-1] >= a[j] >= a[j+1]:
            print(total)
            continue
        print(total-abs(a[j]-a[j-1])-abs(a[j+1]-a[j])+abs(a[j+1]-a[j-1]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1,N+1):
    print(sumA - 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(' ')))
skip=[0]*N
ans = abs(A[0])
for i in range(N):
    if i != N-1:
        ans += abs(A[i]-A[i+1])
    else:
        ans += abs(A[i])
    if  i==0:
        skip[i] = abs(A[i+1])
    elif i < N-1:
        skip[i]=abs(A[i-1]-A[i+1])
    else:
        skip[i] = abs(A[-2])
for i in range(N):
    if i==0:
        print(ans+skip[i]-abs(A[i])-abs(A[i]-A[i+1]))
    elif i==N-1:
        print(ans+skip[i]-abs(A[-1])-abs(A[-2]-A[-1]))
    else:
        print(ans+skip[i]-abs(A[i]-A[i-1])-abs(A[i+1]-A[i]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.append(0)
sm = abs(A[0])
j = 0
while j < N:
        sm += abs(A[j]-A[j+1])
        j += 1

for i in range(N):
    if i == 0:
        print(sm-abs(A[0]-0)
                -abs(A[1]-A[0])
                +abs(A[1]-0))
        continue
    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()))
ans=0
A=A+[0]
_A=[0]*N
_=0
for i in range(N):
  ans+=abs(_-A[i])
  _A[i]=abs(A[i+1]-_)-abs(_-A[i])-abs(A[i]-A[i+1])
  _=A[i]
ans+=abs(_-A[-1])
for i in range(N):
  print(ans+_A[i])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mina = min(a)
a.insert(0, 0), a.append(0)
total = 0
for i in range(N + 1):
    total += abs(a[i] - a[i + 1])

for i in range(N):
        ans = total - 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 = list(map(int, input().split()))
A = [0] + A[:] + [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:
    X = S - abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]) + abs(abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]))
    print(X)
  else:
    X = S
    print(X)

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

A.insert(0, 0)
A.append(0)
sum = 0
for i in range(N + 1):
    sum += abs(A[i + 1] - A[i])
    
count = 0
for i in range(1, N + 1):
    ans = sum - ((abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1])) - abs(A[i + 1] - A[i - 1]))
    print(ans)