Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

2 \leq N \leq 10^5

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

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

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

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

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

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

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

Sample Output 3

21630
21630
19932
8924
21630
19288



Sample input:
3
3 5 -1


Sample output:
12
8
10

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = [abs(aa[i+1]-aa[i]) for i in range(n+1)]
    sumv = sum(g)
    g = dict(zip(range(n+1), g))
    ng = [abs(aa[i+2]-aa[i]) for i in range(n)]
    ng = dict(zip(range(n), ng))
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(n+1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(n)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(len(aa)-1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(len(aa)-2)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = [0]
    for i in range(1, n+2):
        g.append(abs(aa[i]-aa[i-1]))
    ng = [0, 0]
    for i in range(2, n+2):
        ng.append(abs(aa[i]-aa[i-2]))
    sumv = sum(g)
    for i in range(1, n+1):
        print(sumv - (g[i] + g[i+1]) + ng[i+1])

if __name__ == '__main__':
    main()
#0, 3, 5, -1, 0
#0, 3, 2,  6, 1
#0, 0, 5,  4, 5

Submission status: Accepted

Solution code:
import sys

n, *a = map(int, sys.stdin.read().split())
a = [0] + a + [0]

def main():
    s = sum([abs(a[i+1] - a[i]) for i in range(n + 1)])
    for i in range(1, n + 1):
        if a[i-1] <= a[i] <= a[i+1]: res = s
        elif a[i-1] >= a[i] >= a[i+1]: res = s
        else: res = s - 2 * min(abs(a[i] - a[i-1]), abs(a[i+1] - a[i]))
        print(res)
            
if __name__ ==  '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = [0] + readInts() + [0]
    S = 0
    for i in range(1,n+2):
        S += abs(A[i] - A[i-1])
    #print(S)
    for i in range(1,n+1):
        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()))
A.append(0)

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

for i in range(N):
  if i == 0:
    tmp = abs(A[1])
  else:
    tmp = abs(A[i+1] - A[i-1])
  print(ansS - ans[i] - ans[i+1] + tmp)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    A = [0] + A + [0]
    Diff = [0]
    for i in range(1, N+2):
        Diff.append(abs(A[i] - A[i-1]))
    
    total = sum(Diff)
    for i in range(1, N+1):
        print(total + abs(A[i-1] - A[i+1]) - Diff[i] - Diff[i+1])

    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
url = "https://atcoder.jp/contests/abc092/tasks/arc093_a"
import copy
def main():
    n = int(input())
    tmp = list(map(int, input().split()))
    ma = [0]
    ma.extend(tmp)
    ma.append(0)
    all_num = 0
    for i in range(len(ma) - 1):
        all_num += abs(ma[i] - ma[i + 1])
    for i in range(1, len(ma) - 1):
        print(all_num - abs(ma[i - 1] - ma[i]) - abs(ma[i] - ma[i + 1]) + abs(abs(ma[i - 1] - ma[i + 1])))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

