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 math
N=int(input())
m=0
sum=0
A=[]

a=input().split()
for i in range(N):
 m=int(a[i])
 A.append(m)

for i in range(N):
 n=A[i]
 A.pop(i)
 sum +=abs(A[0])+abs(A[N-2])
 for j in range(N-2):
  sum+=abs(A[j]-A[j+1])
 A.insert(i,n)
 print(sum)
 sum=0

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C


if __name__ == '__main__':
    spot_count = int(input())
    mod_spots = [0] + list(map(int, input().split())) + [0]

    # FIXME: TLE
    for i in range(spot_count):
        tmp = mod_spots[i + 1]
        if mod_spots[i] <= mod_spots[i + 2]:
            mod_spots[i + 1] = mod_spots[i]
        elif (mod_spots[i] > 0) and mod_spots[i + 2] > 0:
            mod_spots[i + 1] = 0
        else:
            mod_spots[i + 1] = mod_spots[i]

        cost = sum([abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)])
        mod_spots[i + 1] = tmp
        print(cost)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    SpotNum = int(input())
    SpotCoordinate = [int(i) for i in input().split()]
    
    SpotCoordinate.insert(0, 0)
    SpotCoordinate.append(0)
    
    DiffSpotCoordinate = abs(np.diff(SpotCoordinate))
#    print(DiffSpotCoordinate)
    
    for i in range(SpotNum):
        Diff = abs(SpotCoordinate[i] - SpotCoordinate[i+2] )
#        print(Diff)
        result = Diff + sum(DiffSpotCoordinate[:i]) + sum(DiffSpotCoordinate[i+2:])
#        print(RmSpotCoodinate)
#        print(sum(abs(np.diff(RmSpotCoordinate))))
        print(result)
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -- coding: utf-8 --
def calc_cost(point_list):
    current_x = 0
    cost = 0
    point_list.append(0)
    for i in point_list:
        cost += abs(i - current_x)
        current_x = i
    return cost

