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:
def cs(x):
    ans = 0
    for i in range(len(x)-1):
        ans += abs(x[i+1]-x[i])
    return ans


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

s = cs(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls = [0] + a_ls + [0]
diff_ls = [a_ls[i+1] - a_ls[i] for i in range(n+1)]
_sum = sum([abs(i) for i in diff_ls])
for i in range(n):
    if diff_ls[i] * diff_ls[i+1] > 0:
        print(_sum)
    else:
        print(_sum - abs(diff_ls[i]) - abs(diff_ls[i+1]) + abs(diff_ls[i+1] + diff_ls[i]))

Submission status: Accepted

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

Submission status: Accepted

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

ans = abs(a[0] )

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

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        elif 0 <= a[i+1] <= v or v <= a[i+1] <= 0:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= 0 <= a[i+1] or a[i+1] <= 0 <= v:
            print(ans-abs(v)*2)

    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= 0 <= v or v <= 0 <= a[i-1]:
            print(ans-abs(v)*2)
        elif v <= a[i-1] <= 0 or 0 <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

Submission status: Accepted

Solution code:
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
b = [0]*(n+1)
d = [0]*(n+1)
c = 0
for i in range(n+1):
  t = A[i]-A[i+1]
  d[i] = abs(t)
  if t > 0:
    b[i] = 1
  elif t < 0:
    b[i] = -1
  else:
    b[i] = 0
  c += d[i]
for i in range(n):
  if b[i]*b[i+1] >= 0:
    print(c)
  else:
    print(c-2*min(d[i], d[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 j in range(n + 1):
    cnt += abs(a[j + 1] - a[j])
# print(cnt)

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(cnt)
    else:
        cos = abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]) - abs(a[i - 1] - a[i + 1])
        print(cnt - cos)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
sum=0
for i in range(n+1):
    sum+=abs(a[i+1]-a[i])
for i in range(1,n+1):
    p=a[i-1]
    x=a[i]
    f=a[i+1]
    if p<=x<=f or f<=x<=p:
        print(sum)
    elif p<=f<=x or x<=f<=p:
        print(sum-2*abs(x-f))
    else:
        print(sum-2*abs(x-p))

Submission status: Accepted

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

def get_amount(a,b):
  return abs(a-b)

amount = 0
for i in range(-1,n):
  amount += abs(spots[i]-spots[i+1])
for i in range(n):
  a = spots[i-1]
  b = spots[i]
  c = spots[i+1]
  if a >= b >= c or a <= b <= c:
    print(amount)
  elif a > b and c > b:
    print(amount - (min(a,c)-b)*2)
  else:
    print(amount - (b-max(a,c))*2)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]
mx_cost = 0
tmp = 0
for i in map(int, input().split()):
    a.append(i)
    mx_cost += abs(tmp - i)
    tmp = i
mx_cost += abs(tmp)
a.append(0)

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

Submission status: Accepted

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


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


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

B = [0]*(N+2)
C = [0]*(N+2)
total=0
last=0
simb=1

for i in range(1,N+2):
    if((A[i]-A[i-1])>0):
        C[i]=1
    elif((A[i]-A[i-1])==0):
        C[i]=C[i-1]
    else:
        C[i]=-1

for i in range(1,N+1): 
    if(C[i+1]==C[i]):
        B[i]=1
    else:
        B[i]=-1
        total+=abs(last-A[i])
        last=A[i]

total+=abs(last)

for i in range(1,N+1):
    if(B[i]==1):
        print(total)
    else:
        print(total-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]
lst=[0]*(n+1)
for i in range(n+1):
    lst[i]=abs(a[i+1]-a[i])
s=sum(lst)
for i in range(1,n+1):
    print(s-lst[i-1]-lst[i]+abs(a[i+1]-a[i-1]))

Submission status: Accepted

Solution code:
import math
import copy
import sys
import bisect
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    #複数行の「1 2 3 4」型の入力を一配列に
    #x = sorted([list(map(int, input().split())) for _ in range(n)])
    #ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  
    n=int(input())
    a = list(map(int,input().split()))
    a.append(0)
    x=[abs(a[0])]
    for i in range(n):
        x.append(abs(a[i]-a[i+1]))
    y=[abs(a[1])]
    for i in range(n-1):
        y.append(abs(a[i]-a[i+2]))
    S=sum(x)
    for i in range(n):
        print(S-x[i]-x[i+1]+y[i])

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from math import *

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

sn = abs(a[0])
for i in range(n-1):
    sn += abs(a[i]-a[i+1])
sn += abs(a[n-1])
#print(sn)
p = sn
p -= abs(a[0])+abs(a[1]-a[0])-abs(a[1])
print(p)

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

Submission status: Accepted

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
sum_array = [0]
now = 0
for i in range(n):
    sum_array.append(sum_array[i] + abs(array[i] - now))
    now = array[i]
else:
    sum_array.append(sum_array[-1] + abs(array[-1] - 0))

for j in range(n):
    if j == 0:
        print(sum_array[-1] -
              (sum_array[j + 1] - sum_array[j]) -
              (sum_array[j + 2] - sum_array[j + 1]) +
              (abs(array[j + 1] - 0))
              )
    elif j == n - 1:
        print(sum_array[-3] + abs(array[-2]))
    else:
        print(sum_array[-1] -
              (sum_array[j + 1] - sum_array[j]) -
              (sum_array[j + 2] - sum_array[j + 1]) +
              (abs(array[j + 1] - array[j - 1]))
              )

Submission status: Accepted

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

a=[0]+a+[0]

cost=[abs(a[i]-a[i+1]) for i in range(len(a)-1)]
total=sum(cost)

ans=0
for i in range(n):
    ans = total - cost[i] - cost[i+1] + 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]

