Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

2 \leq N \leq 10^5

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

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

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

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

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

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

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

Sample Output 3

21630
21630
19932
8924
21630
19288



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Accepted

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

# 総コスト
cost = 0
for i in range(n+1):
    cost += abs(A[i+1] - A[i])


for i in range(n):
    c = cost
    if A[i] < A[i+1] and A[i+1] < A[i+2]:
        print(c)
    elif A[i] > A[i+1] and A[i+1] > A[i+2]:
        print(c)
    else:
        c -= (abs(A[i+1] - A[i]) + abs(A[i+2]-A[i+1])) - abs(A[i+2] - A[i])
        print(c)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

A = [0] + A + [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):
    left = acc[i] - acc[0]
    right = acc[N + 1] - acc[i + 2]
    print(left + abs(A[i + 2] - A[i]) + right)

Submission status: Accepted

Solution code:
n=input()
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print(ans if l[i+1]<l[i] else ans+dif)
  else:print(ans if l[i+1]>l[i] else ans+dif)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = [0] + readInts() + [0]
dist = 0
for i in range(len(A)-1):
    dist+=abs(A[i] - A[i+1])

for i in range(1,len(A)-1):
    print(dist - (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]

d = [x - y for y, x in zip(A[:-1], A[1:])]
dist = sum(abs(i) for i in d)

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

Submission status: Accepted

Solution code:
n = int(input())
al = [0] + list(map(int, input().split())) + [0]
csum = 0
for a0,a1 in zip(al[:-1], al[1:]):
    v = abs(a1-a0)
    csum += v

ansl = []
for a0,a1,a2 in zip(al[:-2], al[1:-1], al[2:]):
    if a0 <= a1 <= a2 or a2 <= a1 <= a0:
        ansl.append(csum)
    elif a0 <= a1 and a1 >= a2:
        ansl.append(csum-(a1-max(a0,a2))*2)
    else:
        ansl.append(csum -(min(a2,a0)-a1)*2)

for a in ansl: print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
x = [0]
for i in range(len(A)-1):
    x.append(abs(A[i]-A[i+1]))
ans = sum(x)
for i in range(1, n+1):
    print(ans - (x[i]+x[i+1]) + abs(A[i-1]-A[i+1]))

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  S=abs(A[0])+abs(A[N-1])
  for i in range(N-1):
    S+=abs(A[i]-A[i+1])
  c=0
  for j in range(N-1):
    print(S-abs(c-A[j])-abs(A[j]-A[j+1])+abs(c-A[j+1]))
    c=A[j]
  print(S-abs(c-A[N-1])-abs(A[N-1])+abs(c))
  return 
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = [0] + LI() + [0]

    tot = 0
    for i in range(1, len(A)):
        tot += abs(A[i]-A[i-1])
    # print(tot)

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

A = [0] + A + [0]

s = 0

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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


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

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

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

Submission status: Accepted

Solution code:
import numpy

N = int(input())
p = [int(x) for x in input().split()]
p = [0] + p + [0]

S = numpy.sum(numpy.abs(numpy.diff(p)))

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
s=[0,*A,0]
x=[abs(s[i]-s[i-1]) for i in range(1,len(s))]
S=sum(x)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
new_a = [0] + a + [0]
total_distance = 0
for i in range(1, len(new_a)):
    distance = new_a[i] - new_a[i-1]
    total_distance += abs(distance)
for j in range(1, len(new_a) - 1):
    ans = total_distance - abs(new_a[j] - new_a[j-1]) - \
        abs(new_a[j+1] - new_a[j]) + abs(new_a[j + 1] - new_a[j-1])
    print(ans)

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):
  print(cost - 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 = [0] + list(map(int,input().split())) + [0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

A = [0] + A + [0]


base_lis = []
Sum = 0

for i in range(len(A)-1):
    number = abs(A[i]-A[i+1])
    base_lis.append(number)
    Sum = number + Sum

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

diff1 = []
diff2 = []
sum1 = 0
for i in range(n+1):
    sum1 += abs(L[i+1]-L[i])
    diff1.append(abs(L[i+1]-L[i]))

for i in range(n):
    diff2.append(abs(L[i+2]-L[i]))

for i in range(n):
    ans = sum1-(diff1[i]+diff1[i+1]) + diff2[i]
    print(ans)

Submission status: Accepted

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

s = 0

for i in range(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())
ls = list(map(int, input().split()));
# 先頭と末尾に0を追加（a0とaN+1)
a_list = [0] + ls + [0];
# 全てを経由した時の合計Sを求める
S = 0;
for i in range(N + 1):
  	# |Aj - Aj+1|を足し合わせる
  	S += abs(a_list[i] - a_list[i+1]);
    
# Sを使って各Siを求め、出力
# Si = S + （不連続部分） - （不連続に置き換わる連続部分）
#    = S + |Ai-1 - Ai+1| - (|Ai-1 - Ai| + |Ai - Ai+1|)
for i in range(N):
	Si = S + abs(a_list[i] - a_list[i + 2]) - (abs(a_list[i] - a_list[i + 1]) + abs(a_list[i + 1] - a_list[i + 2]));
	print(Si);

Submission status: Accepted

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

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

for i in range(1, N+1):
    ret = distance + abs(A[i-1]-A[i+1]) - (abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))
    Ret.append(ret)

for r in Ret:
    print(r)

Submission status: Accepted

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

total_cost = 0
cost = [0] * (N+1)

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

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

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(1,N+2):
  S+=abs(A[i]-A[i-1])

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 = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    A = [0] + A + [0]
    N = len(A)
    return N, A


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


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
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:
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,a):
  tripCourse = [0] + a + [0]
  wholeSum = sum(abs(tripCourse[i+1] - tripCourse[i]) for i in range(n+1))
  res = [wholeSum]*n
  for i in range(n):
    res[i] -= abs(tripCourse[i+1] - tripCourse[i+2]) + abs(tripCourse[i] - tripCourse[i+1]) - abs(tripCourse[i+2]-tripCourse[i])
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  ans = solve(N,a)
  for i in range(N):
    print(ans[i])
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
now = 0
dis = 0
for i in A:
    dis += abs(now-i)
    now = i