if __name__ == '__main__':
    N = int(input())
    Cing_spot = list(map(int, input().split(' ')))
    for i in range(len(Cing_spot)):
        print(calc_cost(Cing_spot[:i] + Cing_spot[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A.insert(0, 0)

    d_map = dict()
    d_map[(0,)] = 0

    for i in range(1, N + 1):
        prev_path = (0,)
        for j in range(1, N + 1):
            if i == j:
                continue

            path = prev_path + (j,)
            d_map[path] = d_map[prev_path] + abs(A[j] - A[prev_path[-1]])
            prev_path = path

        path = prev_path + (0,)
        d_map[path] = d_map[prev_path] + abs(A[0] - A[prev_path[-1]])
        print(d_map[path])

Submission status: Time Limit Exceeded

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

for i in range(N):
    A=copy.deepcopy(a)
    A.pop(i)
    A.insert(0,0)
    A.append(0)
    A.append(0)
    B=copy.deepcopy(A)
    B.insert(0,0)
    A_B=[abs(x-y) for (x,y) in zip(A,B)]
    print(sum(A_B))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

spot = input().split()

for i in range(n):
    total = 0

    pos = 0
    
    for l in range(n):
        if i != l:
            money = pos - int(spot[l])
            pos = int(spot[l])
            
            if money < 0:
                money *= -1
            total += money

    if pos < 0:
        pos *= -1
    total += pos
    
    print(total)

Submission status: Time Limit Exceeded

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

def list_set(a,y):
    B = list(a)
    B.pop(y)
    B.insert(0, 0)
    return B
 
 
for y in range(N):
    a = list_set(A,y)
    price = 0
    
    for x in range(len(a)-1):
        price += abs(a[x+1] - a[x])
    price += abs(a[-1])
    print(price)

Submission status: Time Limit Exceeded

Solution code:
def calcbudget(A,i,N):
    bud = 0
    i = i + 1
    next = True
    B = [0]
    B.extend(A)
    B.append(0)
    for j in range(len(B)):
        if j!=N+1:
            if j + 1 != i:
                if next:
                    bud = bud + abs(B[j] - B[j+1])
                else:
                    next = True
            else:
                bud = bud + abs(B[j] - B[j+2])
                next = False
        else:
            return bud

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

budget = []
for i in range(N):
    print(calcbudget(A,i,N))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = sum([abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)])

    for i in range(N):
        spam = Ai[:]
        del spam[i]
        spam = [0] + spam + [0]

        if foo[i] <= foo[i + 1] <= foo[i + 2] or foo[i + 2] <= foo[i + 1] <= foo[i]:
            print(bar)
        else:
            ham = [abs(spam[i] - spam[i + 1]) for i in range(len(spam) - 1)]
            print(sum(ham))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
#print(A)
costs = [0]*N
for i in range(N):
    tmp = A
    A = np.delete(A,i)
    A = np.insert(A,0,0)
    A = np.append(A,0)
    #print(A)
    costs[i] = np.sum(np.abs(np.diff(A)))
    A = tmp
for i in range(len(costs)):
    print(costs[i])

Submission status: Time Limit Exceeded

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

def f(list):
    ans = 0
    ans += abs(list[-1])
    for i, ai in enumerate(list):
        if not (i+1 == len(list)):
            ans += abs(list[i] - list[i+1])
    print(ans)

a.insert(0, 0)
for j in range(n):
    tmp = a[j+1]
    a.pop(j+1)
    f(a)
    a.insert(j+1, tmp)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = sum([abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)])

    for i in range(N):
        spam = Ai[:]
        del spam[i]
        spam = [0] + spam + [0]

        if foo[i] < foo[i + 1] < foo[i + 2] or foo[i + 2] < foo[i + 1] < foo[i]:
            print(bar)
        else:
            ham = [abs(spam[i] - spam[i + 1]) for i in range(len(spam) - 1)]
            print(sum(ham))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [int(i) for i in inp]

for i in range(N):
    B = np.hstack(([0],np.delete(A, i),[0]))
    X = [np.abs(B[j] - B[j+1]) for j in range(N)]
    print(int(np.sum(X)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

#1. input
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

#2. calculate the answer
ans = [0]*N 
for i in range(N):
    #2.1 delete the i-th element
    Awithout_i = np.r_[A[:i], A[i+1:]]  
    #2.2 make the difference list
    subted = np.r_[Awithout_i, 0]
    subting = np.r_[0, Awithout_i]
    difference = np.abs(subted - subting)

    #2.3 sum the difference and output
    ans[i] = np.sum(difference)
    print(ans[i])

Submission status: Time Limit Exceeded

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

for x, y in enumerate(a):
  sum = 0
  present = 0
  for s, t in enumerate(a):
    if s != x:
      cost = abs(t-present)
      sum += cost
      present = t
  sum += abs(present-0)
  answer.append(sum)
  print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = []
for j in range(1,N):
	B.append(abs(A[j]-A[j-1]))
if N >= 3:
	C = [0]
	for k in range(0,N-2):
		C.append(abs(A[k+2]-A[k]))
	C.append(0)
	print(abs(A[1])+sum(B[1:N-1])+abs(A[N-1]))
	for i in range(1,N-1):
		print(abs(A[0])+sum(B[0:i-1])+C[i]+sum(B[i+1:N-1])+abs(A[N-1]))
	print(abs(A[0])+sum(B[0:N-2])+abs(A[N-2]))
else:
	print(2*abs(A[1]))
	print(2*abs(A[0]))

Submission status: Time Limit Exceeded

Solution code:
line = int(input())
spot = list(map(int, input().split()))

spot.append(0)

for i in range(line):
    if i == 0:
        money = abs(0 - spot[1])
    else:
        money = abs(0 - spot[0])
        
    for n in range(line):
        if n == i:
            continue
            
        if n+1 == i:
            money += abs(spot[n]-spot[n+2])
        else:
            money += abs(spot[n]-spot[n+1])
            
    print(money)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = [int(i) for i in input().split()]
B = []
for j in range(1,N):
	B.append(abs(A[j]-A[j-1]))
if N >= 3:
	C = [0]
	for k in range(0,N-2):
		C.append(abs(A[k+2]-A[k]))
	C.append(0)
	print(abs(A[1])+sum(B[1:N-1])+abs(A[N-1]))
	for i in range(1,N-1):
		print(abs(A[0])+sum(B[0:i-1])+C[i]+sum(B[i+1:N-1])+abs(A[N-1]))
	print(abs(A[0])+sum(B[0:N-2])+abs(A[N-2]))
else:
	print(2*abs(A[1]))
	print(2*abs(A[0]))

Submission status: Time Limit Exceeded

Solution code:
try:
    n = int(input().strip())
    spot = [int(i) for i in input().strip().split(" ")]
    for i in range(n):
        max = 0
        point = 0
        for m in range(n):
            if i == m:
                continue
            max+=abs(point - spot[m])
            point=spot[m]
        max+=abs(point - 0)
        print(max)    
except EOFError:
    pass

Submission status: Time Limit Exceeded

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

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

a = 0
I = []
for b in A + [0]:
    I.append(b - a)
    a = b
S = sum(map(abs, I))

for i in range(N):
    j = i + 1
    A_ = [0] + A + [0]
    if A_[j - 1] <= A_[j] <= A_[j + 1]:
        print(S)
    else:
        I_ = I[:]
        I_[i] = I_[i] + I_[i + 1]
        del I_[i + 1]
        n = sum(map(abs, I_))
        print(n)

Submission status: Time Limit Exceeded

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

money = []
for i in range(n):
    x = 0
    money.append(0)
    for j in range(n):
        if i != j:
            money[i] += abs(x-a[j])
            x = a[j]
    money[i] += abs(x-0)


for i in range(n):
    print(money[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()] 
for i in range(n):
  o=0
  p=0
  for j in range(n):
    if j==i:
      continue
    o+=abs(p-a[j])
    p=a[j]
  o+=abs(p)
  print(str(o))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
points = list(map(int, input().split(' ')))
points.insert(0, 0)
points.insert(len(points), 0)

results = []
for i in range(1, len(points) - 1):
    sum, prev = 0, 0
    for point in range(1, len(points)):
        if point == i:
            continue
        sum += abs(prev - points[point])
        prev = points[point]

    print(sum)

Submission status: Time Limit Exceeded

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

tmp_res = 0
tmp_ici = 0
tmp_array = []
for i in array:
    tmp_array.append(abs(tmp_ici-i))
    tmp_ici = i
tmp_array.append(abs(tmp_ici-0))

array = [0] + array + [0]
for i in range(n):
    c = array[i]
    cc = array[i+2]
    a = tmp_array[:i]
    b = tmp_array[i+2:]
    print(sum(a)+abs(c-cc)+sum(b))

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C


if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]
    mod_spots = spots

    for i in range(spot_count):
        tmp = mod_spots[i + 1]
        if mod_spots[i] <= mod_spots[i + 2]:
            mod_spots[i + 1] = mod_spots[i]
        elif (mod_spots[i] > 0) and mod_spots[i + 2] > 0:
            mod_spots[i + 1] = 0
        else:
            mod_spots[i + 1] = mod_spots[i]

        cost = sum([abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)])
        mod_spots[i + 1] = tmp
        print(cost)

Submission status: Time Limit Exceeded

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

for i in range(1,N+1):
  B=A[0:N+2]
  B.pop(i)
  S=0
  for j in range(1,N+1):
    S+=abs(B[j]-B[j-1])
  print(S)

Submission status: Time Limit Exceeded

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

for y in range(N):
    price = 0
    a.pop(y)
    a.insert(0,0)
    hold_max = a[0]
    hold_min = a[0]
    for x in range(len(a)):
        if a[x] > 0 and a[x] > hold_max:
            price += a[x] - hold_max
            hold_min = 0
            hold_max = a[x]
        elif a[x] < 0 and a[x] < hold_min:
            price += abs(a[x]) - abs(hold_min)
            hold_max = 0
            hold_min = a[x]
        else:
            continue
    print(price*2)
    a = list(A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
#print(A)
costs = [0]*N
for i in range(N):
    tmp = A
    A = np.delete(A,i)
    A = np.insert(A,0,0)
    A = np.append(A,0)
    #print(A)
    costs[i] = sum(np.abs(np.diff(A)))
    A = tmp
for i in range(len(costs)):
    print(costs[i])

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
list = input().split(" ")

for k in range(N):
    change = 0
    now = 0
    for i in range(N):
        if k != i:
            if now < int(list[i]):
                change += int(list[i])-now
                now = int(list[i])
            else:
                change += now-int(list[i])
                now = int(list[i])



    change += math.fabs(now)
    change = int(change)
    print(change)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()] 
for i in range(N) :
  RES = 0
  before = 0
  for j in range(N) :
    if i == j :
      continue
    RES += abs(A[j] - before)
    before = A[j]
  RES += abs(before)
  print(RES)

Submission status: Time Limit Exceeded

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

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

    m = 0
    for i in range(n):
        dis = 0
        bef = 0
        if i != 0:
            if abs(a[i-1]) <= b and b <= abs(a[i+1]):
                print(m)
                continue;
        for idx, b in enumerate(a):
            if idx == i:
                continue
            dis += abs(bef - b)
            bef = b
        dis += abs(bef)
        if dis > m:
            m = dis
        print(dis)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

import numpy as np

def main():
    SpotNum = int(input())
    SpotCoodinate = [int(i) for i in input().split()]
    
    SpotCoodinate.insert(0, 0)
    SpotCoodinate.append(0)
    
    for i in range(SpotNum):
        RmSpotCoodinate = SpotCoodinate[:i+1] + SpotCoodinate[i+2:]
#        print(RmSpotCoodinate)
        print(sum(abs(np.diff(RmSpotCoodinate))))
#        print(result)
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
l = []
for a in A:
    start = 0
    ans = 0
    l = A[:] #A全てと同じ
    l.remove(a)
    for i in l:
        ans += abs(i-start)
        start = i
    ans += abs(start-0)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)
a = read_line(*([int] * n))

def price(aa, skip):
    sum = 0

    prev = 0
    for i in range(len(aa)):
        if i == skip:
            continue
        sum += abs(prev - aa[i])
        prev = aa[i]

    sum += abs(prev)
    return sum

for i in range(len(a)):
    print(price(a, i))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [int(i) for i in inp]

X = [np.hstack(([0],np.delete(A, i))) for i in range(N)]
Y = [np.hstack((np.delete(A, i),[0])) for i in range(N)]

Ans = [sum(np.abs(X[i]-Y[i])) for i in range(N)]

for i in range(N):
    print(int(Ans[i]))

Submission status: Time Limit Exceeded

Solution code:
try:
    n = int(input().strip())
    spot = list(input().strip().split(" "))
    for i in range(n):
        max = 0
        point = 0
        for m in range(n):
            if i == m:
                continue
            max+=abs(point - int(spot[m]))
            point=int(spot[m])
        max+=abs(point - 0)
        print(max)    
except EOFError:
    pass

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]
    for i in range(N):
        spam = Ai[:]
        del spam[i]
        spam = [0] + spam + [0]
        ham = [abs(spam[i] - spam[i + 1]) for i in range(len(spam) - 1)]
        print(sum(ham))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