diff.append(abs(A[-1]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
A = deque(map(int, input().split()))
A.appendleft(0)
A.append(0)
ans = 0
for i in range(1, n+2):
    ans+=abs(A[i]-A[i-1])
for i in range(1, n+1):
    d = abs(A[i]-A[i-1])+abs(A[i+1]-A[i])
    print(ans-d+abs(A[i-1]-A[i+1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list((map(int,input().split())))
A.insert(0,0)

d=[]
skip_d=[]

for i in range(N):
    d.append(abs(A[i+1]-A[i]))
    if i<N-1:
        skip_d.append(abs(A[i+2]-A[i]))
    else:
        skip_d.append(abs(A[0]-A[i]))

d.append(abs(A[-1]))

sum_d=sum(d)

for i in range(N):
    ans=sum_d-(d[i]+d[i+1])+skip_d[i]
    
    print(ans)

Submission status: Accepted

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

for i in range(N):
    print(sum - dif1[i] - dif1[i+1] + dif2[i])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
from collections import deque
a = deque(list(map(int, input().split())))
a.append(0)
a.appendleft(0)
s = 0
for i in range(N + 1):
    s += abs(a[i + 1] - a[i]) 
for i in range(1, N + 1):
    ans = s - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1])
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

aa = [0]
a = aa + a
a.append(0)

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

for i in range(1, n + 1):
    print(sub - (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())
list_A = list(map(int, input().split()))
list_A.append(0)
list_A.insert(0, 0)
sum_value = 0

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

ans = 0
for i in range(1, n+1):
    min_value = min(list_A[i+1], list_A[i-1])
    max_value = max(list_A[i+1], list_A[i-1])
    if min_value <= list_A[i] <= max_value:
        ans = sum_value
        print(ans)
    else:
        ans = sum_value + abs(max_value-min_value) - abs(list_A[i]-max_value) - abs(list_A[i]-min_value)
        print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
from collections import deque
a = deque(a)
a.appendleft(0)
a.append(0)
#s = a[0]
s = 0
for i in range(N + 1):
    s += abs(a[i + 1] - a[i])
#s += abs(0 - a[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 = list(map(int,input().split()))
a.insert(0,0)
a.append(0)
cnt = 0
for i in range(n+1):
  cnt += abs(a[i]-a[i+1])
for i in range(1,n+1):
  ans = cnt
  if a[i-1] <= a[i] <= a[i+1]:
    print(ans)
  elif a[i+1] <= a[i] <= a[i-1]:
    print(ans)
  else:
    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 = list(map(int,input().split()))
a.insert(0,0)
a.append(0)
cnt = 0
for i in range(n+1):
  cnt += abs(a[i]-a[i+1])
for i in range(1,n+1):
  ans = cnt
  if a[i-1] <= a[i] <= a[i+1]:
    print(ans)
  elif a[i+1] <= a[i] <= a[i-1]:
    print(ans)
  else:
    if a[i] >= 0:
      ans -=2*min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))
      print(ans)
    else:
      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 = 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])

def calc(a, i, total):
    if i == 0:
        pre = 0
    else:
        pre = a[i - 1]

    if i != len(a) - 1:
        return total - (abs(a[i] - pre) + abs(a[i] - a[i + 1])) + abs(pre - a[i + 1])
    else:
        return total - (abs(pre - a[i]) + abs(a[i])) + abs(pre)

for i in range(n):
    print(calc(a, i, total))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd


n = int(input())

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

a = np.array(a)

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

org = 0
dis = []
for i in range(1,n+2):
    org += abs(a[i]-a[i-1])
    dis.append(abs(a[i]-a[i-1]))

#print(org)
#print(dis)


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

Submission status: Accepted

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

cost = 0
for i in range(len(a) - 1):
    cost += 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(cost)
    else:
        dec = abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])
        inc = abs(a[i + 1] - a[i - 1])
        print(cost - dec + inc)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a = [0] + a + [0]
cost = [abs(a[i]-a[i+1]) for i in range(n+1)]
sum_cost = sum(cost)
next_cost = [abs(a[i]-a[i+2]) for i in range(n)]
for i in range(n):
    print(sum_cost-cost[i]-cost[i+1]+next_cost[i])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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


def money(a, b):
    return (abs(a - b))


sumall = 0

for i in range(len(A) - 1):
    sumall += money(A[i], A[i + 1])

for i in range(1, len(A) - 1):
    ans = sumall
    ans -= (money(A[i - 1], A[i]) + money(A[i], A[i + 1]))
    ans += money(A[i - 1], A[i + 1])
    print(ans)

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = [0] + list(map(int, readline().split())) + [0]
    cost = 0

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

    for j in range(1, n + 1):
        omit = abs(a[j] - a[j - 1]) + abs(a[j + 1] - a[j])
        new = abs(a[j + 1] - a[j - 1])
        print(cost - omit + new)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

total=sum(dist)

for i in range(1,N+1):
    if zero_A[i-1]<=zero_A[i]<=zero_A[i+1] or zero_A[i-1]>=zero_A[i]>=zero_A[i+1]:
        print(total)
    else:
        print(total-2*min(dist[i-1], dist[i]))

