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 sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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

def main():
    N = INT()
    A = LIST()
    A_ = [0] + A +[0]
    ans = []
    p= 0
    for i in range(N+1):
        p += abs(A_[i+1] - A_[i])

    for i in range(1, N+1):
        print(p - (abs(A_[i]-A_[i-1]) + abs(A_[i+1]-A_[i])) + 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()))
x,m=0,0
for i in range(n):
    m+=abs(x-a[i])
    x=a[i]
m+=abs(x)
for i in range(n):
    ans=m
    if i==0: ans+=abs(a[i+1])-abs(a[i+1]-a[i])-abs(a[i])
    elif i==n-1:
        ans+=abs(a[i-1])-abs(a[i])-abs(a[i]-a[i-1])
    else:
        ans+=abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
dist = 0
for i in range(1,N+1):
    dist += abs(A[i]-A[i-1])
dist += abs(A[0]-A[N])
for i in range(1,N):
    if A[i-1]<=A[i]<=A[i+1] or A[i+1]<=A[i]<=A[i-1]:
        print(dist)
    elif A[i-1]<=A[i+1]<=A[i] or A[i]<=A[i+1]<=A[i-1]:
        print(dist-abs(A[i+1]-A[i])*2)
    elif A[i]<=A[i-1]<=A[i+1] or A[i+1]<=A[i-1]<=A[i]:
        print(dist-abs(A[i]-A[i-1])*2)
if A[N-1]<=A[N]<=A[0] or A[0]<=A[N]<=A[N-1]:
        print(dist)
elif A[N-1]<=A[0]<=A[N] or A[N]<=A[0]<=A[N-1]:
    print(dist-abs(A[0]-A[N])*2)
elif A[N]<=A[N-1]<=A[0] or A[0]<=A[N-1]<=A[N]:
    print(dist-abs(A[N]-A[N-1])*2)

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
cn = [abs(a[i+1] - a[i]) for i in range(n+1)]
ct = sum(cn)
cs = [ct - cn[i] - cn[i+1] + abs(a[i] - a[i+2]) for i in range(n)]
print('\n'.join(map(str, cs)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
ls.append(0)
sumls=[abs(ls[i-1]-ls[i]) for i in range(N+1)]
SUM=sum(sumls)
for i in range(N):
  print(SUM-sumls[i]-sumls[i+1]+abs(ls[i-1]-ls[i+1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = [0] + string_to_int(inputs[0]) + [0]
    all_cost = 0
    position = 0
    for a in A:
        all_cost += abs(position - a)
        position = a
    all_cost += abs(position)

    costs = []
    # 0 3 5 -1 0
    for i, a in enumerate(A):
        if i == 0 or i == len(A) - 1:
            continue
        cost = all_cost \
            - abs(A[i] - A[i-1]) \
            - abs(A[i+1] - A[i]) \
            + abs(A[i+1] - A[i-1])
        costs.append(cost)
    return costs


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    for r in ret:
        print(r)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

    if i == n-2:
        skip.append(abs(a[i] - a[0]))
    else:
        skip.append(abs(a[i+2] - a[i]))

dist_one.append(abs(a[-1] - a[0]))

base = sum(dist_one)

for i in range(n-1):
    print(base - sum(dist_one[i:i+2]) + skip[i])

Submission status: Accepted

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

for x in c:
  print(x+s)

Submission status: Accepted

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

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

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:
def cc092():
    n = int(input())
    an = [0] + list(map(int, input().split())) + [0]

    c = 0
    p = 0
    for i in an:
        c += abs(p-i)
        p = i

    for i in range(1, n+1):
        cc = abs(an[i-1]-an[i+1]) - (abs(an[i-1]-an[i]) + abs(an[i]-an[i+1]))
        print(c+cc)

cc092()

Submission status: Accepted

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

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
    total += abs(p-a)
    p = a
total += abs(p)

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

Submission status: Accepted

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

cnt = 0

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

for i in range(1,N+1):
    ans = cnt - 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()))
#print("A",A)

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

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

for i in range(N):
  if i==0:
    print(G[i+1]+abs(A[i+1]))
  elif i==N-1:
    print(S[i-1]+abs(A[i-1]))
  else:
    print(S[i-1]+G[i+1]+abs(A[i+1]-A[i-1]))

Submission status: Accepted

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

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

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

ans = msum - abs(a[N - 2] - a[N - 1]) - abs(a[N - 1]) + abs(a[N - 2] - 0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A.append(0)
A.insert(0, 0)
L = []
for i in range(N+1):
    L.append(abs(A[i]-A[i+1]))
    
L_a = []
for i in range(N):
    L_a.append(abs(A[i]-A[i+2]))
    
l = 0
for i in range(N+1):
    l += abs(A[i]-A[i+1])
    
for i in range(N):
    print(l-L[i]-L[i+1]+L_a[i])

Submission status: Accepted

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

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

dist = 0
for i in range(N+1): # 0からN
    dist += abs(A[i+1] - A[i])

for i in range(1, N+1): # 1からN
    if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
        ans = dist
        print(ans)
    else:
        ans = dist - 2 * min(abs(A[i-1] - A[i]), abs(A[i+1] - A[i]))
        print(ans)

Submission status: Accepted

Solution code:
# aBC092 C - Traveling Plan
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
l = [abs(a[i+1]-a[i]) for i in range(n+1)]
ans = sum(l)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
# 累積和
cur = 0
b = []
for i in range(1, len(a)):
    b.append(abs(a[i] - cur))
    cur = a[i]
s = sum(b)

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

Submission status: Accepted

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

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

for i in range(1, N + 1) :
    if min(A[i-1], A[i+1]) <= A[i] <= max(A[i-1], A[i+1]) :
        print(s)
    else :
        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()))
A.insert(n,0)
A.insert(0,0)
f=0
for i in range(n+1):
    f+=abs(A[i+1]-A[i])
for i in range(1,n+1):
    d=abs(abs(A[i-1]-A[i])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1]))
    print(f-d)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