spot = input().split()

for i in range(n):
    total = 0

    pos = 0
    
    for l in range(n):
        if i == l:
            pass
        
        else:
            money = pos - int(spot[l])
            pos = int(spot[l])
            
            if money < 0:
                money *= -1
            total += money

    if pos < 0:
        pos *= -1
    total += pos
    
    print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
costs = [0]*N
for i in range(N):
    tmp = A[:]
    A.pop(i)
    A.insert(0,0)
    A.append(0)
    #print(A)
    for j in range(len(A)-1):
        #print(A[j+1]-A[j])
        costs[i] += abs(A[j+1]-A[j])
    A = tmp
for i in range(len(costs)):
    print(costs[i])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


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


# solve
for i in range(N):
    t = 0
    B = list(A)
    B.pop(i)
    j = 0
    while (True):
        # 最初
        if (j == 0):
            t += abs(B[j])
            j += 1
        # 最後
        elif (j == len(B)):
            t += abs(B[j-1])
            break
        else:
            t += abs(B[j] - B[j-1])
            j += 1
    print(t)

Submission status: Time Limit Exceeded

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

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

a = 0
I = 0
for b in A + [0]:
    I += abs(a - b)
    a = b

for i in range(1, N + 1):
    A_ = [0] + A + [0]
    if A_[i - 1] <= A_[i] <= A_[i + 1]:
        print(I)
    else:
        del A_[i]
        a = 0
        n = 0
        for b in A_:
            n += abs(a - b)
            a = b
        print(n)

