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:
n = int(input())
x = map(int, input().split())
x = list(x)
for c in x:
    x_remove = x.copy()
    x_remove.remove(c)
    x_remove.insert(0,0)
    x_remove.append(0)
    i = 0
    ans = 0
    for i, b in enumerate(x_remove[1:]):
        ans += abs(x_remove[i] - b)        
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = map(int, input().split())
x = list(x)
for c in x:
    x_remove = x.copy()
    x_remove.remove(c)
    x_remove.insert(0,0)
    x_remove.append(0)
    i = 0
    ans = 0
    for i, b in enumerate(x_remove[1:]):
        ans += abs(x_remove[i] - b)        
        i += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = map(int, input().split())
x = list(x)
for c in x:
    x_remove = x.copy()
    x_remove.remove(c)
    x_remove.insert(0,0)
    x_remove.append(0)
    i = 0
    ans = 0
    while i < len(x_remove)-1:
        ans += abs(x_remove[i+1] - x_remove[i])        
        i += 1
    print(ans)

Submission status: Time Limit Exceeded

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

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

for i in range(len(spot_list)):
    deleted_list = spot_list[:i]+spot_list[i+1:]
    cost = cost_culc(deleted_list)
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [0]
A_list.extend(list(map(int, input().split())))
A_list.append(0)
previous_val = 0
dif = []
for i in A_list[1:]:
    dif.append(previous_val - i)
    previous_val = i

for idx, val in enumerate(dif):
    if idx < len(dif)-1:
        tmp1 = dif[idx]
        tmp2 = dif[idx + 1]
        dif[idx] = 0
        dif[idx + 1] = 0
        print(sum(map(abs, dif)) + abs(tmp1 + tmp2))
        dif[idx] = tmp1
        dif[idx + 1] = tmp2

Submission status: Time Limit Exceeded

Solution code:
import copy


def sumPrice(N, B):
    sum = 0
    for i in range(1, N):
        sum += abs(B[i] - B[i - 1])
    sum += abs(B[N-1] - B[0])
    return sum


N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
for i in range(1, N + 1):
    B = copy.deepcopy(A)
    del B[i]
    print(sumPrice(N, B))

Submission status: Time Limit Exceeded

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

pay = [0] * N
flag = True

for i in range(N):
    for j in range(N + 1):
        if(i == j):
            flag = False
            continue
        if(flag):
            pay[i] += abs(a[j + 1] - a[j])
        else:
            pay[i] += abs(a[j + 1] - a[j - 1])
            flag = True