ans = dis+abs(now)
B = [0]
B.extend(A)
B.append(0)
for i in range(1,N+1):
    if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:
        print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))
    else:
        print(ans)

Submission status: Accepted

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

#print(total)
for i in range(N):
  if i == 0:
    temp = -abs(A[0]-0)-abs(A[0]-A[1])+abs(A[1]-0)
    #print(temp)
  elif i == N-1:
    temp = -abs(A[i]-0)-abs(A[i]-A[i-1])+abs(A[i-1]-0)
  else:
    temp = -abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i+1]-A[i-1])
  ans = total+temp
  print(ans)

Submission status: Accepted

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

B = [0]

B = B+A+[0]

count = 0

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

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = [0]+list(map(int, input().split()))+[0]
a = []
for i in range(n+1):
    a.append(abs(A[i]-A[i+1]))
ans = sum(a)
for i in range(i):
    print(ans-a[i]-a[i+1]+abs(A[i]-A[i+2]))

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = tuple([0,] + list(map(int, input().split())) + [0,])
D = []
sum = 0
for i, a in enumerate(A[1:-1]):
  i += 1
  pre = A[i - 1]
  tem = A[i]
  nex = A[i + 1]
  x = abs(pre - tem)
  y = abs(tem - nex)
  sum += x
  D.append(abs(pre - nex) - x - y)
sum += y
for d in D:
  print(sum + d)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
a = [0] + a + [0]
s = 0
for i in range(n + 1):
    s += abs(a[i] - a[i + 1])
