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

def a(i):
    if 0 <= i < N:
        return A[i]
    else:
        return 0

base = 0
for i in range(N + 1):
    base += abs(a(i) - a(i - 1))

for i in range(N):
    print(base - 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 = [int(v) for v in input().split()]
a.append(0)

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

ans = []
if a[0] < 0 <= a[1] or a[0] > 0 >= a[1]:
    ans.append(all_sum - abs(a[0]) * 2)
elif 0 <= a[0] <= a[1] or 0 >= a[0] >= a[1]:
    ans.append(all_sum)
else:
    ans.append(all_sum - abs(a[0] - a[1]) * 2)

for i in range(n-1):
    if a[i+1] < a[i] <= a[i+2] or a[i+1] > a[i] >= a[i+2]:
        ans.append(all_sum - abs(a[i] - a[i+1]) * 2)
    elif a[i] <= a[i+1] <= a[i+2] or a[i] >= a[i+1] >= a[i+2]:
        ans.append(all_sum)
    else:
        ans.append(all_sum - abs(a[i+1] - a[i+2]) * 2)

for line in ans:
    print(line)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
listA = list(map(int, input().split()))
sumOriginal =0
index =0
while index<len(listA):
    if index == 0:
        sumOriginal+=(max(listA[index], 0)-min(listA[index], 0))
    elif index == len(listA)-1:
        sumOriginal+=(max(listA[index], 0)-min(listA[index], 0))
        sumOriginal+=(max(listA[index], listA[index-1])-min(listA[index], listA[index-1]))
    else:
        sumOriginal+=(max(listA[index], listA[index-1])-min(listA[index], listA[index-1]))
    index+=1

index2=0
listForAnswer =[]
while index2<len(listA):
    sumAnswer=0
    if index2 ==0:
        sumAnswer = sumOriginal-(max(listA[index2], 0)-min(listA[index2], 0))
        sumAnswer-=(max(listA[index2], listA[index2+1])-min(listA[index2], listA[index2+1]))
        sumAnswer+=(max(listA[index2+1], 0)-min(listA[index2+1], 0))
    elif index2 ==len(listA)-1:
        sumAnswer =sumOriginal-(max(listA[index2], 0)-min(listA[index2], 0))
        sumAnswer-=(max(listA[index2], listA[index2-1])-min(listA[index2], listA[index2-1]))
        sumAnswer+=(max(listA[index2-1], 0)-min(listA[index2-1], 0))
    else:
        sumAnswer =sumOriginal-(max(listA[index2], listA[index2+1])-min(listA[index2], listA[index2+1]))
        sumAnswer-=(max(listA[index2], listA[index2-1])-min(listA[index2], listA[index2-1]))
        sumAnswer+=(max(listA[index2-1], listA[index2+1])-min(listA[index2-1], listA[index2+1]))
    listForAnswer.append(sumAnswer)
    index2+=1

for ans in listForAnswer:
    print(ans)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
d=[]
tmp=0
for i,j in enumerate(a):
    if i==0:
        tmp+=abs(j)
        d.append(((abs(j)+abs(a[i]-a[i+1])),abs(a[i+1])))
    elif i==n-1:
        tmp+=abs(a[i-1]-a[i])+abs(j)
        d.append((abs(a[i-1]-a[i])+abs(j),abs(a[i-1])))
    else:
        f=abs(a[i]-a[i-1])
        tmp+=f
        d.append((abs(a[i-1]-a[i])+abs(a[i]-a[i+1]),abs(a[i-1]-a[i+1])))

for i in d:
    print(tmp-i[0]+i[1])

Submission status: Accepted

Solution code:
N = int(input())
p_l = [0] + [int(i) for i in input().split()] + [0]
s0 = 0
ans = ''

for i in range(N+1):
	s0 += abs(p_l[i+1] - p_l[i])

for i in range(1, N+1):
	s = s0 - abs(p_l[i+1]-p_l[i]) - abs(p_l[i]-p_l[i-1]) + abs(p_l[i+1]-p_l[i-1])
	ans += str(s)+'\n'

print(ans[:-1])

Submission status: Accepted

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

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])
#print(s)
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:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
aa = inpl()
S = 0
ba = 0
for a in aa:
	S += abs(a-ba)
	ba = a