cost=[abs(a[i]-a[i+1]) for i in range(len(a)-1)]
total=sum(cost)

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

Submission status: Accepted

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

# Total Cost
c = 0
for i in range(len(a)-1):
    c += abs(a[i+1] - a[i])

# Partial Cost
for i in range(len(a)-1):
    if i == 0:
        continue
    elif i == len(a)-1:
        continue
    else:
        print(c - 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()))

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


print(M-abs(A[N-1])-abs(A[N-1]-A[N-2])+abs(A[N-2]))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

for i in range(n):
    print(total - D[i])

Submission status: Accepted

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

Submission status: Accepted

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

all_cost = 0
prev = 0
for a in A:
    all_cost += abs(a-prev)
    prev = a
all_cost += abs(A[-1])

prev = 0
for i, a in enumerate(A[:-1]):
    print(all_cost - abs(a-prev) - abs(a-A[i+1]) + abs(A[i+1]-prev))
    prev = a
print(all_cost - abs(A[-2]-A[-1]) - abs(A[-1]) + abs(A[-2]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC093C
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

C = [[0, 0] for i in range(N)]

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

C[N - 1][0] = abs(A[N] - A[N - 1])
C[N - 1][1] = abs(A[N+1] - A[N - 1])
C_all +=  abs(A[N])

for i in range(1, N):
    print(C_all - (C[i - 1][0] + C[i][0]) + C[i - 1][1])

print(C_all - (C[N - 1][0] + abs(A[N])) + C[N - 1][1])

Submission status: Accepted

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

C = [[0, 0] for i in range(N)]

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

C[N - 1][0] = abs(A[N] - A[N - 1])
C[N - 1][1] = abs(A[0] - A[N - 1])
C_all += abs(A[N] - A[N - 1]) + abs(A[N])

for i in range(1, N):
    print(C_all - (C[i - 1][0] + C[i][0]) + C[i - 1][1])

print(C_all - (C[N - 1][0] + abs(A[N])) + C[N - 1][1])

Submission status: Accepted

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

longest = 0
ans = 0

for i in range(n+1):
  if i==0:
    longest += abs(sortedlist[0]-0)
  elif i==n:
    longest += abs(0-sortedlist[n-1])
  else:
    longest += abs(sortedlist[i]-sortedlist[i-1])

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
# 2019/08/07
# かんにんぐ

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 図を書いて整理すればいいですね 差分の配列を利用
n = int(input()) 
a = [0] + list(map(int, input().split())) + [0]
b = [0 for _ in range(n+1)]
for i in range(n+1):
  b[i] = abs(a[i] - a[i+1])

s = sum(b)

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

Submission status: Accepted

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

A = [0] + A + [0]

p = 0
for i in range(1,N+2):
    p += 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(p)
    else:
        q = min(abs(A[i-1]-A[i]),abs(A[i]-A[i+1]))
        print(p-2*q)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=[0]+l+[0]
  n+=2

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

  # print(sm)

  for i in range(1,n-1):
    _sm=sm
    _sm+=abs(l[i+1]-l[i-1])
    _sm-=abs(l[i]-l[i-1])
    _sm-=abs(l[i+1]-l[i])
    print(_sm)

main()
# print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):#地点A[i(1~N)]にいかなくなる
    pre = A[i-1]
    cur = A[i]
    nex = A[i+1]
    if pre<=cur<=nex or nex<=cur<=pre:
        print(S)
    else:
        d = abs(cur-pre) + abs(nex-cur) - abs(pre-nex)
        print(S-d)

Submission status: Accepted

Solution code:
import copy

n = int(input())

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

#print(a)
anst = 0
for j in range(1,len(a)):
    anst += abs(a[j]-a[j-1])

for j in range(1,len(a)-1):
    ans = anst
    ans -= abs(a[j-1]-a[j]) + abs(a[j]-a[j+1])
    ans += abs(a[j-1]-a[j+1])
    print(ans)

Submission status: Accepted

Solution code:

n = int(input())
point_list = [0] + [ int(v) for v in input().split() ] + [0]

cost_list = [ abs(point_list[i] - point_list[i+1]) for i in range(n+1)]
total = sum(cost_list)
for i in range(n):
    print( total - ( cost_list[i] + cost_list[i+1] ) + abs(point_list[i] - point_list[i+2]) )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ARC093C - Traveling Plan (ABC092C)
# 累積和
def main():
    N = int(input())
    A = [0] + list(map(int, input().rstrip().split())) + [0]
    S = 0
    for i in range(1, N + 2):
        S += abs(A[i - 1] - A[i])

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=[0]+l+[0]

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

  ans=[]
  for i in range(1,n+1):
    ans.append(sm-abs(l[i]-l[i-1])-abs(l[i+1]-l[i])+abs(l[i+1]-l[i-1]))

  for x in ans:
    print(x)

main()

Submission status: Accepted

Solution code:
N=int(input())
A=[0]+list(map(int,input().split(' ')))+[0]
D=[abs(A[i+1]-A[i]) for i in range(N+1)]
S=sum(D)
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:
# ARC093C - Traveling Plan
N = int(input())
A = [0] + list(map(int, input().rstrip().split())) + [0]
S = 0
for i in range(1, N + 2):
    S += abs(A[i - 1] - A[i])

for i in range(1, N + 1):
    ans = S + 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:
N = int(input())
L = list(map(int, input().split()))
L.append(0)
L.insert(0, 0)
sum = 0
for i in range(N + 1):
	sum += abs(L[i+1] - L[i])
for i in range(N):
	print(sum + abs(L[i+2] - L[i]) - abs(L[i+2] - L[i+1]) - 
	abs(L[i+1] - L[i]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

lst.insert(0, 0)
lst.append(0)
arr = np.array(lst)

# インデックスごとに進んだ場合
order = np.abs(np.roll(arr, -1) - arr)
order = np.delete(order, -1)
sum_order = np.sum(order)
#print(order)

# iを飛ばして進んだ場合
skip = np.abs(np.roll(arr, -2) - arr)
skip = np.delete(skip, -1)
skip = np.delete(skip, -1)
#print(skip)

for i in range(N):
  cost = sum_order - order[i] - order[i+1] + skip[i]
  print(cost)

Submission status: Accepted

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

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

for i in range(1,n+1):
    if spots[i-1]<spots[i] and spots[i+1]<spots[i]:
        diff=min(abs(spots[i-1]-spots[i]),abs(spots[i+1]-spots[i]))
        print(total-abs(diff)*2)
    elif spots[i]<spots[i-1] and spots[i]<spots[i+1]:
        diff=min(abs(spots[i-1]-spots[i]),abs(spots[i+1]-spots[i]))
        print(total-abs(diff)*2)
    else:
        print(total)

Submission status: Accepted

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

Total = 0

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

for i in range(N):
    ans = Total
    if i == 0:
        ans -= abs(A[i]) + abs(A[i+1]-A[i])
        ans += abs(A[i+1])
    elif i == N-1:
        ans -= abs(A[i]) + abs(A[i]-A[i-1])
        ans += abs(A[i-1])
    else:
        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())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
c = [abs(x - y) for x, y in zip(a[:-1], a[1:])]
c_sum = sum(c)
for i in range(n):
    print(c_sum - c[i] - c[i + 1] + abs(a[i] - a[i + 2]))

Submission status: Accepted

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

r = [0]

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
cost=[]
for x in range(len(a)-1):
    cost.append(abs(a[x+1]-a[x]))
S=sum(cost)
change=[]
for y in range(1,n+1):
    change.append(abs(a[y+1]-a[y-1])-(cost[y-1]+cost[y]))
for i in range(n):
    print(S+change[i])

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

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

solve()

Submission status: Accepted

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

Submission status: Accepted

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

no_skip  = 0

for rep, content in enumerate(A[1:]):
    no_skip += abs(content - A[rep])

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

Submission status: Accepted

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

for i in range(n):
  tag=i+1
  #通過
  if(hoge[tag-1]<=hoge[tag] and hoge[tag]<=hoge[tag+1]):
    print(kei)
  elif(hoge[tag-1]>=hoge[tag] and hoge[tag]>=hoge[tag+1]):
    print(kei)
  #Uターン
  elif(hoge[tag+1]<=hoge[tag-1] and hoge[tag-1]<=hoge[tag]):
    print(kei-2*abs(hoge[tag-1]-hoge[tag]))
  elif(hoge[tag]<=hoge[tag-1] and hoge[tag-1]<=hoge[tag+1]):
    print(kei-2*abs(hoge[tag-1]-hoge[tag]))
  #近道
  elif(hoge[tag-1]<=hoge[tag+1] and hoge[tag+1]<=hoge[tag]):
    print(kei-2*abs(hoge[tag+1]-hoge[tag]))
  elif(hoge[tag]<=hoge[tag+1] and hoge[tag+1]<=hoge[tag-1]):
    print(kei-2*abs(hoge[tag+1]-hoge[tag]))

Submission status: Accepted

Solution code:
N = int(input())
As = [0]+list(map(int, input().split()))+[0]
ldp = [0]*(N+1)
rdp = [0]*(N+2)
for i in range(1, N+1):
    ldp[i] = ldp[i-1] + abs(As[i]-As[i-1])
    rdp[-(i+1)] = rdp[-i]+abs(As[-(i+1)]-As[-i])
for i in range(1, N+1):
    ans = ldp[i-1] + rdp[i+1] + abs(As[i+1]-As[i-1])
    print(ans)

Submission status: Accepted

Solution code:
import itertools
N = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
As.insert(0,0)
As.append(0)
cost1 = []
for a,b in zip(As[:-1],As[1:]):
    cost1.append(abs(a-b))
cost2 = []
for a,b in zip(As[:-2],As[2:]):
    cost2.append(abs(a-b))
original = sum(cost1)
# print(cost1)
# print(cost2)
for c1,c2,c3 in zip(cost1[:-1],cost1[1:],cost2):
    print(original -c1 - c2 + c3)

Submission status: Accepted

Solution code:
N = int(input())
A = [0]+[int(x) for x in input().split()]+[0]
dist = []
for ind,i in enumerate(A[:-1]):
    dist.append(abs(A[ind+1]-i))
ans0 = sum(dist)
for i in range(N):
    if(i==0):
        print(ans0 - dist[0]-dist[1] + abs(A[2]-A[0]))
    else:
        print(ans0 - (dist[i]+dist[i+1]) + abs(A[i+2]-A[i]))

Submission status: Accepted

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

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

for j in range(N):
    if j == 0:
        print(TD[j]+D[N]-D[j+1])
    elif j == N-1:
        print(D[j-1]+TD[j])
    else:
        print(D[j-1]+TD[j]+D[N]-D[j+1])