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: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

def dd_cost(L):
    c = 0
    M = L[:]
    for i in range(len(L)):
        if L[i] < 0:
            L[i] = -1
        elif L[i] > 0:
            L[i] = 1
        else:
            L[i] = 0
    L = np.array(L)
    L = L[1:]-L[:-1]
    for i in range(len(L)):
        if L[i] < 0 or L[i] > 0:
            c += abs(M[i]) * 2
    c += abs(M[-1]) * 2
    print(c)

for i in range(len(A)):
    dd_cost(A[:i]+A[i+1:])

Submission status: Time Limit Exceeded

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

def d_cost(L):
    ori = L[0]
    cost = 0
    for i in range(1, len(L)):
        if ori < 0 and L[i] > 0:
            cost += abs(ori) * 2
        elif ori > 0 and L[i] < 0:
            cost += abs(ori) * 2
        elif L[i] == 0:
            cost += abs(ori) * 2
        else:
            pass
        ori = L[i]
    cost += abs(L[-1]) * 2
    print(cost)


for i in range(len(A)):
    d_cost(A[:i]+A[i+1:])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    a_pop = [0] + a[0:i] + a[i+1:len(a)] + [0]
    ans = 0
    for i in range(len(a_pop)-1):
        ans += abs(a_pop[i+1] - a_pop[i])
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
    B = A[:i] + A[i+1:]
    B.append(0)
    B = [0] + B
    ans = 0
    for x, y in zip(B[:-1], B[1:]):
        ans += abs(x-y)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [0] + list(map(int, input().split())) + [0]
edge = []
distance = 0
for i in range(N+1):
    distance += abs(L[i] - L[i+1])
for i in range(1,N+1):
    if (L[i] -L[i-1])*(L[i+1] - L[i] )>=0:
        pass
    else:
        edge.append(i)
for i in range(1,N+1):
    if i in edge:
        print(distance-2*min(abs(L[i]-L[i+1]),abs(L[i]-L[i-1])))
    else:
        print(distance)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [0] + list(map(int, input().split())) + [0]
edge = []
distance = 0
for i in range(N+1):
    distance += abs(L[i] - L[i+1])
for i in range(1,N+1):
    if (L[i] -L[i-1])*(L[i+1] - L[i] )>=0:
        pass
    else:
        edge.append(i)
for i in range(N+1):
    if i in edge:
        print(distance-2*min(abs(L[i]-L[i+1]),abs(L[i]-L[i-1])))
    else:
        if i == 0:
            pass
        else:
            print(distance)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.append(0)
for i in range(len(A)-1):
    ans = 0
    now = 0
    for j in range(len(A)):
        if i != j:
            ans += abs(A[j] - now)
            now = A[j]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans=0
A = list(map(int, input().split()))
for i in range(1, n+1):
    B = A[:i-1]
    C = A[i:]
    D = B+C
    D.append(0)
    for i in range(0, n-1):
        if((D[i] < 0 and D[i+1] < 0) or (D[i] > 0 and D[i+1] > 0)):
            continue
        else:
            ans+=abs(D[i]*2)
    print(ans)
    ans=0

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans=0
A = list(map(int, input().split()))
for i in range(1, n+1):
    B = A[:i-1]
    C = A[i:]
    D = B+C
    D.append(0)
    for i in range(0, n-1):
        if(D[i] < 0 and D[i+1] < 0):
            continue
        elif(D[i]>0 and D[i+1] > 0):
            continue
        else:
            ans+=abs(D[i]*2)
    print(ans)
    ans=0

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
size = len(A)
a = np.array([[A[i] for i in range(size) if i != l] for l in range(1, size-1)])

total = np.zeros(N, dtype='int64')

for i in range(size-2):
    total += np.abs(a[:, i]-a[:, i+1])

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

Submission status: Time Limit Exceeded

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



for i in range(1,n+1):
  if i==n:
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
    exit()
  elif A[i]<=A[i+1] and ((A[i]>0 and A[i+1]<0) or (A[i]<0 and A[i+1]>0)):
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  elif A[i]<=A[i+1]:
    print(sum(diff))
  else:
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=[int(i) for i in input().split()]
#print(n,x)
for i in range(n):
  y=x[0:i]+x[i+1:]