S += abs(ba)

aa = [0] + aa + [0]
for i in range(1,N+1):
	l,m,r = aa[i-1],aa[i],aa[i+1]
	bc = abs(m-l)+abs(r-m)
	nc = abs(r-l)
	print(S-bc+nc)

Submission status: Accepted

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

aa = [0]+a+[0]

b=[]

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

c = sum(b)

for i in range(n):
    ans = c-b[i]-b[i+1]+abs(aa[i+2]-aa[i])
    print(ans)

Submission status: Accepted

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

A = [0] + A + [0]

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

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
sm = 0
x = 0
for _a in a:
  sm += abs(_a - x)
  x = _a
for i in range(1,n + 1):
  print(sm - 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]
diff = [A[i + 1] - A[i] for i in range(N + 1)]
ans = sum([abs(diff[i]) for i in range(N + 1)])
for i in range(N):
    if diff[i] * diff[i + 1] < 0:
        print(ans - 2 * min(abs(diff[i]), abs(diff[i + 1])))
    else:
        print(ans)

Submission status: Accepted

Solution code:
n = int(input())
roads = list(map(int, input().split()))
cost_total = 0
tmp = 0
roads = [0] + roads
roads.append(0)
for i in range(1, n+1):
    cost_total += abs(roads[i] - tmp)
    tmp = roads[i]
cost_total += abs(roads[n])
l = 0
c = roads[1]
for i in range(n):
    ans = cost_total
    r = roads[i+2]
    ans = ans + abs(r-l) - abs(r-c) - abs(c-l)
    print(ans)
    l, c = c, r

Submission status: Accepted

Solution code:
N = int(input())
a_list = [a for a in map(int, input().split())]
a_list.insert(0, 0)
a_list.append(0)
S = 0
before = 0
for a in a_list:
    S += abs(a - before)
    before = a

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]
B = list(map(int, input().split()))
for i in range(len(B)):
    A.append(B[i])
A.append(0)
S = []
cost = 0
pos = 0
for i in range(1, N + 1):
    cost += abs(A[i] - pos)
    pos = A[i]
    S.append(cost)
S.append(cost + abs(pos))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a_list = a_list + [0]

# sumの計算
s = 0
before = 0
for i in a_list:
    s += abs(before - i)
    before = i

# print(s)

diff = 0
before = 0

for ind, i in enumerate(a_list):
    # print("i: {}".format(i))
    new_diff = i - before
    if diff * new_diff >= 0:
        if ind != 0:
            print(s)

    else:
        if ind != 0:
            print(s - 2 * min(abs(diff), abs(new_diff)))

    diff = new_diff
    before = i

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n):
    t = b
    if not (a[i]<=a[i+1]<=a[i+2] or a[i]>=a[i+1]>=a[i+2]):
        t -= abs(a[i]-a[i+1])
        t -= abs(a[i+1]-a[i+2])
        t += abs(a[i]-a[i+2])
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
an = [0] + [int(i) for i in input().split()]+[0]
t = sum([abs(an[i+1]-an[i]) for i in range(N+1)])
ts = []
for i in range(N):
  a,b,c = an[i:i+3]
  ts.append(t+(0 if 0 <= (a-b)*(b-c) else -2*(min(abs(a-b),abs(b-c)))))
print('\n'.join(map(str,ts)))

Submission status: Accepted

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

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

