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:
#■標準入力ショートカット


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N = get_next_int()
    positions = get_next_ints()

    diffs = [0 for i in range(N)]
    dist = 0
    prev_pos = 0
    for i, pos in enumerate(positions):
        dist += abs(pos - prev_pos)

        next_pos = positions[i + 1] if i + 1 < N else 0
        if prev_pos <= pos <= next_pos or prev_pos >= pos >= next_pos:
            diff = 0
        else:
            diff = min(abs(next_pos - pos), abs(prev_pos - pos)) * 2
        diffs[i] = diff
        prev_pos = pos
    dist += abs(prev_pos)
    # print(dist)
    # print(diffs)
    for diff in diffs:
        print(dist - diff)


solve()

Submission status: Accepted

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

for i in range(N):
  cost.append(allcost)
  if i != 0 and i != N-1:
    cost[i] += abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1])
  elif i == 0:
    cost[i] += abs(0-A[i+1]) - abs(0-A[i]) - abs(A[i]-A[i+1])
  else:
    cost[i] -= abs(A[i-1]-A[i]) + abs(A[i]) - abs(A[i-1])
for i in range(N):
  print('%d ' %cost[i])

Submission status: Accepted

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

def x_spot(idx):
    if idx == -1 or idx == N:
        return 0
    else:
        return A[idx]
    
dist_of_all = sum([abs(x_spot(i) - x_spot(i-1)) for i in range(N+1)])

for i in range(N):
    dist = dist_of_all - abs(x_spot(i) - x_spot(i-1)) - abs(x_spot(i) - x_spot(i+1)) + abs(x_spot(i+1) - x_spot(i-1))
    print(dist)

Submission status: Accepted

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

    sum = 0
    for i in range(1, n+2):
        sum += abs(A[i]-A[i-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:
# -*- coding: utf-8 -*-
import traceback
import logging

def main():
    try:
        N = int,raw_input()
        A = map(int,raw_input().split())
        A_size = len(A)
        distance = now_pos = 0
        for i in range(A_size):
            distance = distance + abs(now_pos - A[i])
            now_pos = A[i]

        distance = distance + abs(now_pos)
        for i in range(A_size):
            if i == A_size-1:
                print distance - abs(A[i-1] - A[i]) - abs(A[i]) + abs(A[i-1])
            elif i == 0:
                print distance - abs(A[i]) - abs(A[i] - A[i+1]) + abs(A[i+1])
            else:
                print distance - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])

    except:
        traceback.print_exc()
        return 0

main()

Submission status: Accepted

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


for i in range(N):
	ans = dis - 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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

A = sys.stdin.readline().split(' ')

A = [int(x) for x in A]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = 0

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

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

Submission status: Accepted

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

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

for i in range(1,n+1):
  if (l[i-1] <= l[i] and l[i] <= l[i+1]) or (l[i-1] >= l[i] and l[i] >= l[i+1]):
    print(s)
  elif l[i-1] < l[i] and l[i] > l[i+1]:
    print(s - 2*abs(l[i] - max(l[i-1],l[i+1])))
  else:
    print(s - 2*abs(l[i] - min(l[i-1],l[i+1])))

Submission status: Accepted

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

d1 = [abs(a[0])]
d2 = [abs(a[1])]
for i in range(1, n):
    d1.append(abs(a[i] - a[i - 1]))
d1.append(abs(a[-1]))
s = sum(d1)
for i in range(2, n):
    d2.append(abs(a[i] - a[i - 2]))
d2.append(abs(a[-2]))

for i in range(n):
    print(s - d1[i] - d1[i + 1] + d2[i])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    s = 0
    t = 0
    for c in a:
        s += abs(t-c)
        t = c
    s += abs(t)

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


    return '\n'.join(map(str,r))


print(main())

Submission status: Accepted

Solution code:
def abs(x):
    return -x if x < 0 else x


n = int(input())
spots = list(map(int, input().split()))

costs = [n1 - n2 for n1, n2 in zip(spots + [0], [0] + spots)]
costs_sum = sum([abs(cost) for cost in costs])