#  print(y)
  dist=abs(y[0])
  for j in range(len(y)-1):
    dist+=abs(y[j]-y[j+1])
  dist+=abs(y[-1])
  print(dist)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
AL = list(A)
L = [0]*N
for i in range(0,N):
    AL = list(A)
    del(AL[i])
    L[i] = abs(AL[0])
    for j in range(0,len(AL)-1):
        L[i] += abs(AL[j+1]-AL[j])
    L[i] += abs(AL[len(AL)-1])
        

for i in range(0,N):
    print(L[i])

Submission status: Time Limit Exceeded

Solution code:
def abc092_c():
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n):
        tmp_a = a.copy()
        del tmp_a[i]
        money = abs(tmp_a[0]) + abs(tmp_a[-1])
        for j in range(n - 2):
            money += abs(tmp_a[j] - tmp_a[j + 1])
        print(money)


abc092_c()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def get_cost(li) :
    li = [0] + li + [0]
    cost = 0
    for i in range(1,len(li)) :
        cost += abs(li[i-1] - li[i])
    return cost

N = int(input())
li = [int(i) for i in input().split()]

cost = 0
for i in range(N) :
    l = li[:]
    del l[i]
    cost += get_cost(l)
    print(cost)
    cost = 0

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
for i in range(a):
    count = 0
    st =  0
    for j in range(a):
        if j != i:
            count += abs(st-ar[j])
            st = ar[j]
    count += abs(st-0)
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(N):
    li = []
    for l in range(N):
        li.append(A_list[l])
    del li[i]
    ans = abs(li[0]) + abs(li[N-2])
    for m in range(N-2):
        ans += abs(li[m] - li[m+1])
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n=int(input())
l=list(map(int,input().split()))
l.append(0)
l.insert(0,0)
#print(l)
dis=copy.deepcopy(l)
for i in range(1,n+2):
    dis[i]=abs(l[i]-l[i-1])