Submission status: Time Limit Exceeded

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

from copy import deepcopy

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)
a = read_line(*([int] * n))

def price(aa, skip):
    sum = 0

    prev = 0
    for i in range(len(aa)):
        if i == skip:
            continue
        sum += abs(prev - aa[i])
        prev = aa[i]

    sum += abs(prev)
    return sum

for i in range(len(a)):
    print(price(a, i))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def ab(a):
  if a<0:
    return -1*a
  else:
    return a
n=int(input())
a=input()
a=a.split()
for i in range(n):
  o=0
  p=0
  for j in range(n):
    if j==i:
      continue
    o+=ab(p-int(a[j]))
    p=int(a[j])
  o+=ab(p)
  print(str(o))

Submission status: Time Limit Exceeded

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

A.append(0)
for i in range(N):
    b, s = 0, 0
    for j, a in enumerate(A):
        if i != j:
            s += abs(b - a)
            b = a
    print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=input()
a=a.split()
for i in range(n):
  o=0
  p=0
  for j in range(n):
    if j==i:
      continue
    o+=abs(p-int(a[j]))
    p=int(a[j])
  o+=abs(p)
  print(str(o))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
for j in range(n):
    s = 0
    x = 0
    for i in range(n):
        if i == j:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

Submission status: Time Limit Exceeded

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