for i in range(n):
    if costs[i] * costs[i + 1] < 0:
        elim = min([abs(costs[i]), abs(costs[i + 1])])
        print(costs_sum - 2 * abs(elim))
    else:
        print(costs_sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# get a integer
num = int(raw_input())
# get two integers separated with half-width break
array = map(int, raw_input().split())
# get a string
#s = raw_input()

state = 0
way_total = 0
for j in range(0,num):
    way_total += abs(array[j] - state)
    state = array[j]
way_total += abs(state)

for i in range(0,num):
    if i != num - 1 and i != 0:
        way = way_total - abs(array[i-1] - array[i]) - abs(array[i+1] - array[i]) + abs(array[i-1] - array[i+1])
    elif i == 0:
        way = way_total - abs(array[i])- abs(array[i+1] - array[i]) + abs(array[i+1])
    elif i == num - 1:
        way = way_total - abs(array[i-1] - array[i]) - abs(array[i]) + abs(array[i-1] - 0)
    print(way)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
N = int(input())
A= list(map(int,input().split()))
A = [0] + A + [0]
def diff(X):
    diff_x = list(range(len(X)-1))
    for i in range(len(X)-1):
        diff_x[i] = abs(X[i] - X[i+1])
    return diff_x
Adiff = diff(A)
SUM = 0
for i in range(len(Adiff)):
    SUM += Adiff[i]
for i in range(N):
    SUMM = SUM
    SUMM += abs(A[i]-A[i+2]) - Adiff[i+1]-Adiff[i]
    print(SUMM)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():
	n = I()
	A = LI()
	A.append(0)

	prev = 0
	skip = []
	sum_all = 0

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

		skipped = (t1+t2) - abs(prev - A[i+1])
		sum_all += t1

		skip.append(skipped)

		prev = A[i]
	sum_all += abs(A[n-1] - A[n])

	for s in skip:
		print(sum_all - s)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import copy
import time


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

t0 = time.time()

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


dAs = [dist(As[i], As[i+1]) for i in range(N+1)]
sumdAs = sum(dAs)
# print(time.time()-t0, 'a')

def rem(i):
    ret = copy.deepcopy(dAs)
    print('copy', ret)
    ret[i] = dist(As[max(0, i-1)], As[i+1])
    print('rett', ret, i)
    ret = ret[:max(0, i-1)] + ret[i:]
    print('As', As)
    print('ret', ret)
    return ret

def calc(i):
    return sumdAs - dist(As[i], As[i-1]) - dist(As[i+1], As[i]) + dist(As[i+1], As[i-1])


for i in range(1, N+1):
    print(calc(i))

Submission status: Accepted

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
a = [0] + Is() + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
total = sum(d)
for i in range(n):
    print(total - d[i+1] -d[i] + abs(a[i+2]-a[i]))

Submission status: Accepted

Solution code:
N = int(input())
spot = list(map(int, input().split()))
spot.insert(0, 0)
spot.append(0)
all_cost = 0
for i in range(N + 1):
    all_cost += max(spot[i + 1] - spot[i], spot[i] - spot[i + 1])
for i in range(1, N + 1):
    cost = all_cost
    if (spot[i] > spot[i - 1] and spot[i] > spot[i + 1]) or (spot[i] < spot[i - 1] and spot[i] < spot[i + 1]):
        cost -= 2 * min(max(spot[i] - spot[i - 1], spot[i - 1] - spot[i]), max(spot[i] - spot[i + 1], spot[i + 1] - spot[i]))
    print(cost)

Submission status: Accepted

Solution code:
import operator

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

A1 = [0] + As
A2 = As + [0]
costs = list(map(abs, map(operator.sub, A1, A2)))
cTotal = sum(costs)

for i in range(N):
    print(cTotal - costs[i] - costs[i + 1] + abs(A1[i] - A2[i + 1]))

Submission status: Accepted

Solution code:
import math
N = int(raw_input())
list = map(int,raw_input().split())

k = 0
tot = abs(list[0]) + abs(list[N - 1])

while k < N - 1:
    tot += abs(list[k] - list[k + 1])
    k = k + 1

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

Submission status: Accepted

Solution code:
N = long(raw_input())
A = map(int, raw_input().split())
A = [0] + A + [0]
#print str(A)

maxCost = 0

# Total
for x in range(1, len(A), 1):
    maxCost += abs(A[x -1] - A[x])

#print "maxCost : " + str(maxCost)

# remove each point
for x in range(1, len(A) - 1, 1):
    # unnecessary move
    umove1 = abs(A[x - 1] - A[x])
    umove2 = abs(A[x] - A[x + 1])
    # additional move
    amove = abs(A[x - 1] - A[x + 1])
    print maxCost - umove1 -umove2 + amove

Submission status: Accepted

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

def distance_point_interval(p,a,b):
  if(p<min(a,b)):
    return min(a,b)-p
  elif(max(a,b)<p):
    return p-max(a,b)
  else:
    return 0

distances=[abs(points[i+1]-points[i]) for i in range(n+1)]
cost_all=sum(distances)

for i in range(n):
  print(cost_all-2*distance_point_interval(points[i+1],points[i],points[i+2]))

Submission status: Accepted

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

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

for i in range(n):
    if i==0:
        ret = abs(s[-1]-s[i+1]) + abs(a[i+1])
    elif i==len(a)-1:
        ret = s[i-1] + abs(a[i-1])
    else:
        ret = s[i-1] + abs(s[-1]-s[i+1]) + abs(a[i+1]-a[i-1])

    print(ret)

Submission status: Accepted

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


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

    cost = 0
    prev = 0
    for a in A:
        cost += abs(a - prev)
        prev = a
    cost += abs(prev)

    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:
            x = abs(A[i - 1] - A[i]) + abs(A[i + 1] - A[i])
            y = abs(A[i - 1] - A[i + 1])
            print(cost - (x - y))


if __name__ == '__main__':
    # print(main())
    main()

Submission status: Accepted

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

    S = 0

    p = 0
    for a in A:
        S += abs(a - p)
        p = a
    S += abs(p)

    A = [0] + A
    A.append(0)
    for n in range(1, N+1):
        pre = A[n] - A[n-1]
        ne = A[n+1] - A[n]
        if pre * ne < 0:
            print(S - (abs(min(abs(ne), abs(pre))) * 2))
        else:
            print(S)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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


#print(a)
#print(cost)


costsum=sum(cost)

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

Submission status: Accepted

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

ans = []
sum = 0

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

sum += abs(A[N - 1])

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

Submission status: Accepted

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

    one = [-1 for i in range(n+1)]


    # 差分1
    for i, a_ in enumerate(a):
        if i != n+1:
            one[i] = abs(a[i+1] - a[i])

    #print(n, len(a), a, one)

    two = [-1 for i in range(n+1)]
    for i, a_ in enumerate(a):
        if i == 0 or i == n+1:
            pass
        else:
            two[i] = abs(a[i+1] - a[i-1])


    l = sum(one)

    for i in range(1, n+1):
        print(l - one[i] - one[i-1] + two[i])

solve()

Submission status: Accepted

Solution code:
import math

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

# default
sum = 0
for i in range(len(a)):
    if i == 0:
        sum += abs(a[i])
    else :
        sum += abs(a[i]-a[i-1])
sum += abs(a[i])
baseSum = sum

for i in range(len(a) -1):
    if i == 0 :
        print(baseSum - ( abs(a[0]) + abs(a[1]-a[0]) ) + abs(a[1]))
    else :
        print(baseSum - ( abs(a[i+1]-a[i]) + abs(a[i]-a[i-1]) ) + abs(a[i+1]-a[i-1]))
i+=1
print(baseSum - ( abs(0-a[i]) + abs(a[i]-a[i-1]) ) + abs(0-a[i-1]))

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
AA = list(zip(A[:-1], A[1:]))
cost = [abs(aa[0] - aa[1]) for aa in AA]
# print('cost', cost)
ttl = sum(cost)
# print('ttl', ttl)

for i in range(1, N + 1):
    ans = ttl
    if A[i - 1] < A[i] and A[i] < A[i + 1]:
        pass
    elif A[i - 1] > A[i] and A[i] > A[i + 1]:
        pass
    else:
        d1, d2 = abs(A[i - 1] - A[i]), abs(A[i] - A[i + 1])
        d = min(d1, d2)
        red = d * 2
        ans -= red
    print(ans)

Submission status: Accepted

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

n = int(raw_input())
a = map(int,raw_input().split())

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

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

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

Submission status: Accepted

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


def solve(n, xs):
    res = [sum(abs(xs[i + 1] - xs[i]) for i in range(n))
           + abs(xs[n] - xs[0])] * (n + 1)
    res[0] = None
    for j in range(1, n + 1):
        if j <= n - 1:
            res[j] += abs(xs[j + 1] - xs[j - 1])
            res[j] -= abs(xs[j] - xs[j - 1]) + abs(xs[j + 1] - xs[j])
        else:
            res[j] += abs(xs[0] - xs[n - 1])
            res[j] -= abs(xs[n] - xs[n - 1]) + abs(xs[0] - xs[n])
    return res


def main():
    n = int(input())
    xs = [0]
    xs.extend(int(x) for x in input().split())
    res = solve(n, xs)
    for r in res[1:]:
        print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
m = [0]
m.extend(list(map(int, input().split())))
m.append(0)
k = []
l = []
a = 0

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

for i in range(n):
    l.append(np.abs(k[i + 1]) + np.abs(k[i]) - np.abs(k[i + 1] + k[i]))

for i in range(n):
    print(a - l[i])

Submission status: Accepted

Solution code:
from sys import stdin 
n = int(stdin.readline())
a = [0] + map(int,stdin.readline().split())
ans = 0 
for i in xrange(1,n+1):
    ans += abs(a[i] - a[i-1])
ans += abs(a[n])
b = []
cur = abs(a[2])
for i in xrange(3,n+1):
    cur += abs(a[i] - a[i-1])
cur += abs(a[n])
b.append(cur)

for i in xrange(2,n):
    cur = ans - abs(a[i]-a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1]-a[i+1])
    b.append(cur)