dis=dis[1:n+2]
#print(dis)
for i in range(n):
    print(sum(dis)-dis[i]-dis[i+1]+abs(l[i]-l[i+2]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(len(A)) :
    ans = 0
    p = 0
    for j in range(len(A)) :
        if j == i :
            continue
        else :
            ans += abs(p-A[j])
            p = A[j]
    ans += abs(p)
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n+1):
    origin_dif.append(a[i]-a[i+1])

origin_dif = tuple(origin_dif)

for i in range(n):
    dif = list(origin_dif)
    x = dif.pop(i) + dif.pop(i)
    dif.append(x)
    absed = list(map(abs,dif))
    print(sum(absed))

Submission status: Time Limit Exceeded

Solution code:
#ABC092C
#Input
N=int(input())
A=list(map(int, input().split()))
#Prepare
Now=0
Next=0
ans=0
#Processing
for i in range(N):
    ans=0
    Now=0
    for j in range(N):
        if j!=i:
            Next=A[j]
            ans+=abs(Next-Now)
            Now=Next
    ans+=abs(0-Now)
    print(ans)

Submission status: Time Limit Exceeded

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


A = [0] + A + [0]

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    x = a.pop(i)
    ans, c = 0, 0
    for j in a:
        ans += abs(c-j)
        c = j
    a.insert(i, x)
    ans += abs(c-0)
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    d = a[i+1]
    del(a[i+1])
    c = 0
    for j in range(1,n+1):
        c += abs(a[j]-a[j-1])
    print(c)
    a.insert(i+1,d)

Submission status: Time Limit Exceeded

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

for i in range(n):
    d = a[i+1]
    del(a[i+1])
    c = 0
    for j in range(n+1)[1:n+1]:
        c += abs(a[j]-a[j-1])
    print(c)
    a.insert(i+1,d)

Submission status: Time Limit Exceeded

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

amounts = [0] * N

for n in range(N):
    spot = A[:n] + A[(n+1):]

    amount = 0
    for i in range(1, N - 1):
        amount += abs(spot[i-1] - spot[i])
    amount += abs(spot[0])
    amount += abs(spot[N - 2])
    amounts[n] = amount

for i in range(N):
    print(amounts[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
visitSpot = list(map(int, input().split()))
listForAnswer =[]
index=0
while index<len(visitSpot):
    index2=0
    sum=0
    while index2<len(visitSpot):
        if index2 ==index:
            index2+=1
        elif sum ==0:
            sum+=(max(visitSpot[index2], 0)-min(visitSpot[index2],0))
            index2+=1
        else:
            if index2-1 != index:
                sum+=(max(visitSpot[index2], visitSpot[index2-1])-min(visitSpot[index2],visitSpot[index2-1]))
            else:
                sum+=(max(visitSpot[index2], visitSpot[index2-2])-min(visitSpot[index2],visitSpot[index2-2]))
                flag =0
            index2+=1
    if index2-1!=index:
        sum+=(max(visitSpot[index2-1], 0)-min(visitSpot[index2-1],0))
    else:
        sum+=(max(visitSpot[index2-2], 0)-min(visitSpot[index2-2],0))
    listForAnswer.append(sum)
    index+=1

for ans in listForAnswer:
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    route = copy.deepcopy(A)
    route.pop(i)
    route.insert(0,0)
    route.append(0)
    #print(route)
    dist = 0
    for j in range(N):
        dist += abs(route[j]-route[j+1])
    print(dist)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
for _n in range(n):
  sm = 0
  x = 0
  for i,_a in enumerate(a):
    if _n == i: 
      continue
    sm += abs(_a - x)
    x = _a
  sm += abs(x)
  print(sm)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    cost = 0
    pos = 0
    for j in range(N):
        if(i == j):
            continue
        cost += abs(A[j] - pos)
        pos = A[j]
    cost += abs(pos)
    print(cost)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 14:35:24 2018

@author: sugawara
"""

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    #N = 6
    #A = [-679, -2409, -3258, 3095, -3291, -4462]
    # iからi+1への移動距離
    delta_A = [abs(A[0])] + [abs(A[i] - A[i-1]) for i in range(1, N)]
    
    #i番目を抜かしたときの
    delta_A_1skip = [abs(A[1])] + [abs(A[i+1] - A[i-1]) for i in range(1, N-1)] + [abs(A[N-2])]
    
    res = []
    for i in range(N):
        # i番目を抜いた場合を考える
        tmp_delta_A = delta_A[:i] + [delta_A_1skip[i]] + delta_A[i+2:]
        if i != N-1:
            tmp_delta_A.append(abs(A[-1]))
        res.append(sum(tmp_delta_A))
    #    break
        
    for i in range(N):
        print(res[i])
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 14:35:24 2018

@author: sugawara
"""

N = int(input())
A = [int(i) for i in input().split()]
#N = 6
#A = [-679, -2409, -3258, 3095, -3291, -4462]
# iからi+1への移動距離
delta_A = [abs(A[0])] + [abs(A[i] - A[i-1]) for i in range(1, N)]

#i番目を抜かしたときの
delta_A_1skip = [abs(A[1])] + [abs(A[i+1] - A[i-1]) for i in range(1, N-1)] + [abs(A[N-2])]

res = []
for i in range(N):
    # i番目を抜いた場合を考える
    tmp_delta_A = delta_A[:i] + [delta_A_1skip[i]] + delta_A[i+2:]
    if i != N-1:
        tmp_delta_A.append(abs(A[-1]))
    res.append(sum(tmp_delta_A))
#    break
    
for i in range(N):
    print(res[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.append(0)
cost=0
for idx in range(N):
    b=a.copy()
    b.pop(idx)
    cost=0
    for i in range(len(b)):
        if i==0:
            cost+=abs(b[i])
        else:
            cost+=abs(b[i-1]-b[i])
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(list, int)

for idx in range(len(a)):
    tmp_a = deepcopy(a)
    tmp_a.pop(idx)
    tmp_a.append(0)

    pred = 0
    length = 0
    for el in tmp_a:
        length += abs(el - pred)
        pred = el
    print(length)

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    dd = d.copy()
    a = dd[i]
    b = dd[i+1]
    dd[i] = a + b
    dd.pop(i+1)
    print(sum(map(abs, dd)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import *

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

res = []
for i in range(len(A)):
    r = 0
    a = [0] + A[0:i] + A[i+1:] + [0]
    for j in range(len(a)-1):
        r += abs(a[j+1] - a[j])
    res.append(r)
for i in res:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

tmp = [0]*N

for i in range(N):
    genzaichi = 0
    count = 0
    tmp = A[:i] + A[i+1:]
    for j in tmp:
        count += abs(genzaichi- j)
        genzaichi = j
    count += abs(genzaichi)
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split(" ")))
for i in range (1 , n + 1):
    current = a[:]
    current.pop(i-1)
    money = abs(0 - current[0])
    if 2 < n:
        for j in range (1,len(current)):
            money = abs(current[ j - 1] - current[j]) + money
        money = money + abs(current[len(current) - 1])
    else :
        money = money + abs(0 - current[0])
    print(money)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
travel = list(map(int,input().split()))
plan = travel.copy()
start = 0
answer = 0
answer_list = list()

for i in range(n):
    plan.pop(i)
    for j in range(len(plan)):
        answer += abs(plan[j]-start)
        start = plan[j]
    answer += abs(plan[len(plan)-1])
    answer_list.append(answer)
    answer = 0
    start = 0
    plan = travel.copy()
    
for i in range(len(answer_list)):
    print(answer_list[i])

Submission status: Time Limit Exceeded

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


for i in range(N):
    tujyo=0
    S=0

    for k in range(N):
        if i!=k:
            
            tujyo+=abs(A[k]-S)
            S=A[k]
          
    tujyo+=abs(0-S)
    print(tujyo)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=input()
are=list(map(int,input().split()))
for i in range(len(are)):
    kotae=0
    sin=[0]
    for j in range(len(are)):
        if j != i:
            sin.append(are[j])
    sin.append(0)
    for k in range(len(sin)-1):
        kotae += abs(sin[k+1]-sin[k])
    print(kotae)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
spots_tuple = tuple(list(map(int,input().split(' '))))

for i in range(N):
    spots = list(spots_tuple)
    del spots[i]
    travel_fee = abs(spots[0])
    for q in range(1,N - 1):
        travel_fee += abs(spots[q] - spots[q - 1])
    travel_fee += abs(spots[N - 2])
    print(travel_fee)

Submission status: Time Limit Exceeded

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

for i in range(N):
    A_temp = [j for j in A]
    A_temp.pop(i)
    A_temp.insert(0, 0)
    cost = [0 for n in range(N)]
    for j in range(1, N):
        if A_temp[j] * A_temp[j-1] >= 0 :#パターンその位置
            cost[j] = abs(A_temp[j]-A_temp[j-1]) + cost[j-1]
        elif A_temp[j] * A_temp[j-1] < 0: #符号反転の場合
            cost[j] = cost[j-1] + abs(A_temp[j-1]) + abs(A_temp[j])

    print(max(cost)+abs(A_temp[len(A)-1]))

Submission status: Time Limit Exceeded

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

if n == 2:
    print(abs(a[1]) * 2)
    print(abs(a[0]) * 2)
else:
    for i in range(len(a)):
        cost = 0
        if i == 0:
            cost += abs(a[1]) + abs(a[-1])
            for j in range(1, len(a)-1):
                cost += abs(a[j] - a[j+1])
            print(cost)
        elif i == len(a)-1:
            cost += abs(a[0]) + abs(a[-2])
            for j in range(0, len(a)-2):
                cost += abs(a[j] - a[j+1])
            print(cost)
        else:
            cost += abs(a[0]) + abs(a[-1]) + abs(a[i+1] - a[i-1])
            for j in range(i-1):
                cost += abs(a[j] - a[j+1])
            for j in range(i+1, len(a)-1):
                cost += abs(a[j] - a[j+1])
            print(cost)

Submission status: Time Limit Exceeded

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

if n == 2:
    print(abs(a[1]) * 2)
    print(abs(a[0]) * 2)
else:
    for i in range(len(a)):
        b = a[:]
        b.remove(b[i])
        #print(b)
        
        cost = abs(b[0]) + abs(b[-1])
        for i in range(len(b)-1):
            cost += abs(b[i] - b[i+1])
        print(cost)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
a.append(0)
for i in range(n):
    c = 0
    p = 0
    for j in range(n+1):
        if j == i:
            continue
        c += abs(a[j] - p)
        p = a[j]
    print c

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A0 = list(map(int, input().split()))
A = [0] + A0 + [0]
for i in range (1, N+1):
    tot = 0
    j = 0
    while j < N+1:
        if j+1 != i:
            tot += abs(A[j+1]-A[j])
            j += 1
        else:
            tot += abs(A[j+2]-A[j])
            j += 2
    print(tot)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    out = a[:i] + a[i+1:]
    old = 0
    way = [abs(out[i]-out[i-1]) for i in range(1,n-1,1)]
    print(sum(way)+abs(out[0])+abs(out[-1]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    out = a[:i] + a[i+1:]
    sum = 0
    old = 0
    for o in out:
        sum += abs(old-o)
        old = o
    print(sum+abs(out[-1]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
raw_a = list(map(int,input().split()))
a = [0] + raw_a + [0]
for i in range(1, n+1):  # スキップするもの
    count = 0
    for j in range(i-1):  # i-1まで
        count += abs(a[j+1] - a[j])
    count += abs(a[i+1] - a[i-1])
    for j in range(i+1, n+1):
        count += abs(a[j+1] - a[j])
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())                                                                                     
a=list(map(lambda x:int(x), input().split()))                                                      
a.insert(0,0)                                                                                      
a.append(0)                                                                                        
count=0                                                                                            
d=[abs(a[i]-a[i+1]) for i in range(0, n+1)]                                                        
for i in range(1, n+1):                                                                            
    c=sum(d[:i-1])+sum(d[i+1:])                                                                    
    c+=abs(a[i-1]-a[i+1])                                                                          
    print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int,input().split()))
arr.insert(0,0)
arr.append(0)
ans = 0
tmp = 0
for i in range(1,n + 1):
    for j in range(1,len(arr)):
        if i == j:
            pass
        else:
            ans += abs(arr[j] - tmp)
            tmp = arr[j]
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())
a=list(map(lambda x:int(x), input().split()))
for ri in range(n):
    count=0
    cpa	= a[:]
    cpa.pop(ri)
    cpa.insert(0, 0)
    cpa.append(0)
    for i in range(len(cpa)):
        if i+1>=len(cpa):
            break
        count+=math.fabs(cpa[i]-cpa[i+1])
    print(int(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [0]+A[:]+[0]
C = A[:]+[0]+[0]
D = [abs(i-j) for i, j in zip(B, C)]

for i in range(N):
    if B[i] < B[i+1] and B[i+1] <B[i+2]:
        print(sum(D))
    else:
        t = abs(B[i+1]-B[i])+abs(B[i+2]-B[i+1])-abs(B[i+2]-B[i])
        print(sum(D)-t)

Submission status: Time Limit Exceeded

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

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

for j in range(N):
        print(sum(Diff)-sum(Diff[j:j+2])+abs(A[j]-A[j+2]))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A= [int(i) for i in input().split()]
import copy
for i in range(N):
    B=copy.deepcopy(A)
    B.pop(i)
    dist=0
    dist=dist+abs(B[0])
    for j in range(1,N-1):
        dist=dist+abs(B[j-1]-B[j])
    dist=dist+abs(B[N-2])
    print(dist)

Submission status: Time Limit Exceeded

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

A.insert(0,0)
sum=0


for i in range(N):
    sum=0
    tmp = A.pop(i+1)
#    print('tmp',tmp)

    for j in range(1,N):
        sum+=abs(A[j]-A[j-1])
#        print('sum',sum)
    sum+=abs(A[N-1])
    print(sum)
    A.insert(i+1,tmp)