fee = []
fee2 = []
for i in range(n + 1):
    fee.append(abs(a_list[i] - a_list[i + 1]))
    if i < n:
        fee2.append(abs(a_list[i] - a_list[i + 2]))
    
for i in range(n):
    print(sum(fee[0:i] + [fee2[i]] + fee[i + 2 : n + 1]))

Submission status: Time Limit Exceeded

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

from copy import deepcopy

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)
a = read_line(*([int] * n))

def price(aa):
    sum = 0
    for j in range(len(aa) - 1):
        sum += abs(aa[j] - aa[j + 1])

    return sum

for i in range(len(a)):
    aa = deepcopy(a)

    del aa[i]

    aa = [0] + aa + [0]

    print(price(aa))

Submission status: Time Limit Exceeded

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



for y in range(N):
    a.pop(y)
    a.insert(0, 0)
    price = 0
    for x in range(len(a)-1):
        price += abs(a[x+1] - a[x])
    price += abs(a[-1])
    print(price)
    a = list(A)

Submission status: Time Limit Exceeded

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

for i in range(1, n + 1):
    sum_kingaku = 0
    now_point = 0
    for j, a in enumerate(array):
        if i == j + 1:
            continue
        k = abs(now_point - a)
        sum_kingaku += k
        now_point = a
    sum_kingaku += abs(now_point - 0)
    print(sum_kingaku)

Submission status: Time Limit Exceeded

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

fee = []
for i in range(n + 1):
    fee.append(abs(a_list[i] - a_list[i + 1]))

fee2 = []
for i in range(n):
    fee2.append(abs(a_list[i] - a_list[i + 2]))
    
    
for i in range(n):
    print(sum(fee[0:i] + [fee2[i]] + fee[i + 2 : n + 1]))

