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

for i in range(N):
  b = A[i]
  if i == 0:
    a = 0
  else:
    a = A[i-1]
  if i == N-1:
    c = 0
  else:
    c = A[i+1]
  if a <= b and b <= c:
    print(s)
  elif a <= c and c <= b:
    print(s-(b-c)*2)
  elif b <= a and a <= c:
    print(s-(a-b)*2)
  elif b <= c and c <= a:
    print(s-(c-b)*2)
  elif c <= a and a <= b:
    print(s-(b-a)*2)
  else:
    print(s)

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


sum = sum(diff)
  

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

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


sum = sum(diff)
  

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

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


sum = 0
for i, a in enumerate(A):
  if i == n+1: break 
  sum += abs(a - A[i+1]) 
  

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

Solution (Python):
n = int(input())
tmpa = list(map(int, input().split()))
A = [0] * (n+2)
A[0] = 0
A[n+1] = 0
for i in range(1,n+1,1): A[i] = tmpa[i-1]



sum = 0
for i, a in enumerate(A):
  if i == n+1: break 
  sum += abs(a - A[i+1]) 
  

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

Solution (Python):
N=int(input())
ai=list(map(int,input().split()))

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

print(sum - abs(0-ai[0]) - abs(ai[0]-ai[1]) + abs(0-ai[1]))

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

print(sum - abs(ai[N-2]-ai[N-1]) - abs(ai[N-1]-0) + abs(ai[N-2]-0))

Solution (Python):
N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(1,N+1):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)

Solution (Python):
n = int(input())
a = [0]
a.extend([int(i) for i in input().split()])
a.append(0)
b = [0]*(n+2)
for i in range(n+1):
    b[i+1] = b[i] + abs(a[i+1] - a[i])
for i in range(n):
    ans = b[-1] + abs(a[i+2] - a[i]) - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1])
    print(ans)

Solution (Python):
n=int(input())
m=[0]+list(map(int,input().split()))+[0]
ans=0
l1=[]
l2=[]
for i in range(n+1):
  ans+=abs(m[i+1]-m[i])
for i in range(1,n+1):
  l1.append(abs(m[i]-m[i-1])+abs(m[i]-m[i+1]))
  l2.append(abs(m[i+1]-m[i-1]))
for i in range(n):
  print(ans-l1[i]+l2[i])

Solution (Python):
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):
  shortcut = - abs(A[i-1]-A[i+1]) + abs(A[i-1]-A[i]) + abs(A[i] - A[i+1])
  print(total- shortcut)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0]+[int(_) for _ in stdin.readline().rstrip().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-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))

Solution (Python):
import math
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
a = LI()
a.insert(0,0)
a.append(0)
diff = [abs(a[i] - a[i-1]) for i in range(1,len(a))]
money = sum(diff)


for i in range(1,len(a)-1):
    if a[i-1] <= a[i] <= a[i+1]:
        print(money)
    elif a[i+1] <= a[i] <= a[i-1]:
        print(money)
    elif a[i] <= a[i-1] <= a[i+1]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i+1] <= a[i-1] <= a[i]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i-1] <= a[i+1] <= a[i]:
        print(money-2*abs(a[i+1]-a[i]))
    else:
        
        print(money-2*abs(a[i+1]-a[i]))

Solution (Python):
import math
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
a = LI()
a.insert(0,0)
a.append(0)
diff = [abs(a[i] - a[i-1]) for i in range(1,len(a))]
money = sum(diff)


for i in range(1,len(a)-1):
    if a[i-1] <= a[i] <= a[i+1]:
        print(money)
    elif a[i+1] <= a[i] <= a[i-1]:
        print(money)
    elif a[i] <= a[i-1] <= a[i+1]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i+1] <= a[i-1] <= a[i]:
        print(money-2*abs(a[i-1]-a[i]))
    elif a[i-1] <= a[i+1] <= a[i]:
        print(money-2*abs(a[i+1]-a[i]))
    else:
        
        print(money-2*abs(a[i+1]-a[i]))