for i in range(N):
    print("{0}".format(pay[i]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.append(0)
pay = [0] * N
flag = True

for i in range(N):
    if(flag == False):
           flag = True
    for j in range(N + 1):
        if(flag == False):
           flag = True
           continue

        if(i == N - j - 1):
            if(N - j - 2 >= 0):
                pay[i] += abs(a[N - j] - a[N - j - 2])
                flag = False
            else:
                pay[i] += abs(a[N - j])
                flag = False
        else:
            if(N - j - 1 >= 0):
                pay[i] += abs(a[N - j] - a[N - j - 1])
            else:
                pay[i] += abs(a[N - j])
    
for i in range(N):
    print("{0}".format(pay[i]))

Submission status: Time Limit Exceeded

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

a.append(0)

pay = [0] * N
# print(a)
flag = True

for i in range(N):
    if(flag == False):
           flag = True
    for j in range(N + 1):
        if(flag == False):
           flag = True
           continue

        # print("j={0}".format(j))
        if(i == N - j - 1):
            # print("check")
            if(N - j - 2 >= 0):
                pay[i] += abs(a[N - j] - a[N - j - 2])
                # print(abs(a[N - j] - a[N - j - 2]))
                flag = False
            else:
                pay[i] += abs(a[N - j])
                # print(abs(a[N - j]))
                flag = False
        else:
            if(N - j - 1 >= 0):
                # print("if")
                pay[i] += abs(a[N - j] - a[N - j - 1])
                # print(abs(a[N - j] - a[N - j - 1]))
            else:
                # print("else")
                pay[i] += abs(a[N - j])
                # print(abs(a[N - j]))
        # print("  {0}:{1}".format(j, pay[i]))
    


# 結果
for i in range(N):
# for i in range(N - 1, -1, -1):
    # print("{0}:{1}".format(i,pay[i]))
    print("{0}".format(pay[i]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

def funcabs(a,b):
    if a>=b: ret = a-b
    else: ret = b-a
    return ret

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

for i in range(1,N+1):
    ans = 0
    B = copy.deepcopy(A)
    del B[i]
    for j in range(1,N+1):
        ans += funcabs(B[j],B[j-1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)
kaisa = deque()
ans = list()

for i in range(len(a)):
    if i == 0:
        continue
    diff = a[i] - a[i - 1]
    kaisa.append(diff)

for i in range(n):
    ans = list(kaisa).copy()
    new_num = kaisa[i] + kaisa[i + 1]
    ans.remove(kaisa[i])
    ans.remove(kaisa[i + 1])
    ans.insert(i, new_num)
    print(sum([abs(n) for n in ans]))

Submission status: Time Limit Exceeded

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

for i in a:
    diff = 0
    ls = a.copy()
    ls.remove(i)
    ls.append(0)
    for index, x in enumerate(ls):
        diff += abs(x - old_x)
        old_x = x
    diff_ls.append(diff)

print(*diff_ls, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    #1. make master list
    N = int(input())
    A = list(map(int, input().split()))

    A.append(0)
    A.insert(0,0)
    
    #2. remove i-th componet
    for i in range(1,N+1):
        A_copy = np.array(A)
        A_copy = np.delete(A_copy,i)
        
        dist_abs = sum(abs(A_copy[1:] - A_copy[:-1]))
        
        #3. output
        print(dist_abs)
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
A = list(int(i) for i in input().split())
A.insert(0, 0)
A.append(0)
B = copy.deepcopy(A)
Q = 0

for i in range(N):
    A.pop(i+1)
    for j in range(N):            
        Q += abs(A[j] - A[j+1])
    print("%d" % (Q))
    Q = 0
    A = copy.deepcopy(B)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
A.insert(0, 0)
A.append(0)
Q = 0
j=0

for i in range(N):
    while j < N + 1:
        if j == i:
            Q += abs(A[j] - A[j+2])
            j += 1
        else:
            Q += abs(A[j] - A[j+1])
        j += 1
    print("%d" % (Q))
    Q = 0
    j = 0

Submission status: Time Limit Exceeded

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

for i in a:
    c = 0
    for j in a:
        if i == j:
            continue

        c += abs(j-x)
        x = j

    c += abs(x-0)
    c_lst.append(c)
    x = 0

for i in c_lst:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

	for i in range(1, n+1):
		ans = 0
		tmp = copy.deepcopy(a)
		del tmp[i]

		for j in range(len(tmp)-1):
			ans += abs(tmp[j+1] - tmp[j])
		ans += abs(tmp[-1])
		print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

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

for i in range(1, n + 1):
    total = 0
    b = deepcopy(a)
    b.pop(i)
    for j in range(n):
        total += abs(b[j + 1] - b[j])
    print(total)

Submission status: Time Limit Exceeded

Solution code:
import math

place_count = int(input())
position_list = input().split()

now_position = 0
cost = 0
cost_dict = {}

for skip_position in position_list:
	if skip_position in cost_dict:
		print(cost_dict[skip_position])
	skip_position = int(skip_position)
	for next_position in position_list:
		next_position = int(next_position)
		if skip_position == next_position:
			continue
		cost += abs(next_position - now_position)
		now_position = next_position
	cost += abs(now_position)
	print(cost)
	cost_dict[skip_position] = cost
	now_position = 0
	cost = 0

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

place_count = int(input())
position_list = input().split()

now_position = 0
cost = 0

for skip_position in position_list:
	skip_position = int(skip_position)
	for next_position in position_list:
		next_position = int(next_position)
		if skip_position == next_position:
			continue
		cost += abs(next_position - now_position)
		now_position = next_position
	cost += abs(now_position)
	print(cost)
	now_position = 0
	cost = 0

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.append(0)
for i in range(1,N+1):
  money=0
  list_B=list_A.copy()
  del list_B[i]
  for k in range(1,N+1):
    money+=abs(list_B[k]-list_B[k-1])
  print(money)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
for i in range(1,N+1):
  money=0
  list_B=list_A.copy()
  del list_B[i]
  for k in range(1,N+1):
    money+=abs(list_B[k]-list_B[k-1])
  print(money)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()#List of Str
A.append("0")

def goWithoutNum( num):
    pos = 0
    result = 0
    for i in range(N + 1):
        if i != num:
            result += abs( int( A[i]) - pos)
            pos = int(A[i])
    print( result)

for i in range(N):
    goWithoutNum(i)

Submission status: Time Limit Exceeded

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

ans = []

for i in range(N):
    temp=0
    if i == 0:
        for j in range(N):
            if j == 0:
                temp += abs(a[1])
            elif j != N-1:
                temp += abs(a[j+1] - a[j])
            else:
                temp += abs(a[j])
    elif i != N-1:
        for j in range(N):
            if j == 0:
                temp += abs(a[0])
            elif j < i:
                temp += abs(a[j]-a[j-1])
            elif j == i:
                temp += abs(a[j+1]-a[j-1])
            elif (j > i) and (j < N-1):
                temp += abs(a[j+1]-a[j])
            else:
                temp += abs(a[j])
    else:
        for j in range(N):
            if j == 0:
                temp += abs(a[0])
            elif j != N-1:
                temp += abs(a[j]-a[j-1])
            else:
                temp += abs(a[j-1])
    ans.append(temp)
      
for x in range(N):
    print(ans[x])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
_itvs = input().split(' ')
itvs = []
for itv in _itvs:
    itvs.append(int(itv))

for j in range(n):
    _itvs = itvs.copy()
    _itvs.pop(j)
    tot = [abs(_itvs[0])]
    for i in range(n - 2):
        tot.append(abs(_itvs[i + 1] - _itvs[i]))
    tot.append(abs(_itvs[-1]))
    print(sum(tot))

Submission status: Time Limit Exceeded

Solution code:
import sys
for line in sys.stdin:
    if line == None or line == '\n':
        break
    line = line.rstrip()
    line = line.split(" ")
    if len(line) == 1:
        N = int(line[0])
        continue
    else:
        coordinates = line


        for i in range(N):
            cost = 0
            prev_coord = 0
            for index in range(N):
                if index == i:
                    continue
                cost += abs(prev_coord - int(coordinates[index]))
                prev_coord = int(coordinates[index])
            cost += abs( 0 - prev_coord)
            print(cost)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
arr = input().split(' ')
arr = [int(a) for a in arr]

for i in range(len(arr)):
	cp = [a for a in arr]
	del cp[i]
	cost = math.fabs(cp[0])
	for j in range(1, len(cp)):
		cost += math.fabs(cp[j] - cp[j - 1])
	cost += math.fabs(cp[-1])
	print(int(cost))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=list(map(int,input().split()))
for i in range(N):
    t,ans=[],0
    t+=s
    t.pop(i)
    t.insert(0,0)
    t.append(0)
    for k in range(N):
        ans+=abs(t[k]-t[k+1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    A = B[:i]+B[i+1:]
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    for j in range(N):
        if i != j:
            A.append(B[j])
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
 
spot = list(map(int, input().split()))
 
for i in range(n):
    total = 0
 
    pos = 0
    
    for l in range(n):
        if i != l:
            money = pos - spot[l]
            pos = 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()))

for n in range(N):
    ans = 0
    B = A[:n] + A[n+1:]
    current = 0
    for b in B:
        ans += abs(b - current)
        current = b
    ans += abs(current)
    print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())

a = [i for i in map(int, input().split())]

total = []
x = 0
skip_total = []
for i in range(N-1):
    total.append(abs(a[i] - x))
    skip_total.append(abs(a[i+1] - x))
    x = a[i]
skip_total.append(abs(x - 0))
total.append(abs(a[N-1] - x))
x = a[N-1]
total.append(abs(x - 0))

print(skip_total[0] + sum(total[2:]))
for i in range(1, N-1):
    print(sum(total[0:i]) + skip_total[i] + sum(total[i+2:]))
print(sum(total[0:N-1]) + skip_total[N-1])

Submission status: Time Limit Exceeded

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

N = int(input())

a = [i for i in map(int, input().split())]

total = []
x = 0
for i in range(N):
    total.append(abs(a[i] - x))
    x = a[i]
total.append(abs(x - 0))


skip_total = []
x = 0
for i in range(N-1):
    skip_total.append(abs(a[i+1] - x))
    x = a[i]
skip_total.append(abs(x - 0))

for i in range(N):
    if i == 0:
        print(skip_total[0] + sum(total[2:]))
    elif i == N-1:
        print(sum(total[0:N-1]) + skip_total[N-1])
    else:
        print(sum(total[0:i]) + skip_total[i] + sum(total[i+2:]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0]
B = input().split()
for i in range(len(B)):
    A.append(int(B[i]))
A.append(0)
for i in range(1, N+1):
    a = A[i]
    dis = 0
    del A[i]
    for j in range(N):
        dis += abs(A[j+1]-A[j])
    A.insert(i, a)
    print(dis)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())#3
list = [int(i) for i in input().split()]
list.insert(0,0)
list.append(0)
#[0,3,5,-1,0]


def func(a,b):
    return abs(list[a]-list[b])

def sigma(i, frm, to):
	result = 0; #答えの受け皿
	for n in range(frm, to+1):#0~3
		result += func(n,n+1) 
        #ここで関数を呼び出す。
	result = result+abs(list[i-1]-list[i+1])-(abs(list[i-1]-list[i])+abs(list[i]-list[i+1]))
	print(result)

for i in range(1,N+1):#1~3
	sigma(i,0,N)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    ans = 0
    p = 0
    end = 0
    for j in range(n):
        if j != i :
            ans = ans + abs(spot[j] - p)
            p = spot[j]
    ans = ans + abs(p - end)
    print ans

Submission status: Time Limit Exceeded

Solution code:
def dx(a,b):
    return abs(a-b)

def abs(x):
    if x>=0:
        return x
    else:
        return -x

if __name__ == '__main__':
    n = int(input())
    a = list(False for _ in range(n+2))
    a[0] = 0
    buf = list(map(int, input().split()))
    for i in range(n):
        a[i+1] = buf[i]
    a[n+1] = 0

    for i in range(1,n+1): ##訪れるのを取りやめる座標1->n
        pos = 0
        val = 0
        for j in range(n+2): ##訪れる座標0->(n+1)
            if i != j: ##訪れる座標なら
                val += dx(a[j], a[pos])
                pos = j
        print(val)

Submission status: Time Limit Exceeded

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

for l in range(n):
    cost = 0
    tmp = pos.copy()
    tmp.pop(l+1)
    for i in range(n):
        cost += abs(tmp[i+1] - tmp[i])
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=input().split()
for i in range(n):
    c=[]
    for j in range(n):
        if i!=j:
            c.append(a[j])
    sum=0
    for k in range(n):
        if k==0:
            sum+=abs(int(c[k]))
        elif k==n-1:
            sum+=abs(int(c[k-1]))
        else:
            sum+=abs(int(c[k-1])-int(c[k]))
    print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = [np.sum(np.abs(np.concatenate([A[:i], A[i+1:], np.array([0])], axis=0) \
                                    - np.concatenate([np.array([0]), A[:i], A[i+1:]], axis=0))) for i in range(N)]

[print(ans[i]) for i in range(N)]

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)

ans = []
ans = [np.sum(np.abs(np.r_[A[:i], A[i+1:], 0] \
                                    - np.r_[0, A[:i], A[i+1:]])) for i in range(N)]
[print(ans[i]) for i in range(N)]

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]

    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 = {j: abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)}
        mod_spots[i + 1] = tmp
        print(sum(cost.values()))

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 j in range(N):
    B = np.hstack(([0],np.delete(A, j),[0]))
    print(int(np.sum(np.abs(np.diff(B,n=1)))))

Submission status: Time Limit Exceeded

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

    for i in range(N):
        base = 0
        kyori = 0
        for j in range(N):
            if i != j:
                kyori = kyori + abs(A[j] - base)
                base = A[j]
        kyori = kyori + abs(base)
        print(kyori)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# --*-- encoding:utf-8 --*--
from copy import copy

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


for j in range(1, len(A)-1):
	res = 0
	tmp = copy(A)
	tmp.pop(j)
	for i in range(0, len(tmp)-1):
		res += abs(tmp[i+1] - tmp[i])
	print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.append(0)
A.insert(0,0)
memo = [abs(A[i - 1] - A[i]) for i in range(1, len(A))]
for i in range(1, N + 1):
    c = abs(A[i - 1] - A[i + 1])
    l = sum(memo[:i - 1])
    r = sum(memo[i + 1:])
    print(l + c + r)

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(N+2):
        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=[0]+list(map(int,input().split(" ")))+[0]

#N=3
#A=[0,3,5,-1,0]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

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

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

L = L + [L[-1] + abs(A[-2] - A[0])]

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

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)
    
    SumTable = [0 for i in range(100000)]
#    print(SumTable)
    
    Diff = abs(SpotCoordinate[0] - SpotCoordinate[2] )
    result = Diff + sum(DiffSpotCoordinate[2:])
    print(result)
    
    for i in range(1,SpotNum):
        if(SumTable == []):
            SumTable[i-1] = sum(DiffSpotCoordinate[:i])
#            print(SumTable[i-1])
        else:
            SumTable[i-1] = SumTable[i-2] + sum(DiffSpotCoordinate[i-1:i])
#            print(SumTable[i-1])
            
        Diff = abs(SpotCoordinate[i] - SpotCoordinate[i+2] )
#        print(Diff)
        
        result = Diff + SumTable[i-1] + 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:
n = int(input())
a = list(map(int,input().split()))

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

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):
    for j in range(1, N + 2, 1):
        ans += abs(A[j] - A[j - 1])
    if A[i+1]<A[i-1]:
        if A[i-1]<A[i]:
            ans-=2*abs(A[i-1]-A[i])
        if A[i]<A[i+1]:
            ans-=2*abs(A[i+1]-A[i])
    if A[i-1]<A[i+1]:
        if A[i+1]<A[i]:
            ans-=2*abs(A[i]-A[i+1])
        if A[i]<A[i-1]:
            ans-=2*abs(A[i-1]-A[i])
    print(ans)
    ans=0

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)

