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

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

def calc(l):
    count = 0
    for i in range(len(l)-1):
        count += abs(l[i]-l[i+1])

    return count

# 0 3 5 -1 0 みたいに
L = [0] + A + [0]
max_L = calc(L)
#print(max_L)

# 左右引いて、左右通しで計算すればいい
for i in range(1, N+1):
    diff_minus = abs(L[i-1]-L[i])+abs(L[i]-L[i+1])
    diff_plus = abs(L[i-1]-L[i+1])
    print(max_L-diff_minus+diff_plus)

Submission status: Accepted

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

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

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]

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


for i in range(1, N+1):
    skip_cost = (abs(A[i-1] - A[i+1])) - \
        (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(total_cost + skip_cost)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

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

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):

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

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


    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

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

    x = sorted(A)

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


    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
A = list(map(int, input().split()))
A = [0 if i in [0,N+1] else A[i-1] for i in range(N+2)]

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

for i in range(1,N+1):
	mae = abs(A[i]-A[i-1]) + abs(A[i+1]-A[i])
	ato = abs(A[i+1]-A[i-1])
	sa = mae - ato

	print(tmpr - sa)

Submission status: Accepted

Solution code:
import sys
from statistics import *
from collections import *
stdin = sys.stdin

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

n = ni()
li = deque(na())
li.appendleft(0)
li.append(0)
s = 0
for i in range(len(li) - 1):
    s += abs(li[i + 1] - li[i])
for i in range(1, len(li) - 1):
    print(s - abs(li[i+1] - li[i]) - abs(li[i] - li[i-1]) + abs(li[i+1] -li[i-1]))

Submission status: Accepted

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


total = sum(abs(a[i+1]-a[i]) for i in range(n+1))
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:
N = int(input())
As = list(map(int, input().split()))
As = [0]+As+[0]
s = 0
for i in range(N+1):
  s += abs(As[i]-As[i+1])
#print(s)
for i in range(1, N+1):
  r = s-abs(As[i]-As[i-1])-abs(As[i]-As[i+1])+abs(As[i-1]-As[i+1])
  print(r)

Submission status: Accepted

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

for i in range(n):
    b.append(abs(a[i] - a[i + 1]))
    if i < n - 1:
        c.append(abs(a[i] - a[i + 2]))

sum_b = sum(b)
for i in range(n):
    print(sum_b + c[i] - b[i] - b[i + 1])

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
A=[0]+A+[0]
f=abs
s=sum(f(i-j)for i,j in zip(A,A[1:]))
print(*[s-f(i-j)-f(j-k)+f(i-k)for i,j,k in zip(A,A[1:],A[2:])])

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
A=[0]+A+[0]
f=lambda i:abs(A[i]-A[i+1])
s=sum(f(i)for i in range(N+1))
print(*[s-f(i)-f(i+1)+abs(A[i]-A[i+2])for i in range(N)])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
A=[0]+list(map(int,input().split()))+[0]
S=sum(abs(A[j]-A[j+1]) for j in range(n+1))
for i in range(n):
  if (A[i+1]-A[i])*(A[i+2]-A[i+1])>=0:
    print(S)
  else:
    print(S-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()))

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

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

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

for i in range(1, N+1):
    ans = sum_dA
    if (A[i-1] - A[i]) * (A[i] - A[i+1]) < 0:
        ans = ans - 2 * min(abs(A[i]-A[i-1]), abs(A[i]-A[i+1]))
    print(ans)

Submission status: Accepted

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

for j in range(1, n+1):
    print(cost+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 = [int(i) for i in input().split()]
a.append(0)
b = [abs(a[0])]
c = [abs(a[1])]

for i in range(n):
    b.append(abs(a[i] - a[i+1]))
    if i < n-1:
        c.append(abs(a[i] - a[i+2]))
sum_b = sum(b)
for i in range(n):
    print(sum_b + c[i] - b[i] - b[i+1])

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

ALL = 0
for i in range(N + 1):
    ALL += 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(ALL)
        continue

    ans = ALL + abs(A[i - 1] - A[i + 1]) - abs(A[i - 1] - A[i]) - abs(A[i + 1] - A[i])
    print(ans)

Submission status: Accepted

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

for i in range(n):
    if i > 0 and i < n-1:
        ans = plan -abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i+1] - a[i-1])
        
    elif i == 0:
        ans = plan - abs(a[i]) -abs(a[i + 1] - a[i]) + abs(a[i + 1])
        
    else:
        ans = plan -abs(a[i] - a[i - 1]) - abs(a[-1]) + abs(a[-2])
    
    print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    dist = []
    prev = 0
    for i in range(N):
        dist.append(abs(A[i]-prev))
        prev = A[i]
    dist.append(abs(A[N-1]-0))
    plan_tot = sum(dist)
    for i in range(N):
        v = plan_tot - dist[i] - dist[i+1]
        if i == 0:
            v += abs(A[1])
        elif i == N-1:
            v += abs(A[N-2])
        else:
            v += abs(A[i+1]-A[i-1])
        print(v)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1,N+1):
  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]+[int(i) for i in 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:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    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+1]-a[i]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1])) #集合の考え方