L = [0] + L + [0]

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

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

su = abs(L[0])
a = [0] * N
for i in range(1, N):
    t = 0
    if L[i - 1] * L[i] < 0:
        t = abs(L[i - 1]) + abs(L[i])
    else:
        t = abs(L[i - 1] - L[i])
    su += t
    a[i] = t
su += abs(L[-1])

if L[0] * L[1] <= 0:
    print(su - abs(L[0]) * 2)
else:
    if L[0] < 0:
        if L[0] > L[1]:
            print(su)
        else:
            print(su - a[1] * 2)
    else:
        if L[0] < L[1]:
            print(su)
        else:
            print(su - a[1] * 2)

for i in range(1, N - 1):
    c = a[i] + a[i + 1]

    t = 0
    if L[i - 1] * L[i + 1] < 0:
        t = abs(L[i - 1]) + abs(L[i + 1])
    else:
        t = abs(L[i - 1] - L[i + 1])

    print(su - c + t)

if L[-2] * L[-1] <= 0:
    print(su - abs(L[-1]) * 2)
else:
    if L[-1] < 0:
        if L[-1] > L[-2]:
            print(su)
        else:
            print(su - a[-1] * 2)
    else:
        if L[-1] < L[-2]:
            print(su)
        else:
            print(su - a[-1] * 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

    else: print(dp[-1] +abs(a[i+1]-a[i-1]) - abs(a[i+1]-a[i])- abs(a[i]-a[i-1]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

pay = []

for i in range(N):
    a, b, c = A[i], A[i + 1], A[i + 2]
    if a < c:
        if a <= b <= c:
            pay.append(0)
        elif b < a:
            pay.append(2 * abs(a - b))
        elif c < b:
            pay.append((2 * abs(b - c)))
    elif c < a:
        if c <= b <= a:
            pay.append(0)
        elif b < c:
            pay.append(2 * abs(c - b))
        elif a < b:
            pay.append(2 * abs(b - a))
    else:
        if a == b:
            pay.append(0)
        else:
            pay.append(2 * abs(b - a))

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


for p in pay:
    print(ans - p)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


dif1=[]
dif2=[]

for i in range(n+1):
    dif1+=[abs(li[i+1]-li[i])]
for i in range(n):
    dif2+=[abs(li[i+2]-li[i])]

total=sum(dif1)

for i in range(n):
    print(total-dif1[i]-dif1[i+1]+dif2[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n + 1):
    ans = s
    ans -= abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1])
    ans += 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]
s = sum([abs(a[i+1]-a[i]) for i in range(n+1)])
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())
ls = [0] + list(map(int, input().split())) + [0]
ds = [abs(a - b) for a, b in zip(ls, ls[1:])]
total = sum(ds)
for i in range(1, n + 1):
    prev = ls[i - 1]
    curr = ls[i]
    next_ = ls[i + 1]
    if prev <= curr <= next_ or prev >= curr >= next_:
        print(total)
    else:
        d = abs(next_ - prev)
        print(total + d - ds[i] - ds[i - 1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.insert(n+1, 0)
kyori=0
for i in range(1,len(a)):
    kyori += abs(a[i]-a[i-1])
for i in range(1, len(a)-1):
    kyori2= kyori
    if a[i-1]<=a[i]<=a[i+1] or a[i-1]>=a[i]>=a[i+1]:
        print(kyori2)
    elif a[i-1]<a[i+1]<a[i] or a[i]<a[i+1]<a[i-1]:
        kyori2 = kyori2 -abs(a[i+1]-a[i])*2
        print(kyori2)
    else:
        kyori2 = kyori2-abs(a[i-1]-a[i])*2
        print(kyori2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [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 - 1] - A[i]) - abs(A[i + 1] - A[i]) + abs(A[i - 1] - A[i + 1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#YouTube解説
N = int(input())
A = [int(a) for a in input().split()]
A.insert(0, 0)
A.append(0)

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

for j in range(1, N+1):
  ans = 0
  A_im1 = A[j-1]
  A_i = A[j]
  A_ip1 = A[j+1]
  ans = total_money - abs(A_im1 - A_i) - abs(A_i - A_ip1) + abs(A_im1 - A_ip1)
  print(ans)

Submission status: Accepted

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

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

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

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

B_abs = [abs(b) for b in B]
B_abs_cusum = [0]
cusum = 0
for j in B_abs:
  cusum += j
  B_abs_cusum.append(cusum)

for k in range(1, N+1):
  M1 = B_abs_cusum[k-1]
  M2 = abs(B[k-1] + B[k])
  M3 = B_abs_cusum[-1] - B_abs_cusum[k+1]
  M = M1 + M2 + M3
  print(M)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a = list(map(int,input().split()))
dp = [0] * (N+1)
dp[0] = abs(a[0])
for i in range(1, N):
    dp[i] = abs(a[i]-a[i-1])
dp[N] = abs(a[-1])
result = sum(dp)
for i in range(N):
    ans = result
    ans -= dp[i]+dp[i+1]
    if i == 0:
        ans += abs(a[i+1])
    elif i == N-1:
        ans += abs(a[i-1])
    else:
        ans += abs(a[i+1] - a[i-1])
    print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    A=[int(i) for i in input().split()]
    B=[A[0]]+[A[i+1]-A[i] for i in range(n-1)]+[-A[n-1]]
    abssum=sum(abs(b) for b in B)
    for i in range(n):
        print(abssum-abs(B[i])-abs(B[i+1])+abs(B[i]+B[i+1]))
resolve()

Submission status: Accepted

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

b = [0]

for i in range(len(a)-1):
    b.append(abs(a[i+1]-a[i]) + b[-1])

s = b[-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

for x in ans:
    print(x)

Submission status: Accepted

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  maes = [(0,0)]
  usiros = [(0,0)]
  
  for i in range(n):
    place = a[i]
    value,preplace = maes[i]
    maes.append((value+abs(preplace-place),place))
  for i in range(n-1,-1,-1):
    place = a[i]
    value,preplace = usiros[(n-i-1)]
    usiros.append((value+abs(preplace-place),place))

  for i in range(n):
    maeval,maeplace = maes[i]
    usival,usiplace = usiros[n-i-1]
    print(maeval+usival+abs(maeplace-usiplace))

solve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

# 順方向と逆方向から計算したリストを保持しておく？
# 戻るときはリストの最も右の要素と原点とのdiffをとればいい

# 増加しなければスキップしてもかかる金額は変わらない

L = [0] + L + [0]
A = [abs(x - y) for x , y in zip(L, L[1::])]
SA = sum(A)

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

# 順方向と逆方向から計算したリストを保持しておく？
# 戻るときはリストの最も右の要素と原点とのdiffをとればいい

# 増加しなければスキップしてもかかる金額は変わらない

L = [0] + L
A = [abs(x - y) for x , y in zip(L, L[1::])]
SA = sum(A)
ans = 0

for i in range(N):
    if i < N - 1:
        idx = i + 1
        x = L[idx]
        # 単調減少か、または単調増加か
        right = L[idx + 1] - x
        left = x - L[idx - 1]
        if (left >= 0 and right >= 0) or (left <= 0 and right <= 0):
            ans = SA
        else:
            ans = SA - (abs(x - L[idx - 1]) + abs(x - L[idx + 1])) + abs(L[idx + 1] - L[idx - 1])
        print(ans + abs(L[N]))
    else:
        print(SA - abs(L[N] - L[N - 1]) + abs(L[N - 1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    max_ = 0
    for i in range(1, N+2):
        max_ += abs(a[i] - a[i-1])
    
    for i in range(1, N+1):
        pre = a[i] - a[i-1]
        nex = a[i+1] - a[i]
        if (pre > 0 and nex < 0) or (pre < 0 and nex > 0):
            abs_pre = abs(pre)
            abs_nex = abs(nex)
            print(max_ - min(abs_nex, abs_pre) * 2)
        else:
            print(max_)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc092/tasks/arc093_a
# C - Traveling Plan

N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = [0] + a_list + [0]
total_cost = 0
for x, y in zip(a_list[:-1], a_list[1:]):
    total_cost += abs(x - y)

diff_list = []

for i in range(1, N + 1): # 10 ** 5
    before = abs(a_list[i-1] - a_list[i]) + abs(a_list[i] - a_list[i+1])
    after = abs(a_list[i-1] - a_list[i+1])
    diff_list.append(before - after)

ans = '\n'.join([str(total_cost - d) for d in diff_list])
print(ans)