Solution (Python):
from numpy import*
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
b=sum(abs(array(a[1:])-array(a[:-1])))

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

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

d = {}
dd = {}
for i in range(N+1):
    d[i] = abs(A[i+1] - A[i])
for i in range(N):
    dd[i] = abs(A[i+2] - A[i])

sA = sum(d.values())
for i in range(N):
    ans = sA - d[i+1] - d[i] + dd[i]
    print(ans)

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

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

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

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

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

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

total = 0
costs = []
for i in range(1, N+1):
    total += abs(As[i] - As[i-1])
    x1 = As[i] - As[i-1]
    x2 = As[i+1] - As[i-1]
    if x1 * x2 >= 0 and abs(x1) <= abs(x2):
        costs.append(0)
    elif x1 * x2 >= 0 and abs(x1) > abs(x2):
        costs.append(2 * abs(x2 - x1))
    elif x1 * x2 < 0:
        costs.append(2 * abs(x1))
total += abs(As[N+1] - As[N])

for i in range(N):
    print(total - costs[i])

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

sum_all = 0
for i in range(N+2):
 if(i != 0):
  sum_all += abs(A[i]-A[i-1])








for i in range(N+2):
  if((i != 0)and(i != N+1)):
    cost_prev = abs(A[i-1]-A[i])+abs(A[i]-A[i+1])
    cost_after = abs(A[i-1]-A[i+1])
    ans = sum_all - cost_prev + cost_after
    print(ans)

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

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()] + [0]
dist = []
tmp = 0
alldist = 0

for i in A:
    dist.append(i-tmp)
    tmp = i

for i in dist:
     alldist += abs(i)

for i in range(N):
    print(alldist - (abs(dist[i])+abs(dist[i+1])-abs(dist[i]+dist[i+1])))

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

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

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

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

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

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

Solution (Python):


II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    N = II()
    A = [0] + MIL() + [0]
    d = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
    cost = sum(d)

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


if __name__ == "__main__":
    main()

Solution (Python):
A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j==0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-2*abs(B[0]))
        else:
            print(S-2*abs(B[1]-B[0]))
    elif j==len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-2*abs(B[-1]))
        else:
            print(S-2*abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-2*abs(B[j-1]-B[j]))
        else:
            print(S-2*abs(B[j+1]-B[j]))

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


sums = abs(a[0])
flags = [0 for _ in range(n+1)]

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

a.insert(0,0)

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

Solution (Python):
a = int(input())
ar = list(map(int,input().split(" ")))
ar.insert(0,0)
ar.append(0)
count = 0
for i in range(1,a+2):
    count += abs(ar[i]-ar[i-1])
for i in range(1,a+1):
    b = abs(ar[i-1]-ar[i+1])
    c = abs(ar[i-1]-ar[i])
    d = abs(ar[i]-ar[i+1])
    print(count + b - c - d)

Solution (Python):
N = input()
A = [0] + map(int, raw_input().split()) + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    print cost - abs(a - b) - abs(b - c) + abs(a - c)

Solution (Python):
N = input()
A = map(int, raw_input().split())
A = [0] + A + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    if max(a, b, c) == b or min(a, b, c) == b:
        diff = - abs(a - b) - abs(b - c) + abs(a - c)
    else:
        diff = 0
    print cost + diff

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

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

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

AA = [0]
AA.extend(A)
AA.append(0)

Adif1 = []

for i in range(1, N + 2):
	x = abs(AA[i] - AA[i - 1])
	Adif1.append(x)

s = sum(Adif1)

Adif2 = []

for i in range(2, N + 2):
	x = abs(AA[i] - AA[i - 2])
	Adif2.append(x)