Submission status: Accepted

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



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




for i in range(1, len(li)-1):
    if li[i-1] <= li[i] <= li[i+1] or li[i-1] >= li[i] >= li[i+1]:
        print(ret)
    elif li[i] < li[i-1] < li[i+1] or li[i] > li[i-1] > li[i+1]:
        print(ret - abs(li[i] - li[i-1]) * 2)
    else:
        print(ret - abs(li[i+1] - li[i]) * 2)

Submission status: Accepted

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

a_sum = 0
for i in range(n + 1):
  a_sum += 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(a_sum)
  else:
    print(a_sum - 2 * min(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]
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+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.insert(0,0)
A.append(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]))

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] - A[i+1])
total += abs(0 - A[0]) + abs(0 - A[-1]) 

ans = 0
now = 0
next = 0
next2 = 0
for i in range(N):
    next = A[i]
    if i == 0:
        now = 0
    else:
        now = A[i-1]
    
    if i == N-1:
        next2 = 0
    else:
        next2 = A[i+1]
    
    if now <= next <= next2 or now >= next >= next2:
        ans = total
    elif now <= next2 <= next or now >= next2 >= next:
        ans = total - abs(next2-next)*2
    elif next2 <= now <= next or next2 >= now >= next:
        ans = total - abs(now - next)*2
    
    print(ans)

Submission status: Accepted

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

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

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

list_sum = sum(diff)

for i in range(n):
    x = diff[i] + diff[i+1] - diff_2[i]
    print(list_sum - x)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
s = 0

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

print(s-abs(l[0]-0)-abs(l[1]-l[0])+abs(l[1]-0))
for j in range(1, n-1):
  print(s-abs(l[j-1]-l[j])-abs(l[j]-l[j+1])+abs(l[j-1]-l[j+1]))
print(s-abs(l[-1]-0)-abs(l[-1]-l[-2])+abs(l[-2]-0))

Submission status: Accepted

Solution code:
"""
観光スポット    1   2   3   4   ... N
座標           A1  A2  A3  A4  ... An

-O-+--+-+---+
観光スポットiを回るのをやめたときの、移動金額の総和

3-O----1--2

0 3 5 -1 0


"""


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

## 総和を出す
cnt = 0
prev = 0
for a in As:
    cnt += abs(a-prev)
    prev = a
cnt += abs(a)
# print(cnt)