Submission status: Time Limit Exceeded

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

for i in range(n):
    ans = 0
    tmp = 0
    for j in range(n):
        if j != i:
            ans += abs(tmp - a[j])
            tmp = a[j]

    ans += abs(tmp - 0)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
N = int(input())
point = list(map(int,input().split()))

for i in range(N):
	prev = 0
	ans = 0
	for j in range(N):
		if j == i:
			continue
		ans += abs(point[j] - prev)
		prev = point[j]
	ans += abs(prev)
	print(ans)

Submission status: Time Limit Exceeded

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

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

for A_i in A:
    A_ = A[:]
    A_.remove(A_i)
    A_.append(0)
    a = 0
    i = 0
    for b in A_:
        i += abs(a - b)
        a = b
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [int(i) for i in inp]

for i in range(N):
    B = A.copy()
    B = np.delete(B, i)
    X = np.hstack(([0],B))
    Y = np.hstack((B,[0]))
    res = np.abs(X-Y)
    print(int(np.sum(res)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
for j in range(n):
    s = 0
    x = 0
    for i in range(len(a)):
        if i == j:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

Submission status: Time Limit Exceeded

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

for i in range(N):
    s = 0
    a = 0
    for j, b in enumerate(A):
        if i == j:
            continue
        s += abs(a - b)
        a = b
    s += abs(a)
    print(s)

Submission status: Time Limit Exceeded

Solution code:
# coding : utf-8

import numpy as np

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

for i in range(N):
    suml = 0
    start = 0
    for j in range(N):
        if i == j:
            continue
        suml += abs(start - D[j])
        start = D[j]
    print(suml+abs(start))

Submission status: Time Limit Exceeded

Solution code:
import difflib
n = int(input())
l = list(map(int, input().split()))
total = 0
last = 0
for i in range(n):
  total = 0
  last = 0
  for j in range(n):
    if j == i:
      pass
    else:
      total += abs(l[j] - last)
      last = l[j]
  total += abs(last)
  print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
result = ""
for n in range(N):
    result += str(sum(cost[:n]) + abs(A[n] - A[n + 2]) + sum(cost[n + 2:]))
    if n != N - 1:
        result += '\n'
print(result)

Submission status: Time Limit Exceeded

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

def calc(a, k):
    s = 0
    x = 0
    for i in range(len(a)):
        if i == k:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    for i in range(n):
        dis = 0
        bef = 0
        for idx, b in enumerate(a):
            if idx == i:
                continue
            dis += abs(bef - b)
            bef = b
        dis += abs(0 - bef)
        print(dis)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
for i in range(len(a)):
    a1=a.copy()
    a1.pop(i)
    c=[0]+a1+[0]
    b=[]
    for i in range(len(c)-1):
        b.append(abs(c[i]-c[i+1]))
    print(sum(b))

Submission status: Time Limit Exceeded

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


for i in range(N):
    ans = 0
    pos = 0
    for j in range(len(A)):
        if j == i:
            continue
        ans += abs(A[j]-pos)
        #print('ans', ans)#debug
        pos = A[j]
        #print('pos:', pos)#debug
    ans += abs(pos)
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    l = list(A)
    l.pop(i)
    answer = 0
    for j in range(len(l)-1):
        answer += abs(l[j]-l[j+1])
    else:
        answer += abs(l[0])+abs(l[-1])
    print(answer)

Submission status: Time Limit Exceeded

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

for i in range(1,N+1):	# i番目を訪れない
	now = 0
	ans = 0
	for k in range(1,N+2):
		if k != i:
			ans += abs(A[now] - A[k])
			now = k
	print(ans)

Submission status: Time Limit Exceeded

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


def money(arr):
    now_x = 0
    total_score = 0

    for i in arr:
        total_score += abs(i-now_x)
        now_x = i

    total_score += abs(now_x)
    return total_score


for i in range(n):
    tmp = [i for i in a]

    tmp.pop(i)
    tmp.append(0)

    print(money(tmp))