for i in range(N):
	print(s + Adif2[i] - Adif1[i] - Adif1[i + 1])

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

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

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = [0]+inpl()+[0]
sumtr = 0
for i in range(N+1):
    sumtr += abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(sumtr +abs(A[i+1]-A[i-1]) -abs(A[i]-A[i-1]) -abs(A[i+1]-A[i]))

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = [0]+inpl()+[0]
sumtr = 0
for i in range(N+1):
    sumtr += abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(sumtr +abs(A[i+1]-A[i-1]) -abs(A[i]-A[i-1]) -abs(A[i+1]-A[i]))

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

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

for i in range(n):
    mae = 0 if i == 0 else a[i-1]
    ato = 0 if i == n-1 else a[i+1]
    q = abs(a[i] - mae) + abs(ato - a[i])
    w = abs(ato - mae)
    print(s - q + w)

Solution (Python):
N=int(input().strip())
a=[0]
b=list(map(int, input().split()))
for i in range(N):
    a.append(b[i])
a.append(0)

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
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]:
        sub = 0
    elif A[i-1] <= A[i+1] <= A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] <= A[i-1] <= A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] <= A[i-1] <= A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] <= A[i+1]<= A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(cost - sub)

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

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L = [0]+L+[0]
All = 0
for i in range(N+1) :
    All += abs(L[i]-L[i+1])
for i in range(1,N+1) :
    ans = All + abs(L[i-1]-L[i+1]) - (abs(L[i-1]-L[i]) + abs(L[i]-L[i+1]))
    print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]


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

for i in range(1, N + 1):
    d1 = abs(A[i - 1] - A[i])
    d2 = abs(A[i + 1] - A[i])
    d3 = abs(A[i - 1] - A[i + 1])
    print(sum - d1 - d2 + d3)

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

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

S = 0

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

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

Solution (Python):

n = int(input())
va = [0] + list(map(int, input().split())) + [0]
diffs = []

total = 0
for i, j in zip(va, va[1:]):
    total += abs(j-i)

for i, j, k in zip(va, va[1:], va[2:]):
    print(total-(abs(j-i)+abs(k-j)-abs(k-i)))

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

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

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

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

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = 0
for a, b in zip(A, A[1:]):
    cost += abs(a - b)
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]))

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])
ans_pre = 0
for i in range(0,n+1):
    ans_pre += abs(list_memo[i])
for i in range(0,n):
    ans = ans_pre - abs(list_memo[i]) - abs(list_memo[i+1]) + abs(list_memo[i] + list_memo[i+1])
    print(ans)

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

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

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

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

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

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

Solution (Python):
N=int(input())

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

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

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



for i in range(N):
  if i==0:
    
    if (0<=A[i] and A[i]<=A[i+1]) or (0>=A[i] and A[i]>=A[i+1]):
      print(distance)
    
    else:
      print(distance-(abs(A[i])+abs(A[i+1]-A[i]))+abs(A[i+1]))
  elif i==N-1:
    
    if (A[i-1]<=A[i] and A[i]<=0) or (A[i-1]>=A[i] and A[i]>=0):
      print(distance)
    
    else:
      print(distance-(abs(A[i]-A[i-1])+abs(A[i]))+abs(A[i-1]))
  else:
    
    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(distance)
    
    
    
    else:
      print(distance-(abs(A[i]-A[i-1])+abs(A[i+1]-A[i]))+abs(A[i+1]-A[i-1]))

Solution (Python):
n = int(input())


arr = []
arr.append(0) 
arr.extend(map(int,raw_input().split()))
arr.append(0)

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

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

Solution (Python):
def main():
  N = int(input())
  t = input().split(" ")
  a = [0] + [int(i) for i in t] + [0]
  
  d = []
  dd = []
  sum = 0
  for i in range(N+1):
    d.append(abs(a[i] - a[i+1]))
    if i != 0:
      dd.append(abs(a[i-1] - a[i+1]))
    sum += d[i]
  for i in range(N):
    print(sum - d[i] - d[i+1] + dd[i])
main()

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

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