ans = [np.sum(np.abs(np.r_[A[:i], A[i+1:], 0] \
                                    - np.r_[0, A[:i], A[i+1:]])) for i in range(N)]
[print(ans[i]) for i in range(N)]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0,0)
start = 0
ans = 0
for i in A:
    ans += abs(i-start)
    start = i

for i in A[1:-1]:
    a = A.index(i)
    ans2 = ans
    if A[a-1] <= A[a] <= A[a+1] or A[a-1] >= A[a] >= A[a+1]:
        print(ans2)
    elif A[a+1] <= A[a-1] <= A[a] or A[a+1] >= A[a-1] >= A[a]:
        print(ans2 - 2 * abs(A[a]-A[a-1]))
    else:
        print(ans2 - 2 * abs(A[a]-A[a+1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.append(0)
A.insert(0,0)
memoL,memoR = list(A),list(A)
for i in range(1,len(A)):
    memoL[i] = abs(A[i] - A[i - 1])
    memoR[len(A) - i] = abs(A[i] - A[i - 1])

for i in range(1, N + 1):
    c = abs(A[i - 1] - A[i + 1])
    l = sum(memoL[:i])
    r = sum(memoR[:len(A) - i - 1])
    print(l + c + r)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))
    P.insert(0, 0)
    Dis = [[abs(P[i]-P[(i+j+1)%(N+1)]) for i in range(N+1)] for j in range(2)]
    
    for i in range(N): print(sum(Dis[0])-sum(Dis[0][i:i+2])+Dis[1][i])

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(N*2):
        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())