for i in range(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:
spot_num = int(input())
spot_place = [ int(p) for p in input().split(" ") ]
diff_table = []
max_num = 0

for i in range(spot_num):
  if i == 0:
    max_num += abs(spot_place[0] - 0)
    diff_table.append(abs(spot_place[1] - 0) - \
    (abs(spot_place[0] - 0) + abs(spot_place[1] - spot_place[0])))
  elif i == spot_num-1:
    diff_table.append(abs(0 - spot_place[i-1]) - \
    (abs(spot_place[i] - spot_place[i-1]) + abs(0 - spot_place[i])))
    max_num += abs(spot_place[i] - spot_place[i-1])
  else:
    diff_table.append(abs(spot_place[i+1] - spot_place[i-1]) - \
    (abs(spot_place[i] - spot_place[i-1]) + abs(spot_place[i+1] - spot_place[i])))
    max_num += abs(spot_place[i] - spot_place[i-1])
    
max_num += abs(0 - spot_place[spot_num-1])

for i in range(spot_num):
  print(max_num+diff_table[i])

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
        
def main():
    plan=[0]
    n = int(input())
    plan+=list(map(int,input().split()))
    plan.append(0)
    pay_sum = 0
    for i in range(1,n+2):
        pay_sum += abs(plan[i] - plan[i-1])
    
    for i in range(1,n+1):
        result = abs(plan[i-1] - plan[i+1])
        result -= abs(plan[i-1] - plan[i])
        result -= abs(plan[i+1] - plan[i])
        print(pay_sum + result)

if __name__=="__main__":
    main()

Submission status: Accepted

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


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    A = [0] + A + [0] ## append start and goal (1-indexed table)
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for i in range(1,n+1):
        _sum += abs(prev - A[i])
        prev = A[i]
        diff[i-1] = abs(A[i-1] - A[i+1]) - (abs(A[i]-A[i-1]) + abs(A[i+1] - A[i]))
    ## add the cost until goal.
    _sum += abs(A[n])
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for idx, a in enumerate(A):
        _sum += abs(prev - a)
        prev = a
        if idx == 0:
            diff[idx] = abs(0 - A[1]) - (abs(a-0) + abs(a - A[1]))
        elif idx < n - 1:
            diff[idx] = abs(A[idx - 1] - A[idx + 1]) - (abs(a - A[idx - 1]) + abs(a - A[idx + 1]))
        elif idx == n - 1:
            diff[idx] = abs(A[idx - 1] - 0) - (abs(a - A[idx - 1]) + abs(a - 0))
    _sum += abs(a)
    
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    A.insert(0, 0)
    A.append(0)
    sumA = 0
    for i in range(n+1):
        sumA += abs(A[i+1] - A[i])

    for i in range(n):
        ansA = sumA - abs(A[i+1] - A[i]) - \
            abs(A[i + 2] - A[i + 1]) + abs(A[i + 2] - A[i])
        print(ansA)


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(n + 1):
    ans += 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(ans)
    else:
        print(ans - 2*min(abs(A[i-1] - A[i]), abs(A[i+1] - A[i])))

Submission status: Accepted

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

for i in range(1,N+1):
    print(dist[i])

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

Submission status: Accepted

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

Submission status: Accepted

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

X=0
for i in range(1,N+2):
    X+=abs(A[i]-A[i-1])
    
S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=X-(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1])
print("\n".join(map(str,S[1:])))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = [0] + readInts() + [0]
pa = 0
for i in range(n+1):
    pa += abs(A[i+1] - A[i])
#print(pa)
for i in range(n):
    print(pa - 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 = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
print(tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2]))
for i in range(2,N):
    print(tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
print(tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1]))

Submission status: Accepted

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

Submission status: Accepted

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

A = [0]+A+[0]

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

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

Submission status: Accepted

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

rlt = 0
lst = []

for i in range(N+1):
  rlt += abs(As[i+1]-As[i])
  
for i in range(1,N+1):
  print(rlt-abs(As[i]-As[i-1])-abs(As[i+1]-As[i])+abs(As[i+1]-As[i-1]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [0] + [int(x) for x in input().split()] + [0]
    sm = 0
    for i in range(n+1):
        sm += abs(a[i] - a[i+1])

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

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [0] + [int(item) for item in input().split()] + [0]
    
    all_sum = 0
    prev = 0
    for i in range(N+2):
        all_sum += abs(As[i] - prev)
        prev = As[i]

    prev = As[0]
    for i in range(N):
        print(all_sum + abs(As[i] - As[i+2]) - (abs(As[i]-As[i+1]) + abs(As[i+1] - As[i+2])))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())

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

B = [0] + A + [0]

diff_1 = [abs(B[i+1] - B[i]) for i in range(N+1)]
diff_2 = [abs(B[i+2] - B[i]) for i in range(N)]
ans = sum(diff_1)

for i in range(N):
    tmp = ans + diff_2[i] - (diff_1[i] + diff_1[i+1])
    print(tmp)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

# In[19]:


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


# In[22]:


a0 = [0]+A+[0]
cost_all = sum([abs(a0[i+1]-a0[i]) for i in range(N+1)])
for i in range(N):
    diff = abs(a0[i+2]-a0[i])-(abs(a0[i+1]-a0[i])+abs(a0[i+2]-a0[i+1]))
    ans = cost_all + diff
    print(ans)


# In[ ]:

Submission status: Accepted

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

#%%
A = [0] + A
A.append(0)
#%%
diff = [abs(A[i] - A[i+1]) for i in range(len(A)-1)]
diff2 = [abs(A[i] - A[i+2]) for i in range(len(A)-2)]
total = sum(diff)

for i in range(n):
    ans = total - sum(diff[i:i+2]) + diff2[i]
    print(ans)

Submission status: Accepted

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

#%%
A = [0] + A
A.append(0)

diff = [abs(A[i] - A[i+1]) for i in range(len(A)-1)]
diff2 = [abs(A[i] - A[i+2]) for i in range(len(A)-2)]
total = sum(diff)

for i in range(n):
    ans = total - (diff[i] + diff[i+1]) + diff2[i]
    print(ans)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
a.appendleft(0)
a.append(0)
a=list(a)
#print(a)
#全部回った場合
tot=0
for i in range(1,n+2):
    tot+=abs(a[i]-a[i-1])
#print(tot,a)
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(tot)
    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]

g = [0]*(N+1)

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

s = sum(g)

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