cur = 0
for i in xrange(1,n):
    cur += abs(a[i]-a[i-1])
cur += abs(a[n-1])
b.append(cur)
for i in b:
    print i

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0]+[int(x) for x in input().split()]+[0]
cost1 = [abs(x-y) for x, y in zip(a, a[1:])]
s = sum(cost1)
cost2 = [abs(x-y) for x, y in zip(a, a[2:])]
for i in range(n):
    print(s-cost1[i]-cost1[i+1]+cost2[i])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
prev = 0
costs = []
total = 0
for a in A:
  cost = abs(a - prev)
  total += cost
  costs.append(cost)
  prev = a
cost = abs(prev)
total += cost
costs.append(cost)

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

Submission status: Accepted

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

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

ans = [full - abs(xs[i-1] - xs[i]) - abs(xs[i] - xs[i+1]) + abs(xs[i-1] - xs[i+1]) for i in range(1, n+1)]

print('\n'.join(map(str, ans)))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
aaa = [0] + list(map(int, input().split())) + [0]
diff = [abs(a - b) for a, b in zip(aaa, aaa[1:])]
sa = sum(diff)
omit = [abs(aaa[i] - aaa[i + 2]) - diff[i] - diff[i + 1] for i in range(n)]
print('\n'.join(map(str, (sa + o for o in omit))))

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from itertools import repeat
def main(ab=abs):
    n = int(stdin.readline())
    a = [0] + map(int, stdin.readline().split(), repeat(10, n)) + [0]
    d = [a[i+1] - a[i] for i in xrange(n + 1)]
    d = map(ab, d)
    s = sum(d)
    ans = [0] * n
    for i in xrange(1, n + 1):
        ans[i-1] = s - d[i] - d[i-1] + ab(a[i-1] - a[i+1])
    stdout.write('\n'.join(map(str, ans)))