spotStrList = input().split()
result = 0
spotList = ['0']
for x in range(n):
    spotList.append(spotStrList[x])
spotList.append('0')

def travelfrom(spotNum, skipNum):
    if spotNum == skipNum:
        return 0
    elif spotNum == skipNum -1:
        return abs(int(spotList[spotNum+2])-int(spotList[spotNum]))
    else:
        return abs(int(spotList[spotNum+1])-int(spotList[spotNum]))
              
for i in range(n):
    for spot in range(n+1):
        result += travelfrom(spot,i+1)
    print(result)
    result=0

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
 
for y in range(1, N+1):
    hold = A[y]
    A.pop(y)
    price = 0
    
    for x in range(len(A)-1):
        price += abs(A[x+1] - A[x])
    price += abs(A[-1])
    print(price)
    A.insert(y, hold)

Submission status: Time Limit Exceeded

Solution code:
import copy
nu = int(input())
data = list(map(int,input().split()))
al = 0
for i in range(nu):
  ta = copy.deepcopy(data)
  da = ta.pop(i)
  for j in range(nu - 2):
    al += abs(ta[j + 1] - ta[j])
  if i == 0:
    al += abs(data[1]) + abs(data[nu - 1])
  elif i == nu - 1:
    al += abs(data[0]) + abs(data[nu - 2])
  else:
    al += abs(data[0]) + abs(data[nu - 1])
  print(al)
  al = 0

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)