for i in range(1, N+1):
  if A[i-1] <= A[i] <= A[i+1]:
    print(full)
  else:
    print(full - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 14:35:24 2018

@author: sugawara
"""


N = int(input())
A = [int(i) for i in input().split()]
#N = 6
#A = [-679, -2409, -3258, 3095, -3291, -4462]
#N = 3
#A = [3, 5, -1]

# iからi+1への移動距離
delta_A = [abs(A[0])] + [abs(A[i] - A[i-1]) for i in range(1, N)] + [abs(A[-1])]
sum_of_all = sum(delta_A)

A = [0] + A + [0]
res = []
for i in range(N):
    res.append(sum_of_all - abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1]) + abs(A[i+2] - A[i]))
    
    
for i in range(N):
    print(res[i])

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()
    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):
        ans = total
        ans -= abs(A[i] - A[i - 1])
        ans -= abs(A[i + 1] - A[i])
        ans += abs(A[i + 1] - A[i - 1])
        print(ans)


main()

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)

# diminish in travel distance if we cancel travelling to ai.
# |a_{i+1} - a_{i}| + |a_{i} - a_{i-1}| - ||a_{i+1} - a_{i-1}|

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

# print(orig_dist)


for i in range(1, len(A) - 1):
    d = orig_dist - \
        abs(A[i+1] - A[i]) - \
        abs(A[i] - A[i-1]) + \
        abs(A[i+1] - A[i-1])
    print(d)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

d = []

# comparison list 
prev = 0
for i in range(N + 1) :
    if i == 0 : d.append(abs(a[i]))
    elif i == N : d.append(abs(a[i - 1]))
    else : d.append(abs(prev - a[i]))
    
    if i != N : prev = a[i]

totsum = sum(d)

for i in range(N) :
    # for first
    if i == 0 :
        x, y, z = 0, a[i], a[i + 1]
    elif i == N - 1 :
        x, y, z = a[i - 1], a[i], 0
    else :
        x, y, z = a[i - 1], a[i], a[i + 1]

    if x <= y <= z or x >= y >= z :
        print(totsum)
    else :
        print(totsum - abs(d[i] + d[i + 1]) + abs(d[i] - d[i + 1]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(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.insert(n+1,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())
A = list(map(int, input().split()))

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

total = sum(cost)

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

Submission status: Accepted

Solution code:
N = int(input())
src = [0] + list(map(int,input().split())) + [0]
cums = [0]
for a,b in zip(src,src[1:]):
    d = abs(a-b)
    cums.append(cums[-1] + d)

ans = []
for i in range(N):
    tmp = cums[i] + abs(src[i] - src[i+2]) + cums[-1] - cums[i+2]
    ans.append(tmp)
print(*ans, sep='\n')

Submission status: Accepted

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

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

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

list=[0]
list += a
list += [0]

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

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

def main():
    n = int(input()) + 2
    a_list = list(map(int, input().split()))
    a_list.insert(0,0)
    a_list.append(0)

    all_price = 0
    for i in range(1, n):
        all_price += abs(a_list[i] - a_list[i-1])
    
    for i in range(1, n-1):
        diff = abs(a_list[i] - a_list[i-1]) + abs(a_list[i+1] - a_list[i]) - abs(a_list[i+1] - a_list[i-1])
        print(all_price - diff)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
  if i==0:
    t1 = 0
  else:
    t1 = a[i-1]
  if i==n-1:
    t3 = 0
  else:
    t3 = a[i+1]
  t2 = a[i]
  ans = s+abs(t3-t1)-(abs(t3-t2)+abs(t2-t1))
  print(ans)

Submission status: Accepted

Solution code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
B = [0]+A+[0]
sums=0
for i in range(N+1):
    sums = sums+abs(B[i]-B[i+1])

for i in range(1,N+1):
    if min(B[i-1],B[i+1]) <= B[i] and B[i] <= max(B[i-1],B[i+1]):
        print(sums)
    else:
        print(sums-2*min(abs(B[i]-B[i-1]),abs(B[i]-B[i+1])))

Submission status: Accepted

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

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

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


for i in range(N):
    ss = s
    ss -= abs(d[i]) + abs(d[i+1]) - abs(d[i] + d[i+1])
    print(ss)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

# 出発点と終着点もリストに追加しておく
AN = [0]
AN += list(map(int, input().split()))
AN += [0]

# 全地点行った場合の各距離と合計距離を出しておく
All = []
for i in range(N+1):
	All.append(abs(AN[i] - AN[i+1]))
dist = sum(All)

# 行かなくなった箇所に応じた距離の増減をして出力
for i in range(1, N+1):
	tmp = dist
	tmp -= All[i-1] + All[i]
	tmp += abs(AN[i-1] - AN[i+1])
	print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

A2=[0]+A+[0]

D=0

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

for i in range(1,N+1):
    if (A2[i]-A2[i-1])*(A2[i]-A2[i+1])<0:
        print(D)
    else:
        print(D-abs(A2[i]-A2[i-1])-abs(A2[i]-A2[i+1])+abs(A2[i+1]-A2[i-1]))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
summ = 0
i = 0
while i < N-1:
  summ += abs(A[i]-A[i+1])
  i += 1
print(abs(A[1])+abs(A[N-1])+summ-abs(A[0]-A[1]))
j = 1
while j < N-1:
  print(abs(A[0])+abs(A[N-1])+summ-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])+abs(A[j-1]-A[j+1]))
  j += 1
print(abs(A[0])+abs(A[N-2])+summ-abs(A[N-2]-A[N-1]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
result_1 = 0
result_1 += abs(a[0])
for i in range(n-1):
    result_1 += abs(a[i+1]-a[i])
result_1 += abs(a[n-1])
a.insert(0,0)
a.insert(n+1,0)
for i in range(n):
    if a[i+2] >= a[i+1] >= a[i] or a[i+2] <= a[i+1] <= a[i]:
        print(result_1)
    else:
        b = abs(a[i+2]-a[i+1])
        c = abs(a[i+1]-a[i])
        d = abs(a[i+2]-a[i])
        result = result_1 - (b + c - d)
        print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    ai = [int(i) for i in input().split()]
    ai = [0] + ai + [0]

    z = sum([abs(y - x) for x, y in zip(ai, ai[1:])])
    for i in range(1, len(ai)-1):
        zz = z
        zz -= abs(ai[i-1] - ai[i])
        zz -= abs(ai[i] - ai[i+1])
        zz += abs(ai[i-1] - ai[i+1])
        print(zz)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
S=sum(abs(x-y)for x,y in zip(A,A[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=[0]+list(map(int,input().split()))+[0]
S=sum(abs(x-y)for x,y in zip(A,A[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()))
A = [0] + A
N = len(A)

def cost_delta(A, index):
    size = len(A)
    d = abs(A[index-1] - A[(index+1)%size])
    d -= abs(A[index] - A[(index+1)%size])
    d -= abs(A[index-1] - A[index])
    return d


total_cost = sum([abs(A[i]-A[i+1]) for i in range(N-1)]) + abs(A[0]-A[N-1])
#print(total_cost)
for i in range(1,N):
    delta = cost_delta(A, i)
    print(total_cost + delta )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
spot = list(map(int,(input()).split()))
cost = []
cost1 = []

spot = [0] + spot + [0]

for i in range(N+1):
    cost.append(abs(spot[i+1]-spot[i]))

for i in range(N):
    cost1.append(abs(spot[i+2]-spot[i]))

costsum = 0
for i in cost:
    costsum += i

for i in range(1,N+1):
    prisum = costsum
    prisum = prisum - cost[i-1] - cost[i] + cost1[i-1]
    print(prisum)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
a.insert(0,0)
a.append(0)
b=[]
en=0
for i in range(n+1):
  b.append(a[i+1]-a[i])
  en+=abs(b[i])

for i in range(1,n+1):
  if b[i]*b[i-1]<=0:
    print(en+abs(a[i+1]-a[i-1])-abs(b[i])-abs(b[i-1]))
  else:
    print(en)

Submission status: Accepted

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

A_sum = sum([abs(a1-a2) for a1, a2 in zip(A, A[1:])])

for i in range(1,N+1):
    print(A_sum + 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(N, 0)
A.insert(0, 0)
cost_sum = 0
for i in range(1, len(A)):
	cost_sum += abs(A[i] - A[i-1])
for i in range(1, len(A) - 1):
	print(cost_sum + abs(A[i-1] - A[i+1]) - abs(A[i-1] - A[i]) - abs(A[i+1] - A[i]))

Submission status: Accepted

Solution code:
from itertools import islice

n = int(input())
xs = [0] + [int(x) for x in input().split()] + [0]


total = sum(abs(a-b) for a,b in zip(xs, islice(xs, 1, None)))

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

Submission status: Accepted

Solution code:
N = int(input())
a_list = input().split(" ")
A_list = list(map(int,a_list))
A_list.insert(0,0)

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

sum_len += abs(A_list[N])

for j in range(1,N+1):
	if(j != N):
		length = sum_len - (abs(A_list[j-1]-A_list[j])+abs(A_list[j]-A_list[j+1]))
		length += abs(A_list[j-1]-A_list[j+1])
		print(length)
	elif(j == N):
		length = sum_len - abs(A_list[j-1]-A_list[j]) - abs(A_list[j])
		length += abs(A_list[j-1])
		print(length)

Submission status: Accepted

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

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


  
COST=[None]*N

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

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

print(money - 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()))
all = abs(a[0]) + abs(a[n-1])
for i in range(n-1):
	all += abs(a[i+1] - a[i])
for u in range(n):
	if u == 0:
		print(all + abs(a[1]) - abs(a[0]) - abs(a[1] - a[0]))
	elif u == n-1:
		print(all + abs(a[n-2]) - abs(a[n-1]) - abs(a[n-1] - a[n-2]))
	else:
	    b = abs(a[u] - a[u-1])
	    c = abs(a[u+1] - a[u])
	    d = abs(a[u+1] - a[u-1])
	    print(all - b - c + d)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.insert(n+1,0)
total=0
#通常のコストを計算
for i in range(1,n+2):
    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:
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
distance = []

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


dist_sum = sum(distance)

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

Submission status: Accepted

Solution code:

N=int(input())

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

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


for k in range(1,N+1):
    mae=A[k-1]
    usiro=A[k+1]
    if mae<= A[k]<=usiro or usiro<= A[k]<=mae:
        print(tujyo)
    else:
        print(tujyo-abs(A[k]-mae)-abs(usiro-A[k])+abs(usiro-mae))

Submission status: Accepted

Solution code:
n = int(input())
lis = [0] + list(map(int,input().split())) + [0]
b = 0
for i in range(n+1):
 b += abs(lis[i+1]-lis[i])
for i in range(1,n+1):
 if (lis[i-1] <= lis[i] <= lis[i+1]) or (lis[i+1] <= lis[i] <= lis[i-1]):
   print(b)
 else:
  print(b-abs(lis[i-1] - lis[i]) - abs(lis[i+1] - lis[i]) + abs(lis[i+1] - lis[i-1]))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split(' ')))
A.insert(0,0)
A.append(0)
An = [abs(A[1] - A[0])]
Ann = []
i = 0
while i < n:
    An.append(abs(A[i+2] - A[i+1]))
    Ann.append(abs(A[i+2] - A[i]) - An[i] - An[i+1])
    i += 1
s = sum(An)
ans = ""
for q in Ann:
    ans += str(q + s) + '\n'
print(ans[:-1])

Submission status: Accepted

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

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

for i in range(1, N + 1):
    if (A[i - 1] <= A[i] and A[i] <= A[i + 1]) or (A[i - 1] >= A[i] and A[i] >= A[i + 1]):
        print(tmp)
    else:
        print(tmp - 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 = [int(x) for x in input().split()]

def main():
    A.insert(0, 0)
    A.append(0)

    costs = 0
    skip_benf = []
    for i in range(len(A) - 1):
        p1 = A[i]
        p2 = A[i + 1]
        cost = abs(p1 - p2)
        costs += cost

        if i > N - 1:
            continue

        p3 = A[i + 2]
        benf = (cost + abs(p2 - p3) - abs(p1 - p3))
        skip_benf.append(benf)

    for benf in skip_benf:
        ans = costs - benf
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def m():
    n = int(input())
    a = list(map(int, input().split()))
    total = abs(a[0]) + abs(a[n-1])
    for i in range(1, n):
        total += abs(a[i] - a[i-1])
    for j in range(n):
        if j == 0:
            print(total - abs(a[j]) - abs(a[j]-a[j+1]) + abs(a[j+1]))
            continue
        if j == n-1:
            print(total - abs(a[j-1]-a[j]) - abs(a[j]) + abs(a[j-1]))
            continue
        print(total - abs(a[j-1]-a[j]) - abs(a[j]-a[j+1]) + abs(a[j+1]-a[j-1]))


m()