main()

Submission status: Accepted

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

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

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

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:]):
    cums.append(cums[-1] + abs(a-b))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N = int(input())
A = [0] + inpl() + [0]

S1 = [abs(a-b) for a, b in zip(A[:-1], A[1:])]
S2 = [abs(a-b) for a, b in zip(A[:-2], A[2:])]

S = sum(S1)
for i in range(N):
    print(S - S1[i] - S1[i+1] + S2[i])

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(e) for e in input().split(' ')]

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

# total
total_trip = 0
for i in range(N+1):
    total_trip += abs(a_list[i+1] - a_list[i])

# res
for i in range(N):
    lag = abs(a_list[i+2] - a_list[i+1]) + abs(a_list[i+1] - a_list[i]) - abs(a_list[i+2] - a_list[i])
    print(total_trip - lag)

Submission status: Accepted

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

B = [0] + A + [0]
s = 0

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = [ 0 ] + list(map(int, input().split())) + [ 0 ]
acc = 0
for i in range(n + 1):
    acc += abs(a[i + 1] - a[i])
for i in range(n):
    result = acc
    result -= abs(a[i + 1] - a[i])
    result -= abs(a[i + 2] - a[i + 1])
    result += abs(a[i + 2] - a[i])
    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xs = [int(x) for x in input().split()]

    dests = [0] + xs + [0]
    tos = dests[1:]
    frs = dests[:-1]

    cur, allcost = 0, 0
    for dest in tos:
        allcost += abs(dest - cur)
        cur = dest

    for i in range(n):
        cost = allcost - abs(frs[i] - tos[i]) - abs(frs[i+1] - tos[i+1]) + abs(frs[i] - tos[i+1])
        print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input()
A = [0]+map(int, raw_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: Runtime Error

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