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

Solution (Python):
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())

Solution (Python):
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)

Solution (Python):


num = int(raw_input())

array = map(int, raw_input().split())



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)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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]))

Solution (Python):
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








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)


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




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

Solution (Python):
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)


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

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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]))

Solution (Python):
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])

Solution (Python):
N = long(raw_input())
A = map(int, raw_input().split())
A = [0] + A + [0]


maxCost = 0


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




for x in range(1, len(A) - 1, 1):
    
    umove1 = abs(A[x - 1] - A[x])
    umove2 = abs(A[x] - A[x + 1])
    
    amove = abs(A[x - 1] - A[x + 1])
    print maxCost - umove1 -umove2 + amove

Solution (Python):
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]))

Solution (Python):
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)

Solution (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__':
    
    main()

Solution (Python):
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()

Solution (Python):
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]))






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

Solution (Python):
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)

Solution (Python):
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)]


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

    

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

Solution (Python):
import math

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


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

Solution (Python):
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]

ttl = sum(cost)


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)

Solution (Python):


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

Solution (Python):



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

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
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

Solution (Python):



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


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


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

Solution (Python):
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]))

Solution (Python):


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)

Solution (Python):
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])

Solution (Python):
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]))

Solution (Python):
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)))

Solution (Python):
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()

Solution (Python):
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))))

Solution (Python):
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()

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):

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


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


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)

Solution (Python):
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')

Solution (Python):

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)

Solution (Python):
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]))

Solution (Python):
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()

Solution (Python):
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])