Submission status: Accepted

Solution code:
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):
  if (A[i-1] <= A[i] <= A[i+1]) or (A[i-1] >= A[i] >= A[i+1]):
    print(dist)
  else:
    print(dist - 2 * min( abs(A[i]-A[i-1]), abs(A[i]-A[i+1]) ) )

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))
su=0
su+=abs(a[1])
for i in range(2,n+1):
    su+=abs(a[i]-a[i-1])
su+=abs(a[n])
a.append(0)
#print(su)
for i in range(1,n+1):
    x,y=a[i-1],a[i+1]
    if min(x,y)<=a[i] and a[i]<=max(x,y):
        print(su)
    else:
        d1=abs(a[i-1]-a[i])
        d2=abs(a[i]-a[i+1])
        print(su-2*min(d1,d2))

Submission status: Accepted

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

front = [0]*(n+2)
back = [0]*(n+2)
delta = [0]*(n+1)
delta2 = [0]*n
# print(A)

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

for i in range(n):
    delta2[i] = abs(A[i]-A[i+2])
# print(delta2)

for i in range(1,n+2):
    front[i] = front[i-1]+delta[i-1]
    back[i] = back[i-1]+delta[(n+1)-i]
back.reverse()
# print(front)
# print(back)

for i in range(n):
    print(front[i]+delta2[i]+back[i+2])

Submission status: Accepted

Solution code:
#92c
N = int(input()) #<=10**5
A_list = [0] + [int(e) for e in input().split()] + [0]

fare = [abs(A_list[i]-A_list[i-1]) for i in range(1,N+2)]
sum_fare = sum(fare)

#print(A_list)
#print(fare)

for i in range(1,N+1):
    print(sum_fare - (fare[i-1]+fare[i]) + abs(A_list[i+1] - A_list[i-1]))

Submission status: Accepted

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

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



resolve()

Submission status: Accepted

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

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

d = sum(costs)

for i in range(1, n+1):
    distance = d - abs(al[i] - al[i+1]) - abs(al[i-1] - al[i]) + abs(al[i-1] - al[i+1])
    print(distance)

Submission status: Accepted

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

#print('a: ', a)
#print('cost: ', cost)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.append(0)
a.insert(0,0)
sm = 0

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

for i in range(1,len(a)-1):
    dis1 = abs(a[i-1] - a[i]) + abs(a[i+1] - a[i])
    dis2 = abs(a[i-1] - a[i+1])
    print(sm - dis1 + dis2)

Submission status: Accepted

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

Submission status: Accepted

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


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

    for i in range(1, N + 1):
        l, r = min(A[i - 1], A[i + 1]), max(A[i - 1], A[i + 1])
        if l <= A[i] <= r:
            print(S)
        elif A[i] <= l:
            print(S - 2 * (l - A[i]))
        else:
            print(S - 2 * (A[i] - r))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

d = 0
a.insert(0, 0)
a.append(0)
for i in range(n+1):
  d += abs(a[i+1] - a[i])
  
for i in range(n):
  ans = d - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1]) + abs(a[i+2]-a[i])
  print(ans)

Submission status: Accepted

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