route_sum += abs(a[n - 1])

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

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = [0] + reads() + [0] 
planned = sum(abs(A[i+1] - A[i]) for i in range(N+1))
for i in range(1, N+1):
  diff = abs(A[i+1]-A[i]) + abs(A[i]-A[i-1]) - abs(A[i+1]-A[i-1])
  print(planned - diff)

Solution (Python):
def solve(n, xs):
    ss = [0] + [abs(a - b) for (a, b) in zip(xs + [0], [0] + xs)]
    for i in range(1, n + 1):
        ss[i + 1] += ss[i]
    cost2 = [abs(a - b) for (a, b) in zip(xs[1:] + [0], [0] + xs[:n - 1])]
    for k in range(n):
        yield ss[n + 1] - ss[k + 2] + ss[k] + cost2[k]

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    for ans in solve(n, xs):
        print(ans)

Solution (Python):
import numpy as np
import math

N = int(input())

spot = np.zeros(N + 1)
spot[1:] = np.array(list(map(int, input().split())))

tot = int(np.abs(np.roll(spot, 1) - spot).sum())

for i in range(1, N+1):
    print(int(tot - math.fabs(spot[i] - spot[i-1]) - math.fabs(spot[(i+1) % (N+1)] - spot[i])\
            + math.fabs(spot[(i+1) % (N+1)] - spot[i-1])))

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

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

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

Solution (Python):
from operator import itemgetter

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

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

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A+[0]
travel=0
for i in range(N+1):
    travel+=abs(A[i+1]-A[i])
ans =[]
for i in range(1,N+1):
    ans.append(travel-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
print('\n'.join(map(str,ans)))

Solution (Python):
N = int(input())

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

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

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

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

Solution (Python):
import numpy as np
n = int(input())
a = np.empty(n+2, dtype=np.int)
a[0] = 0
a[n+1] = 0
a[1:n+1] = np.int64(input().split())
da = np.absolute(a[1:] - a[:-1])
gain = da[1:] + da[:-1]
loss = np.absolute(a[2:] - a[:-2])
s = da.sum()
for i in range(n):
    print(s+loss[i]-gain[i])

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

Solution (Python):
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)
cost = [abs(A[i] - A[i+1]) for i in range(N+1)]
allcost = sum(cost)
for i in range(N):
    print(allcost - cost[i] - cost[i+1] + abs(A[i]-A[i+2]))

Solution (Python):
n = int(input())
lis = [0] + list(map(int, input().split())) + [0]
tmp = []
for j in range(len(lis)-1):
    tmp.append(lis[j+1] - lis[j])
lis = list(map(abs,tmp))
preans = sum(lis)
for i in range(len(tmp)-1):
    print(preans - lis[i] - lis[i+1] + abs(tmp[i] + tmp[i+1]))

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

Solution (Python):
num = input()
num_list = [int(i) for i in input().split(' ')]

from collections import deque

def cal_minus(three_pos):
    p = three_pos[0]
    c = three_pos[1]
    n = three_pos[2]
    dic = {'p':p, 'c': c, 'n':n}
    sorted_dict = sorted(dic.items(), key=lambda x : x[1])
    name = sorted_dict[1][0]
    if name == 'p':
        return 2 * abs(p-c)
    elif name == 'c':
        return 0
    else:
        return 2 * abs(c-n)
        

minus_list = []
three_pos = deque([0, num_list[0], num_list[1]])
for i in range(0, len(num_list)):
    minus = cal_minus(three_pos)
    minus_list.append(minus)
    if i < len(num_list)-2:
        next_ = num_list[i + 2]
    else:
        next_ = 0
    three_pos.append(next_)
    three_pos.popleft()
    
all_ = 0
pre = 0
for i in range(len(num_list)):
    plus = abs(num_list[i] - pre)
    pre = num_list[i]
    all_ += plus
all_ += abs(num_list[-1])

for i in minus_list:
    print(all_-i)

Solution (Python):



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)
    
    
    for diff in diffs:
        print(dist - diff)


solve()

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

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

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

Solution (Python):

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

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

Solution (Python):



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

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

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

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

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

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

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

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

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