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
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


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

Submission status: Accepted

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

b=[0] + a + [0]
now=0
dist=0


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

for i in range(1,n+1):
    ans=0
    
    d1 = abs(b[i-1] - b[i+1])
    d2 = abs(b[i]-b[i-1])
    d3 = abs(b[i+1]-b[i])

    ans = dist+d1-(d2+d3) 

    print(ans)

Submission status: Accepted

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

move = [abs(a[i - 1] - a[i]) for i in range(1, n + 2)]
msum = sum(move)
for i in range(1, n + 1):
    tmp = - move[i - 1] - move[i] + abs(a[i - 1] - a[i + 1])
    print(msum + tmp)

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0 for _ in range(n+2)]
a[1:-1] = list(map(int, input().split()))
total = 0
for i in range(n + 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:
n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
a.append(0)

total = 0

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

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

Submission status: Accepted

Solution code:
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    *A, = map(int, input().split())

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.insert(0, 0)
L.append(0)
S = 0
for i in range(1, n + 2):
    S += abs(L[i] - L[i - 1])
T = [0] * n
for j in range(1, n + 1):
    T[j - 1] = abs(L[j + 1] - L[j - 1]) - abs(L[j] - L[j - 1]) - abs(L[j + 1] - L[j])
for k in range(n):
    print(S + T[k])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline

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

d=[0]*(n+1)
d[1]=abs(s[0])
for i in range(2,n+1):
    d[i]=d[i-1]+abs(s[i-1]-s[i-2])
ans=abs(s[n-1])+d[n]-d[2]+d[0]+abs(s[1])
print(ans)
for i in range(1,n-1):
    ans=abs(s[n-1])+d[i]+d[n]-d[i+2]+abs(s[i+1]-s[i-1])
    print(ans)
ans=d[n-1]+abs(s[n-2])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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


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

S = sum(dd)

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))

a = deque(a)
a.appendleft(0)
a.append(0)

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    rui = [0]*(n+1)

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

    for i in range(n):
        if i == 0:
            print(sr-rui[i]-rui[i+1]+abs(a[i+1]))
        elif i == n-1:
            print(sr-rui[i+1]-rui[i]+abs(a[i-1]))
        else:
            print(sr-rui[i]-rui[i+1]+abs(a[i-1]-a[i+1]))
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, n + 2):
    costs.append(abs(spots[i] - spots[i - 1]))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

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


s+=abs(a[n]-a[n-1])
l[n]=abs(a[n]-a[n-1])+abs(a[n]-a[0])-abs(a[0]-a[n-1])


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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1,n-1):
    ans = total - 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:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [0] + list(map(int, input().split())) + [0]

    cost_init = 0
    for i in range(1, n + 2):
        cost_init += 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(cost_init)
        elif A[i - 1] <= A[i] and A[i] >= A[i + 1] or A[i - 1] >= A[i] and A[i] <= A[i + 1]:
            cost = cost_init - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1])
            print(cost)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0]+a+[0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])
 
    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

Submission status: Accepted

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

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

for i in range(1, N + 1):
    l, m, r = A[i - 1], A[i], A[i + 1]
    d = dist
    d -= abs(l - m)
    d -= abs(r - m)
    d += abs(r - l)
    print(d)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
cuml = [0]
for a,b in zip(A,A[1:]):
    cuml.append(cuml[-1] + abs(a-b))
cumr = [cuml[-1]-c for c in cuml[::-1]][::-1]

ans = [cuml[i] + cumr[i+2] + abs(A[i] - A[i+2]) for i in range(N)]
print(*ans, sep='\n')

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(n+1):
    total += abs(a[i+1] - a[i])

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, 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):
    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()))

route=[0]+A+[0]
dis=0

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

for j in range(1,N+1):
    if (route[j-1]<=route[j] and route[j]<=route[j+1]) or (route[j+1]<=route[j] and route[j]<=route[j-1]):
        print(dis)
    elif (route[j-1]<=route[j+1] and route[j+1]<=route[j]) or (route[j]<=route[j+1] and route[j+1]<=route[j-1]):
        print(dis-abs(route[j+1]-route[j])*2)
    else:
        print(dis-abs(route[j-1]-route[j])*2)

Submission status: Accepted

Solution code:
N=int(input())
from collections import deque
l=deque(map(int,input().split()))
l.appendleft(0)
l.append(0)
S=[abs(l[i]-l[i+1]) for i in range(N+1)]
S_sum=sum(S)
for i in range(N):
   print(S_sum-S[i]-S[i+1]+abs(l[i]-l[i+2]))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc093/tasks/arc093_a