## 損失はどのくらいか
for i in range(N):
    l = As[i]
    m = As[i+1]
    r = As[i+2]
    diff1 = abs(r-m)+abs(m-l)
    diff2 = abs(r-l)
    print(cnt-(diff1-diff2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

lst = list(map(int, input().split()))
lst.insert(0,0)
lst.insert(len(lst),0)

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

for i in range(1,N+1):
  a = lst[i-1]
  b = lst[i]
  c = lst[i+1]
  if (a <= b and b <= c or a >= b and b >= c):
    print(money)
  elif (a <= c and c <= b):
    print(money - abs(2 * (c - b)))
  elif (b <= a and a <= c):
    print(money - abs(2 * (a - b)))
  elif (b <= c and c <= a):
    print(money - abs(2 * (b - c)))
  elif (c <= a and a <= b):
    print(money - abs(2 * (a - b)))

Submission status: Accepted

Solution code:
n = int(raw_input())
A = map(int, raw_input().split())
c = 0
absA = [abs(0-A[0])]
jumpA = []
for i in range(n-1):
    absA.append(abs(A[i+1]-A[i]))
    jumpA.append(abs(c-A[i+1]))
    c = A[i]
absA.append(abs(A[-1]-0))
jumpA.append(abs(A[-2]-0))
total = sum(absA)
for i in range(n):
    print total - absA[i] - absA[i+1] + jumpA[i]

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

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

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

total = sum(B)

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] + data + [0]
ab = [0] * (N+1)
for i in range(0,N+1):
    ab[i] = abs(data[i] - data[i+1])

S = sum(ab)

for j in range(0,N):
    print(S - ab[j] - ab[j+1] + (abs(data[j] - data[j+2])))

Submission status: Accepted

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

distSum = [0 for _ in range(N + 3)]

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

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

Submission status: Accepted

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

for i in range(0,len(a)-1):
    dis1.append(abs(a[i+1]-a[i]))
s = sum(dis1)
for i in range(0,len(a)-2):
    dis2.append(abs(a[i+2]-a[i]))

for i in range(n):
    print(s-dis1[i]-dis1[i+1]+dis2[i])

Submission status: Accepted

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

li = [abs(a[i] - a[i+1]) for i in range(N + 1)]
sumli = sum(li)

# iは除く番号
for i in range(1, N + 1):
  print(sumli - (li[i-1] + li[i]) + abs(a[i-1]-a[i+1]))

Submission status: Accepted

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

Submission status: Accepted

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

L = []
pos = 0
for i in range(N):
    x = abs(pos-A[i])
    pos = A[i]
    L.append(x)
L.append(abs(A[-1]))

cs = [0]
for i in range(N+1):
    x = L[i]+cs[-1]
    cs.append(x)
m = cs[-1]
#print(L,cs)

for i in range(N):
    x = m - L[i]-L[i+1]
    if i == 0:
        x += abs(0-A[i+1])
    elif i == N-1:
        x = cs[-3] + abs(A[N-2])
    else:
        x += abs(A[i-1]-A[i+1])
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.insert(0,0)
li.insert(n+1,0)
lidiff = [0]*(n+1)
for i in range(n+1):
  lidiff[i] = abs(li[i+1]-li[i])
li2diff = [0]*n
for i in range(n):
  li2diff[i] = abs(li[i+2]-li[i])
s = sum(lidiff)
for i in range(n):
  print(s-lidiff[i]-lidiff[i+1]+li2diff[i])

Submission status: Accepted

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

acum = []

# 総和を取る
for i in range(1, len(A)):
    acum.append(abs(A[i-1] - A[i]))

S = sum(acum)

ans = [0] * N
for skip_i in range(N):
    print(S - (acum[skip_i] + acum[skip_i+1]) + abs(A[skip_i] - A[skip_i+2]))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

li1 = []
li1.append(a[0])

long = len(a)

for i in range(long - 1):
    S = a[i+1] - a[i]
    li1.append(S)

li1.append(-a[-1])

li2 = [abs(li1[i+1] + li1[i]) for i in range(long)]
li3 = [abs(li1[i+1]) + abs(li1[i]) for i in range(long)]

ab_li1 = map(lambda x:abs(x), li1)

S = sum(ab_li1)

for i in range(long):
    print(S - li3[i] + li2[i])

Submission status: Accepted

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

li1 = []
li1.append(a[0])

for i in range(len(a) - 1):
    S = a[i+1] - a[i]
    li1.append(S)

li1.append(-a[-1])

li2 = [abs(li1[i+1] + li1[i]) for i in range(len(a))]
li3 = [abs(li1[i+1]) + abs(li1[i]) for i in range(len(a))]

ab_li1 = map(lambda x:abs(x), li1)

S = sum(ab_li1)

for i in range(len(li3)):
    print(S - li3[i] + li2[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input());*a,=map(int,input().split())
if n!=2:
	b=[abs(a[0])]+[abs(i-j)for i,j in zip(a,a[1:])]+[abs(a[-1])]
	c=[abs(a[1])]+[abs(i-j)for i,j in zip(a,a[2:])]+[abs(a[-2])]
	s=sum(b)
	for i,j,k in zip(b,b[1:],c):
		print(s-i-j+k)
else:
	print(2*abs(a[1]),2*abs(a[0]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())  
li = list(map(int, input().split()))
li.append(0)
li.insert(0,0)
li_cost = [abs(li[i]-li[i+1]) for i in range(n+1)]
cost_sum = sum(li_cost)

for i in range(n):
    if li_cost[i] == 0:
        print(cost_sum)
    else:
        print(cost_sum - li_cost[i] - li_cost[i+1] + abs(li[i] - li[i+2]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + [int(s) for s in input().split()] + [0]
s = sum([abs(A[i + 1] - A[i]) for i in range(N + 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:
from itertools import accumulate
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
b = [0]
for i in range(n + 1):
    b.append(abs(a[i] - a[i + 1]))
c = list(accumulate(b))
# print(n, a, b, c)
ans = 0
for i in range(0, n):
    ans = 0
    ans += c[i] - c[0]
    ans += abs(a[i] - a[i + 2])
    ans += c[n + 1] - c[i + 2]
    # print(c[i] - c[0], abs(a[i] - a[i + 2]), c[n + 1] - c[i + 2])
    print(ans)

Submission status: Accepted

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

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(1, N+1):
  L[i] = L[i-1] + abs(nums[i-1] - nums[i-2])
  R[N-i] = R[N-i+1] + abs(nums[N-i+2] - nums[N-i+1])
for i in range(1, N+1):
  print(L[i]+R[i]+abs(nums[i+1]-nums[i-1]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

A=[0]+A     #最初
A.append(0) #最後 要素数 N+2 になった
full=0
for i in range(N+1):
    full+=abs(A[i+1]-A[i])

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

Submission status: Accepted

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

B = [abs(A[i]) if i == 0 else abs(A[i]-A[i-1]) for i in range(N)]
B.append(abs(A[N-1]))

C = [abs(A[1]) if i == 0 else abs(A[i+1]-A[i-1]) for i in range(N-1)]
C.append(abs(A[-2]))

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())
a=list(map(int,input().split()))
a.insert(0,0)
a.append(0)
b=[]
c=0
for i in range(n+1):
    c=abs(a[i]-a[i+1])
    b.append(c)
B=sum(b)
for i in range(n):
    print(B-b[i]-b[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)
S = sum([abs(A[i] - A[i+1]) for i in range(0, N+1)])
for i in range(1, N+1):
    ans = S + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ans)