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 = np.array([int(i) for i in input().split()])
for i in range(n):
  ans = 0
  tmp = 0
  for j in range(n):  
    if i != j:
      ans += abs(tmp - a[j])
      tmp = a[j]
  print(ans+abs(tmp))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  ans = 0
  tmp = 0
  for j in range(n):  
    if i != j:
      ans += abs(tmp - a[j])
      tmp = a[j]
  print(ans+abs(tmp))

Submission status: Time Limit Exceeded

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

cost_list = []
for i in range(1, n+2):
    cost_list.append(abs(a[i] - a[i-1]))

for i in range(n):
    print(sum(cost_list[:i]) + sum(cost_list[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 i in range(n):
    p = 0
    cnt = 0
    for j in a[:i] + a[i+1:]:
        cnt += abs(j-p)
        p = j
    
    cnt += abs(j-0)
    
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=tuple(map(int,input().split()))
    a=(0,)+a+(0,)
    ans=[sum(abs((a[:i+1]+a[i+2:])[j] - (a[:i+1]+a[i+2:])[j+1]) for j in range(n))\
                for i in range(n)]
    print("\n".join(map(str,ans)))
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=tuple(map(int,input().split()))
    a=(0,)+a+(0,)
    ans=[0]*n
    for i in range(n):
        ans[i]=sum(abs((a[:i+1]+a[i+2:])[j] - (a[:i+1]+a[i+2:])[j+1]) for j in range(n))
    print("\n".join(map(str,ans)))
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):
    b = [0] + a[:i] + a[i+1:] + [0]
    ans = 0
    for j in range(len(b)-1):
        ans += abs(b[j] - b[j+1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
for i in range(1,N+1):
    B = np.concatenate([A[:i],A[i+1:]])
    print(abs(np.diff(B)).sum())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input().split()))
sum = 0
s.insert(0, 0)
s.insert(n+1, 0)
for i in range(1,n+1):
    st = s[i]
    s.pop(i)
    for j in range(n):
        sum += abs((s[j])-(s[j+1]))
    print(sum)
    s.insert(i, st)
    sum = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.deepcopy(a)
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
for i in range(len(b) - 1):
    ans = sum(b) - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from numpy import abs
from copy import deepcopy
import numpy as np
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
dist = []

for i in range(N):
  A_cancelled = deepcopy(A)
  A_cancelled.pop(i+1)
  
  from_arr = np.array(A_cancelled[:-1])
  to_arr = np.array(A_cancelled[1:])
  
  dist.append(sum(abs(from_arr - to_arr)))
  
for i in dist:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
from numpy import abs
from copy import deepcopy
import numpy as np
N = int(input())
A = list(map(int,input().split()))
dist = []

for i in range(N):
  A_cancelled = deepcopy(A)
  A_cancelled.pop(i)
  
  A_cancelled.append(0)
  A_cancelled.insert(0,0)
  
  from_arr = np.array(A_cancelled[:-1])
  to_arr = np.array(A_cancelled[1:])
  
  dist.append(sum(abs(from_arr - to_arr)))
  
for i in dist:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.deepcopy(a)
sum = 0
ans = []
for i in range(n):
    sum = 0
    a = copy.deepcopy(a_copy)
    a.pop(i)
    sum += abs(a[0]) + abs(a[-1])
    for j in range(len(a) - 1):
        sum += abs(a[j] - a[j + 1])

    ans.append(sum)
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [0] + list(map(int,input().split())) + [0]
B = [0]*n
C = [0]*(n+1)

for i in range(n):
    B[i]=abs(A[i]-A[i+2])
for i in range(n+1):
    C[i]=abs(A[i]-A[i+1])
for i in range(n):
    print(sum(C[0:i])+B[i]+sum(C[i+2:n+1]))

Submission status: Time Limit Exceeded

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

for i in range(n):
	cnt = 0
	c = []
	c = copy.copy(a)
	c.pop(i)
	iti = 0
	for j in range(len(c)):
		cnt += abs(c[j] - iti)
		iti = c[j]
	cnt += abs(c[-1])
	print (cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

for i in range(n):
    point = 0
    lin = li[:]
    lin.pop(i)
    lin = [0] + lin + [0]
    for j in range(1,len(lin)):
        point += abs(lin[j]-lin[j-1])
    print(point)

Submission status: Time Limit Exceeded

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

D = [abs(A[i+1]-A[i]) for i in range(len(A)-1)]

for i in range(n):
  print(sum(D)-D[i]-D[i+1]+abs(A[i+2]-A[i]))

Submission status: Time Limit Exceeded

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

A.append(0)

def calc_total_amount(a_list, k):
  
  pos = 0
  total_amount = 0
  
  for i in range(n+1):
    if i == k: continue
  
    total_amount += abs(a_list[i] - pos)
    pos = a_list[i]

  return(total_amount)

for i in range(n):
  print(calc_total_amount(A, i))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
a=a+[0]
for i in range(1,n+1):
    b=a[:i-1]+a[i:]
    print(sum(abs(x-y) for x,y in zip(b,b[1:]))+abs(b[0]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = [int(i) for i in input().split()]
lst.insert(0, 0)
res = [0]
for i in range(1, N+1):
    t = lst[:]
    del(t[i])
    res.append(sum([abs(t[i] - t[i-1]) for i in range(1, N)]) + abs(t[-1]))

for i in range(1, N+1):
    print(res[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = [int(i) for i in input().split()]
lst.insert(0, 0)
res = [0]
for i in range(1, N+1):
    t = lst[:]
    del(t[i])
    k = 0
    for i in range(1, len(t)):
        k += abs(t[i] - t[i-1])
    res.append(sum([abs(t[i] - t[i-1]) for i in range(1, N)]) + abs(t[-1]))

for i in range(1, N+1):
    print(res[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = [int(i) for i in input().split()]
lst.insert(0, 0)
res = [0]
for i in range(1, N+1):
    t = lst[:]
    del(t[i])
    # if max(t) < 0:
    #     res.append(2 * abs(min(t)))
    # elif min(t) > 0:
    #     res.append(2 * maxt)
    # else:
    #     res.append(2 * (max(t) - min(t)))
    k = 0
    for i in range(1, len(t)):
        k += abs(t[i] - t[i-1])
    res.append(k + abs(t[-1]))

for i in range(1, N+1):
    print(res[i])

Submission status: Time Limit Exceeded

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

for i in range(n):
  aa = a[:i]+a[i+1:]
  aa = [0]+aa+[0]
  print(sum([abs(aa[index+1]-aa[index]) for index in range(n)]))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
for i in range(1, n+1):
    if max(a[i-1:i+2]) == a[i] or min(a[i-1:i+2]) == a[i]:
        tmp = d[:i-1] + [abs(d[i-1]-d[i])] + d[i+1:]
        print(sum(tmp))
    else:
        print(sum(d))

Submission status: Time Limit Exceeded

Solution code:
def except_arr(arr, i):
    pre = arr[0:i]
    post = arr[i+1:]
    return pre+post

def cc092():
    n = int(input())
    an = list(map(int, input().split()))

    for i in range(0, n):
        bn = except_arr(an, i)
        bn.extend([0])
        pos = 0
        cost = 0
        for j in bn:
            cost += abs(pos-j)
            pos = j
        print(cost)

cc092()

Submission status: Time Limit Exceeded

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

for i in range(n):
    ans = 0
    cur = 0
    for j in range(n + 1):
        if i == j:
            continue
        if j == n:
            ans += abs(cur)
            break
        ans += abs(a[j] - cur)
        cur = a[j]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(num) for num in input().split()]

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

Submission status: Time Limit Exceeded

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

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

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):
    ans = 0
    b = a[:i]+a[i+1:]
    for j in range(len(b)-1):
        ans += abs(b[j]-b[j+1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.insert(0, 0)
A.append(0)

B = []
for i in range(len(A)-1):
  B.append(A[i+1] - A[i])
B_abs = [abs(b) for b in B]

for j in range(1, N+1):
  M1 = sum(B_abs[:j-1])
  M2 = abs(B[j-1] + B[j])
  M3 = sum(B_abs[j+1:])
  M = M1 + M2 + M3
  print(M)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = list(map(int,input().split()))
dp = [0] * (N+1)
dp[0] = abs(a[0])
for i in range(1, N):
    dp[i] = abs(a[i]-a[i-1])
dp[N] = abs(a[-1])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(N):
    A_new = A[:i] + A[i+1:]
    A_new_new = np.diff(A_new)
    A_new_new = list(map(lambda n:abs(n), A_new_new))
    ans = abs(A_new[0]) + sum(A_new_new) + abs(A_new[-1])
    print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    pass_sopt = A[:i] + A[i+1:]
    pass_sopt.append(0)
    pass_sopt.insert(0, 0)
    count = 0
    for j in range(len(pass_sopt)-1):
        count += abs(pass_sopt[j] - pass_sopt[j+1])
    print(count)

Submission status: Time Limit Exceeded

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

def get_key(l):
    return ','.join(map(str, l))

def calc(l):
    if len(l) <= 1:
        dp[get_key(l)] = 0
        return 0

    if get_key(l) in dp:
        return dp[get_key(l)]

    x = abs(l[0]-l[1]) + calc(l[1:])
    dp[get_key(l)] = x
    return x

# 0 3 5 -1 0 みたいに
L = [0] + A + [0]
dp = {}
for i in range(1, N+1):
    l = L[0:i] + L[i+1:]
    print(calc(l))

Submission status: Time Limit Exceeded

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

def get_key(l):
    return ','.join(map(str, l))

def calc(l):
    if len(l) <= 1:
        dp[get_key(l)] = 0
        return 0

#    print(l)
    x = abs(l[0]-l[1]) + calc(l[1:])
    dp[get_key(l)] = x
    return x

# 0 3 5 -1 0 みたいに
L = [0] + A + [0]
dp = {}
for i in range(1, N+1):
    l = L[0:i] + L[i+1:]
    print(calc(l))

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

def calc(l):
    count = 0
    for i in range(len(l)-1):
        count += abs(l[i]-l[i+1])

    return count

# 0 3 5 -1 0 みたいに
L = [0] + A + [0]
for i in range(1, N+1):
    l = L[0:i] + L[i+1:]
    print(calc(l))

Submission status: Time Limit Exceeded

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

money = []
for i in range(len(a)):
    arr = [0]+a[:i]+a[i+1:]+[0]
    tmp = []
    for j in range(len(arr)-1):
        tmp.append(abs(arr[j]-arr[j+1]))
    money.append(sum(tmp))


print(*money, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
cost=0
for i in range(n):
  cost=0
  A=a[:]
  if i==0:
    A[i]=0
  else:
    A[i]=A[i-1]
  cost+=abs(A[0]-0)
  for j in range(n-1):
    cost+=abs(A[j+1]-A[j])
  cost+=abs(0-A[-1])
  print(cost,end="\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.append(0)
b = [abs(a[0])]
c = [abs(a[1])]
for i in range(n):
    b.append(abs(a[i] - a[i+1]))
    if i < n-1:
        c.append(abs(a[i] - a[i+2]))

for i in range(n):
    ans = c[i]
    for j in range(0,i):
        ans += b[j]
    for k in range(i+2,n+1):
        ans += b[k]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Axis_str = input().split()
Axis = [int(s) for s in Axis_str]
#NとAxisでとれたのでこっから処理
#forで各都市スキップしながら出力？
Axis_i = len(Axis)
for i in range(Axis_i):
  pos = 0 #今いる座標
  next_pos_index = 0#次いく座標番号
  totalMoney = 0
  for j in range(Axis_i):#移動回数は座標の数
    if next_pos_index != i:
      totalMoney += abs(pos - Axis[next_pos_index])
      pos = Axis[next_pos_index]
    next_pos_index += 1
  totalMoney += abs(pos)

  print(totalMoney)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
box=list(map(int,input().split()))
for i in range(n):
    box_ano=copy.copy(box)
    del box_ano[i]
    count=abs(box_ano[0])+abs(box_ano[-1])
    for j in range(len(box_ano)):
        try:
            count +=abs(box_ano[j]-box_ano[j+1])
        except:continue
    print(count)

Submission status: Time Limit Exceeded

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

# iは除く番号
for i in range(1, N + 1):
  s = 0
  for j in range(N + 1):
    if j + 1 == i:
      s += abs(a[j] - a[j+2])
    elif j != i:
      s += abs(a[j] - a[j+1])      
  print(s)

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(1,n+1):
    ans=0
    tmp=a.copy()
    tmp.pop(i)
    for j in range(1,n+1):
        ans+=abs(tmp[j]-tmp[j-1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int, input().split(' ')))
ls.append(0)    # add gole point
prev_point = 0
for x in range(0, n):
    val = 0
    for p, y in enumerate(ls):
        if p == x:
            continue
        else:
            val += abs(prev_point - y)
            prev_point = y
    print(val)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
str = input().split()
A = []
A.append(0)
for i in range(N):
    A.append(int(str[i]))
A.append(0)
SUM = 0
distance = []

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

    
buf1 = 0
buf2 = 0
for i in range(1,N+1):
    buf1 = distance.pop(i-1)
    buf2 = distance.pop(i-1)
    #print(A)
    distance.insert(i-1,abs(A[i+1]-A[i-1]))
    print(sum(distance))
    distance.pop(i-1)
    distance.insert(i-1,buf2)
    distance.insert(i-1,buf1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
#print(cost)
for i in range(n):
    Cost=cost[:i]+cost[i+2:]+[abs(a[i+2]-a[i])]
    #print(Cost)
    print(sum(Cost))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
str = input().split()
A = []
A.append(0)
for i in range(N):
    A.append(int(str[i]))
A.append(0)
SUM = 0
cnt = 0
buf = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        if i == j:
            buf = A.pop(j)
            cnt = j
        SUM = SUM + abs(A[j] - A[j-1])
    A.insert(cnt,buf)
    print(SUM)
    SUM = 0

Submission status: Time Limit Exceeded

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

A.append(0)
A.insert(0,0)
for i in range(len(A)-1):
    ans.append(abs(A[i+1]-A[i]))

for j in range(1,len(A)-1):
    print(sum(ans)-ans[j]-ans[j-1]+abs(A[j+1]-A[j-1]))

Submission status: Time Limit Exceeded

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

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

for j in range(n):
  answer = sum([abs(i) for i in gap[0:j]]) + abs(gap[j] + gap[j + 1]) + sum([abs(i) for i in gap[j + 2:]])
  print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())
A = [0] + A + [0]
diff = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
diff_i = [abs(A[i + 2] - A[i]) for i in range(N)]
for i in range(N):
  print(sum(diff) + diff_i[i] -  (diff[i] + diff[i + 1]))

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())
A = [0] + A + [0]
diff = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
for i in range(N):
  print(sum(diff) + abs(A[i + 2] - A[i + 0]) -  (diff[i] + diff[i + 1]))

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
cost = list(map(int,input().split()))
for i in range(N):
    ans = 0
    temp_cost = cost.copy()
    temp_cost.pop(i)
    ans += abs(temp_cost[0]) + abs(temp_cost[-1])
    for i in range(0,N-2):
        ans += abs(temp_cost[i] - temp_cost[i+1])
        
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    cost = 0
    old = 0
    plan = a[:i] + a[i+1:n] + [0]

    for j in plan:
        dx = abs(old - j)
        old = j
        cost += dx
    print(cost)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
A.append(0)
D=[abs(A[0])]
for i in range(n-1):
  D+=[abs(A[i]-A[i+1])]
D.append(abs(A[n-1]))
for i in range(n):
  print(sum(D[:i])+abs(A[i-1]-A[i+1])+sum(D[i+2:]))

Submission status: Time Limit Exceeded

Solution code:
def dist(list):
  d=abs(list[0])+abs(list[-1])
  for i in range(len(list)-1):
    d+=abs(list[i+1]-list[i])
  return(d)
n=int(input())
A=[int(i) for i in input().split()]
for i in range(n):
  print(dist(A[:i]+A[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
dif = []
for i in range(N + 1):
	dif.append((abs(A[i+1] - A[i])))

for i in range(N):
	temp_dif = copy.copy(dif)
	del temp_dif[i + 1]
	del temp_dif[i]
	temp_dif.append(abs(A[i + 2] - A[i]))
	print(sum(temp_dif))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a = [0] + a + [0]
for i in range(n):
    b = a[:i+1] + a[i+2:]
    c = 0
    for j in range(n):
        c += abs(b[j+1] - b[j])
    print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

X=np.abs(np.diff(np.array([0] + A + [0]), n=1)).sum()

myfunc = lambda x:abs(x[0]-x[2]) - abs(x[0]-x[1]) - abs(x[1]-x[2])
B = np.array([myfunc(([0] + A + [0])[i:i+3]) for i in range(N)])

for x in list(X+B):
  print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

def calc_fee(l):
    s = 0
    l = [0] + l + [0]
    for i in range(len(l)-1):
        s += abs(l[i+1] - l[i])
    return s

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

for i in range(n):
    A_ = copy.copy(A)
    del A_[i]
    
    price = calc_fee(A_)
    print(price)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    l = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    print("\n".join(
        [str(sum(l) - l[i] - l[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()

Submission status: Time Limit Exceeded

Solution code:
input = open(0).read

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


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

    if N != 2:
        print("\n".join(
            [str(abs(A[0]) + sum(l) - l[i] - l[i + 1] + abs(A[i] - A[i + 2])
                 + abs(A[-1])) for i in range(N - 2)]))

    print(abs(A[0]) + sum(l) - l[-1] + abs(A[-2]))
    return


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.append(0)
for i in range(0, N):
    cost = 0
    pos = 0
    for p in range(0, N+1):
        if p != i:
            cost += abs(pos - A[p])
            pos = A[p]
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
for i in range(N):
    tmp = [0]
    tmp.extend(L[:i])
    tmp.extend(L[i+1:])
    tmp.append(0)
    ans = 0
    for j, n in enumerate(tmp):
        if j == 0:
            pre = n
            continue
        ans += abs(pre - n)
        pre = n
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("Heisei")
    else:print("TBD")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

def swap(s,pos):
    s[pos]-=1
    s[pos+1]+=1
    print(s)
    if pos == n-2: return s
    if s[pos+2] == 0: swap(s,pos+1)
    return s


n = ip()                              #入力整数1つ
#h,w= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意

for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    d = 0
    for k in range(1,len(b)):
        d+=abs(b[k-1]-b[k])
    print(d+abs(b[0])+abs(b[len(b)-1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(n) for n in input().split()]
A = [0] + A + [0]
L = []
LL = []

for i, a in enumerate(A):
    if i < len(A) - 1:
        L.append(abs(A[i] - A[i+1]))
    if i < len(A) - 2:
        LL.append(abs(A[i] - A[i+2]))

for i in range(N):
    ans = sum(L) - L[i] - L[i+1] + LL[i]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# C
import copy
import numpy as np
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    l = copy.copy(a)
    l.pop(i)
    print(sum(abs(np.array([0] + l) - np.array(l+[0]))))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split());c=[0]+a+[0]
for i in range(n):s,t,r=c[i:i+3];print(sum(abs(c[t]-c[t+1])for t in range(n+1))+abs(r-s)-abs(t-s)-abs(t-r))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
for i in range(n):
  s=[0]+a[:i]+a[i+1:]+[0]
  print(sum(abs(s[t]-s[t+1])for t in range(n)))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
for i in range(n):s=[0]+a[:i]+a[i+1:]+[0];print(sum(abs(s[t]-s[t+1])for t 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]+A[:i]+A[i+1:]+[0]
    cnt=0
    for j in range(n):
        cnt+=abs(B[j+1]-B[j])
    print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
    yen = sum(sa) + abs(a[i+2]-a[i]) - sa[i] - sa[i+1]
    print(yen)

Submission status: Time Limit Exceeded

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

for i in range(n):
    p = list(range(n+1)) + [0]
    p.pop(i+1)

    yen = sum(sa) + abs(a[p[i+1]] - a[p[i]]) - sa[i] - sa[i+1]
    print(yen)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0]
a += list(map(int,input().split()))
w = [[0]*(n+1) for _ in range(n+1)]

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

for i in range(1,n+1):
    yen = 0
    p = list(range(n+1)) + [0]
    p.pop(i)

    for j in range(n):
        yen += w[p[j]][p[j+1]]
    print(yen)