from copy import deepcopy
n = int(input())

nums = [int(i) for i in input().split()]

diff = []
for i in range(n):
    if i == 0:
        diff.append(abs(nums[i]))
    else:
        diff.append(abs(nums[i] - nums[i - 1]))
total = sum(diff) + abs(nums[-1])
for i in range(n):
    if i == n - 1:
        t = total - (diff[-1] + abs(nums[-1])) + abs(nums[-2])
    else:
        if i == 0:
            t = total - abs(nums[i]) - diff[i + 1] + abs(nums[i + 1])
        else:
            t = total - (diff[i] + diff[i + 1]) + abs(nums[i - 1] - nums[i + 1])
    print(t)

Submission status: Accepted

Solution code:
import collections
import numpy as np
import sys
import copy
N=int(input())
#W,H,X,Y=map(int,input().split())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
    B[i]=abs(A[i+1]-A[i])
A=[0]+A+[0]
B=[abs(A[1])]+B+[abs(A[-2])]
tot=sum(B)
for i in range(1,N+1):
    if (A[i+1]-A[i])*(A[i]-A[i-1])>=0:
        print(tot)
    else:
        print(tot-min(B[i-1],B[i])*2)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = [0]+iil()+[0]

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

for i in range(1,n+1):
    minus = abs(A[i]-A[i-1])+abs(A[i+1]-A[i])
    plus = abs(A[i+1]-A[i-1])
    print(cst+plus-minus)

Submission status: Accepted

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

a_ = 0
total = 0
for a in A:
    total += abs(a_ - a)
    a_ = a

b = 0
for i, a in enumerate(A[:-1]):
    c = A[i+1]
    ans = total - abs(b - a) - abs(c - a) + abs(c - b)
    print(ans)
    b = a

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np
import sys
input = sys.stdin.readline
import math

n=int(input())
a = [0]
a += (list(map(int,input().split())))
a += [0]
b = np.array([ abs(a[i] - a[i+1]) for i in range(n+1)])
c = sum(b)
d = np.array([ abs(a[i] - a[i+2]) for i in range(n)])
e = np.array([])
e = [(c - b[j] - b[j+1] + d[j]) for j in range(n) ]
for i in range(n):
    print(e[i])

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
count=abs(l[0])
for ii in range(1,n):
    count+=abs(l[ii]-l[ii-1])
count+=abs(l[n-1])
suml=count  
for j in range(n):
    if j==0:
        print(suml-abs(l[0])-abs(l[1]-l[0])+abs(l[1]))
    elif j!=n-1:
        print(suml-abs(l[j]-l[j-1])-abs(l[j+1]-l[j])+abs(l[j+1]-l[j-1]))
    else:
        print(suml-abs(l[n-1]-l[n-2])-abs(l[n-1])+abs(l[n-2]))

Submission status: Accepted

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

cost_li = [0]*(n+1)
cost_li[0]=a_input[1]
cost_li[-1]=abs(a_input[-2])

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

sum_cost = sum(cost_li)

for i in range(1,n+1):
    ans = sum_cost-cost_li[i-1]-cost_li[i]+abs(a_input[i+1]-a_input[i-1])
    print(ans)

Submission status: Accepted

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

dist = []
for i in range(1, len(A)):
    dist.append(abs(A[i] - A[i-1]))

total = sum(dist)

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

Submission status: Accepted

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

S = np.sum(np.abs(np.diff(A)))
for i in range(1, N+1):
    print(int(S+np.abs(A[i-1]-A[i+1])-(np.abs(A[i-1]-A[i])+np.abs(A[i]-A[i+1]))))

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = collections.deque(list(map(int, input().split())))
A.appendleft(0)
A.append(0)

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

travel_sum = sum(ac)
for i in range(N):
    # 訪れるのを取りやめた観光スポットの前後の移動金額を合計から引く
    ans = travel_sum-(ac[i]+ac[i+1])

    # 取りやめたことで発生する移動金額を加算する
    ans += abs(A[i]-A[i+2])
    print(ans)

Submission status: Accepted

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

ls = [0] + A + [0]

ls2 = [0] * (N+1)
for n in range(N+1):
  ls2[n] = abs(ls[n+1]-ls[n])

sum_ls2 = sum(ls2)
for n in range(N):
  print(sum_ls2 - ls2[n] - ls2[n+1] + abs(ls[n+2]-ls[n]))

Submission status: Accepted

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

cost=0
pre=0
for i in range(n+2):
    cost+=abs(a[i]-pre)
    pre=a[i]