ans = [np.sum(np.abs(np.r_[A[:i], A[i+1:], 0] \
                                    - np.r_[0, A[:i], A[i+1:]])) for i in range(N)]
for i in range(N):
    print(ans[i])

Submission status: Time Limit Exceeded

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

#N=5
#A=[0,1,1,1,2,0,0]

for i in range(1,N+1):
  S=0
  for j in range(1,N+2):
    S+=abs(A[j]-A[j-1])
  if A[i-1]<A[i+1]:
    if A[i]<A[i-1]:
      S-=2*abs(A[i]-A[i-1])
    elif A[i]>A[i+1]:
      S-=2*abs(A[i+1]-A[i])
  else:
    if A[i]>A[i-1]:
      S-=2*abs(A[i]-A[i-1])
    elif A[i]<A[i+1]:
      S-=2*abs(A[i+1]-A[i])
  print(S)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))
    P.insert(0, 0)
    Dis = [[abs(P[i]-P[(i+j)%(N+1)]) for i in range(N+1)] for j in range(1,N+1)]
    
    for i in range(N): print(sum(Dis[0])-sum(Dis[0][i:i+2])+Dis[1][i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    b = 0
    bud = 0
    for j, ai in enumerate(a):
        if i != j:
            bud += abs(ai - b)
            b = ai
    bud += abs(b)
    print(bud)