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:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))
######################################################################################################
def main():
    n=int(input())
    A=inputintlist()
    ssum=abs(0-A[0])+abs(0-A[-1])
    for a in range(n-1):
        ssum+=abs(A[a]-A[a+1])
    A=[0]+A+[0]
    for a in range(1,n+1):
        ans=ssum-(abs(A[a]-A[a-1])+abs(A[a]-A[a+1]))+abs(A[a-1]-A[a+1])
        print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import chain


def cost(p1, p2):
    return abs(p1 - p2)


input()
points = tuple(chain.from_iterable(([0], tuple(map(int, input().split(' '))), [0])))

base_cost = sum([cost(p, pre_p) for pre_p, p in zip(points, points[1:])])

for pre_p, p, next_p in zip(points, points[1:], points[2:]):
    diff = cost(pre_p, next_p) - cost(pre_p, p) - cost(p, next_p)
    print(base_cost + diff)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
D = B[1:] + B[:-1]
total = B.sum()
for i in range(N):
    print(total - D[i] + C[i])

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
total = B.sum()
for i in range(N):
    print(total - B[i:i + 2].sum() + C[i])

Submission status: Accepted

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

distances = []

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

S = sum(distances)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]+list(map(int, input().split()))+[0]
cost = []
for i in range(N+1):
    cost.append(abs(A[i]-A[i+1]))
sum_cost = sum(cost)
for i in range(1,N+1):
    print(sum_cost+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]
pre = 0
yen = sum(abs(i - j) for i, j in zip(A, A[1:]))
ans = [yen] * N
for i in range(N):
    ans[i] += -abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2])
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in 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:
def main():
    m, *a = map(int, open(0).read().split())
    a = [0] + a + [0]
    s = 0
    p = [abs(i - j) for i, j in zip(a, a[1:])]
    s = sum(p)
    t = [str(s - abs(i - j) - abs(j - k) + abs(k - i)) for i, j, k in zip(a, a[1:], a[2:])]
    ans = "\n".join(t)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

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

    max = 0

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

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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

Submission status: Accepted

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

cost = []

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

s_cost = sum(cost)
for i in range(n):
  print(s_cost - cost[i]- cost[i+1] + abs(a[i+2]-a[i]))

Submission status: Accepted

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

lst = []
before = 0
for num in a:
    lst.append(abs(num - before))
    before = num
total = sum(lst)
for i in range(n):
    if i == 0:
        print(total - lst[i] - lst[i + 1] + abs(a[i+1]))
    else:
        print(total - lst[i] - lst[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]
s=0
for i in range(n+1):
    s+=abs(a[i]-a[i+1])
ans=0
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 = [0] + [int(i) for i in input().split()] + [0]
d1a = [abs(a[i + 1] - a[i]) for i in range(n + 1)]
d2a = [abs(a[i + 1] - a[i - 1]) for i in range(1, n + 1)]
sum_a = sum(d1a)
for i in range(1, n + 1):
    print(sum_a + d2a[i - 1] - (d1a[i - 1] + d1a[i]))

Submission status: Accepted

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

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

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:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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+1]-A[i]) - abs(A[i+2]-A[i+1]) + abs(A[i+2]-A[i]))

Submission status: Accepted

Solution code:
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
data = [0] + a + [0]
total = 0
for i in range(n+1):
    total += abs(data[i]-data[i+1])

ans = 0
for i in range(1, n+1):
    ans = total+abs(data[i-1]-data[i+1]) - \
        abs(data[i]-data[i+1])-abs(data[i-1]-data[i])
    print(ans)