#print(a,cost)
for i in range(n):
    if (a[i]-a[i+1])*(a[i+1]-a[i+2])<0:
        print(cost-2*(min(abs(a[i]-a[i+1]),abs(a[i+1]-a[i+2]))))
    else:
        print(cost)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 15:59:37 2020

@author: shinba
"""
from collections import deque

n = int(input())
A = deque(map(int,input().split()))

A.appendleft(0)
A.append(0)

B = []

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

s = sum(B)

for i in range(n):
    sub =  B[i] + B[i+1] - abs(A[i+2]-A[i])
    if sub == 0:
        print(s)
    else:
        print(s-sub)

Submission status: Accepted

Solution code:
n=int(input())
a = [0]+list(map(int,input().split()))+[0,0]
x = abs(a[1])
z = abs(a[2])
aa = list()
p=x#sum
for i in range(1,n+1):
    k = a[i]
    y=abs(a[i+1]-k)
    aa.append(x+y-z)
    x = y
    z = abs(a[i+2]-k)
    p+=y
print('\n'.join([str(p-i) for i in aa]))

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

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

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

    for i in range(1, len(a) - 1):
        smaller = min(a[i - 1], a[i + 1])
        current = a[i]
        larger = max(a[i - 1], a[i + 1])

        if smaller <= current <= larger:
            print(total)
        elif current < smaller:
            print(total - abs(current - smaller) * 2)
        elif current > larger:
            print(total - abs(current - larger) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
ar.append(0)
ar.insert(0,0)
mx = 0
for i in range(1,len(ar)):
    mx += abs(ar[i] - ar[i-1])
for i in range(1,len(ar) - 1):
    mi = mx
    mi -= abs(ar[i-1] - ar[i])
    mi -= abs(ar[i] - ar[i+1])
    mi += abs(ar[i-1] - ar[i+1])
    print(mi)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    sum_B = sum(B)
    ans = [0] * N
    for i in range(N):
        ans[i] = sum_B - (B[i] + B[i + 1]) + abs(A[i + 2] - A[i])

    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(readline())
    A = [0] + list(map(int, readline().split())) + [0]
    total = 0
    for i in range(N+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]))






if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
bbefore=0
before=a.pop(0)
s=abs(before-bbefore)
lst=[]
for i in a:
   s+=abs(i-before)
   lst.append(abs(i-before)+abs(before-bbefore)-abs(i-bbefore))
   bbefore=before
   before=i
for i in lst:
   print(s-i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1]))

Submission status: Accepted

Solution code:
def modelAnswer(N:int,A:list) -> None:
   total = 0
   for j in range(N-1):
      total += abs(A[j] - A[j+1])
   total += abs(A[0]) + abs(A[N-1])
   for i in range(N):
      p = 0 if(i == 0) else A[i-1]
      n = 0 if(i == N - 1) else A[i + 1]
      print(total + abs(p - n) - (abs(p - A[i])+ abs(A[i] - n)))
def main():
   N = int(input())
   A = list(map(int,input().split()))
   modelAnswer(N,A[:])
if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))
travel1 = [abs(arrA[0])]
travel2 = [abs(arrA[1])]
for i in range(N-1):
    travel1.append(abs(arrA[i]-arrA[i+1]))
    if i <N-2:
        travel2.append(abs(arrA[i]-arrA[i+2])) 
    else:
        travel2.append(abs(arrA[i])) 
travel1.append(abs(arrA[N-1]))

sums = sum(travel1)

for i in range(N):
    print(sums-travel1[i]-travel1[i+1]+travel2[i])
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

S = [0] * (N + 1)
S[0] = abs(A[0])
for i, a in enumerate(A[1:]):
    S[i + 1] += abs(a - A[i])
S[-1] = abs(A[-1])

s = sum(S)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

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

Submission status: Accepted

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

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

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

bs=abs(a[0])
bl=abs(a[n-1])
sum=sum(b)+bs+bl

if 0<=a[0]<=a[1] or 0>=a[0]>=a[1]:
  print(sum)
else:
  print(sum-b[0]-bs+abs(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(sum)
  else:
    print(sum-b[i-1]-b[i]+abs(a[i+1]-a[i-1]))
    
if a[n-2]<=a[n-1]<=0 or a[n-2]>=a[n-1]>=0:
  print(sum)
  
else:
  print(sum-b[n-2]-bl+abs(a[n-2]))

Submission status: Accepted

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

a.insert(0,0)
a.append(0)
d = [abs(a[i]-a[i+1]) for i in range(n+1)]
s = sum(d)
for i in range(1,n+1):
    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 = [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(1, N+1):
    T = S - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])
    print(T)