for i in range(n):
    if a[i] <= a[i+1] <= a[i+2] or a[i+2] <= a[i+1] <= a[i]:
        print(origin_len)
    else:
        len_a = abs(a[i+1] - a[i])
        len_b = abs(a[i+1] - a[i+2])

        print(origin_len - 2 * min(len_a, len_b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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 = [0] + [int(x) for x in input().split()] + [0]

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

C = []
for i in range(2,N+2) :
    C.append(abs(A[i] - A[i-2]))

tlen = sum(B)
for i in range(N) :
    print(tlen - B[i] - B[i+1] + C[i])

Submission status: Accepted

Solution code:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    diff = []
    for i in range(1, N+1):
        if A[i-1]<A[i] and A[i+1]<A[i]:
            diff.append((A[i]-max(A[i-1], A[i+1]))*2)
        elif A[i-1]>A[i] and A[i+1]>A[i]:
            diff.append((min(A[i-1], A[i+1])-A[i])*2)
        else:
            diff.append(0)
    res = 0
    for i in range(N+1):
        res += abs(A[i+1]-A[i])
    for i in diff:
        print(res-i)

if __name__ == '__main__':
    main()

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:
import math
N = int(input())
ARR = [int(s) for s in input().split(" ")]
ARR.insert(0,0)
ARR.append(0)


def calculate(arr):
    S = 0
    for i in range(len(arr)-1):
        S = S + int(math.fabs(arr[i+1]-arr[i]))

    for i in range(1,len(arr)-1):
        print(int(S + math.fabs(arr[i-1]-arr[i+1]) - (math.fabs(arr[i-1]-arr[i]) + math.fabs(arr[i]-arr[i+1]))))



calculate(ARR)

Submission status: Accepted

Solution code:
N = int(input())
AList = list(map(int, input().split()))
sumFee = 0

# 全てを回った時の料金を求める
sumFee += abs(AList[0])
for i in range(1, N):
  sumFee += abs(AList[i] - AList[i - 1])
sumFee += abs(AList[N-1])

# Iを抜かした時の料金を求める
for i in range(N):
  low_i = abs(AList[i] - AList[i-1]) if i != 0 else abs(AList[0])
  high_i = abs(AList[i + 1] - AList[i]) if i != N - 1 else abs(AList[N-1])
  if i == 0 :
    mix_i = abs(AList[i + 1])
  elif i == N - 1 :
    mix_i = abs(AList[i - 1])
  else:
    mix_i = abs(AList[i + 1] - AList[i - 1])
  
  print(sumFee - low_i - high_i + mix_i)

Submission status: Accepted

Solution code:
import copy
N=int(input())
A=list(map(int,input().split()))
allcost=abs(0-A[0])
for i in range(N-1):
    allcost=allcost+abs(A[i]-A[i+1])
allcost=allcost+abs(A[N-1])
#print(allcost)
A.insert(0,0)
A.append(0)
for i in range(N):
    print(allcost-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())
l=[0]+list(map(int,input().split()))+[0]
f=lambda x,y:abs(l[x]-l[y])
s=sum(f(i+1,i) for i in range(n+1))
for i in range(n): print(s-f(i+1,i)-f(i+2,i+1)+f(i+2,i))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l=[0]+l+[0]

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

for i in range(1,n+1):
    print(x + 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()))
a.append(0)
a.insert(0,0)
a_abs = []
for i in range(n+1):
    a_abs.append(abs(a[i]-a[i+1]))

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

Submission status: Accepted

Solution code:
from copy import deepcopy
N = int(input())
A = list(map(int,input().split()))
A = [0] + A + [0]
dist = []
for i in range(N+1):
    dist.append(abs(A[i]-A[i+1]))
S = sum(dist)
for i in range(1,N+1):
    print(S+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 = [int(x) for x in input().split()]

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

ans = 0

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

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

Submission status: Accepted

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

total = 0

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

S=0
for i in range( len(A_list) ):
    if i==0:
        S = abs(A_list[i])
    else:
        S += abs(A_list[i] - A_list[i-1])
        
S += abs(A_list[i])


ans_S=[]
for i in range( len(A_list) ):
    if i == 0:
        ex_S = S - abs(A_list[i+1] - A_list[i]) - abs(A_list[i] - 0) + abs(A_list[i+1] - 0)
    elif i == len(A_list)-1:
        ex_S = S - abs(0 - A_list[i]) - abs(A_list[i] - A_list[i-1]) + abs(0 - A_list[i-1])
    else:
        ex_S = S - abs(A_list[i+1] - A_list[i]) - abs(A_list[i] - A_list[i-1]) + abs(A_list[i+1] - A_list[i-1])
    
    ans_S.append(ex_S)


for i in ans_S:
    print(i)

Submission status: Accepted

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

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


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