Submission status: Accepted

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

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

    ans = []
    for i in range(1,N+1):
        res = sm - (abs(A[i]-A[i-1])+abs(A[i+1]-A[i])) + abs(A[i+1]-A[i-1])
        ans.append(res)

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

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

    for i in range(N):
        l1=A[i+1]-A[i]
        l2=A[i+2]-A[i]
        l3=A[i+2]-A[i+1]
        print(S-abs(abs(l2)-(abs(l3)+abs(l1))))
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in 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):
  tmp = [A[i-1],A[i],A[i+1]]
  tmp.sort()
  ans = 0
  if tmp[1] == A[i]:
    ans = S
  elif tmp[2] == A[i]:
    ans = S- (tmp[2]-tmp[1])*2
  else:
    ans = S - (tmp[1]-tmp[0])*2
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
total = np.abs(np.diff(A)).sum()
saved = np.abs(A[1:-1]-A[:-2])+np.abs(A[1:-1]-A[2:])-np.abs(A[:-2]-A[2:])
answer = total - saved
print(*answer, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

S = 0
for i in range(n+1):
    S += abs(a_ls[i] - a_ls[i+1])
for i in range(1,n+1):
    ans = S + abs(a_ls[i+1] - a_ls[i-1]) - (abs(a_ls[i-1] - a_ls[i]) + abs(a_ls[i] - a_ls[i+1]))
    print(ans)

Submission status: Accepted

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

sum_pay = sum(pay)
for j in range(1,N+1):
  print(sum_pay + (abs(A[j-1] - A[j+1]) - abs(A[j-1] - A[j]) - abs(A[j] - A[j+1])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

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

    arr = [0]
    arr.extend(a)
    arr.append(0)
    total = sum([abs(arr[i-1] - arr[i]) for i in range(1, n+2)])

    for i in range(1, n+1):
        #print(abs(arr[i-1] - arr[i]), abs(arr[i-1] - arr[i+1]))
        ans = total - abs(arr[i-1] - arr[i]) - abs(arr[i] - arr[i+1]) + abs(arr[i-1] - arr[i+1])
        print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

for i in range(n):
    print(ans[i])

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

q = [0] * (n + 2)
SUM = 0
for i in range(n + 1):
    temp = abs(cost[i + 1] - cost[i])
    SUM += temp
    q[i] += temp
    q[i + 1] += temp
#print(SUM)

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

Submission status: Accepted

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

    t += abs(a[i] - a[i-1])


t += abs(a[-1])


before = 0
for i,now in enumerate(a):

    if i == n-1:
        after = 0
    else:
        after = a[i+1]


    if before <= now <= after or after <= now <= before:
        dis.append(0)
    elif before <= after <= now or now <= after <= before:
        dis.append(2 * abs(now - after))
    else:
        dis.append(2 * abs(now - before))
    before = now

for i, d in enumerate(dis):
    print(t-d)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = [0] + [int(_) for _ in input().split()] + [0]
  l = 0
  for i in range(N+1):
    l += abs(A[i+1] - A[i])
  for i in range(1, N+1):
    print(l - 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())
l = [0]+list(map(int,input().split()))+[0]
s = 0
for j in range(len(l)-1):
    s += abs(l[j+1]-l[j])
for i in range(1,n+1):
  a = l[i-1]
  b = l[i]
  c = l[i+1]
  if a<=b<=c:
    print(s)
  elif a<=c<=b:
    print(s-2*(b-c))
  elif b<=a<=c:
    print(s-2*(a-b))
  elif b<=c<=a:
    print(s-2*(c-b))
  elif c<=a<=b:
    print(s-2*(b-a))
  elif c<=b<=a:
    print(s)

Submission status: Accepted

Solution code:
# solution

import io
import sys

data = int(input())
array = [0] + [int(x) for x in input().split()] + [0]

cnt = sum(abs(array[i+1] - array[i]) for i in range(data+1))

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc092/tasks/arc093_a
# 16:37-16]53 done


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

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

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

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

    print(S[N-2]+abs(A[N-2]))


main()

Submission status: Accepted

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

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

al=0
#print(a)

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

for j in range(n):
    t=(abs(a[j]-a[j+1])+abs(a[j+1]-a[j+2]))-(abs(a[j]-a[j+2]))
    print(al-t)

Submission status: Accepted

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

Submission status: Accepted

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

tmp = abs(a[0])

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

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

total = 0
now = 0
skip = {}

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

for i in range(N):
    # print(total, skip[i])

    print(total+skip[i])

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]-a[i+1])
for i in range(1,n+1):
  s=sorted(a[i-1:i+2])
  if a[i]==s[0]:
    print(ans-(s[1]-s[0])*2)
  elif a[i]==s[2]:
    print(ans-(s[2]-s[1])*2)
  else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    r = 0
    r += abs(A[0])
    for i in range(N - 1):
        r += abs(A[i] - A[i + 1])
    r += abs(A[-1])
    for i in range(N):
        pp = (0 if i == 0 else A[i - 1])
        np = (0 if i == N - 1 else A[i + 1])
        print(r - abs(A[i] - pp) - abs(A[i] - np) + abs(pp - np))


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
alist=list(map(int,input().split()))
a2list=[0]+alist+[0]
#print(a2list)

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

for i in range(N):
  dist=alldist-abs(a2list[i+1]-a2list[i])-abs(a2list[i+2]-a2list[i+1])+abs(a2list[i+2]-a2list[i])
  print(dist)

Submission status: Accepted

Solution code:
N=int(input())
alist=list(map(int,input().split()))
a2list=[0]+alist+[0]
#print(a2list)

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

for i in range(N):
  if a2list[i+1]-a2list[i]>=0 and a2list[i+2]-a2list[i+1]>=0:
    print(alldist)
  elif a2list[i+1]-a2list[i]<=0 and a2list[i+2]-a2list[i+1]<=0:
    print(alldist)
  else:
    dist=alldist-abs(a2list[i+1]-a2list[i])-abs(a2list[i+2]-a2list[i+1])+abs(a2list[i+2]-a2list[i])
    print(dist)

Submission status: Accepted

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



# 0 3 5 -1 0
# 0 5 -1 0
# 0 3 -1 0
# 0 3 5 0

Submission status: Accepted

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

A = [0] + A + [0] # 数はN+2こ
kane = []
for i in range(1, N+2):
    kane.append(abs(A[i] - A[i-1]))
skane = sum(kane)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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(1,n+1):
        print(S - abs(A[i-1]-A[i])-abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]))


if __name__ == '__main__':
    main()