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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from copy import deepcopy

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

s = []
for i in range(0,N):
    n = 0
    B = deepcopy(A)
    del(B[i]) 
    for j in range(0,N-1):
        if j == 0:
            n = abs(B[j])
        elif j == N-2:
            n = n + abs(B[j-1] - B[j]) 
            n = n + abs(B[j])
        else:
            n = n + abs(B[j-1] - B[j])
    s.append(n)
    
for i in s:
    print(i)

Submission status: Wrong Answer

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
    n = S - (abs(I[i]) + abs(I[i + 1])) + I[i] + I[i + 1]
    print(n)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
# a = []
# for i in range(N):
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
for i in range(2, N+2):
    a_tmp=copy.copy(a)
    del a_tmp[i]
    d = 0
    for j in range(N):
        d += abs(a_tmp[j+1] - a_tmp[j])
    print(d)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
sumroute = 0
ever = 0

for i in range(len(b)):
    sumroute += abs(b[i] - ever)
    ever = b[i]
sumroute += abs(b[-1])
b.append(0)
if b[0] * b[1] < 0:
    print(sumroute-(2*abs(b[0])))
else:
    print(sumroute)
for i in range(len(b)-2):
    if (b[i+1]-b[i]) * (b[i+2]-b[i+1]) < 0:
        print(sumroute-2*min(abs(b[i+1]-b[i]),abs(b[i+2]-b[i+1])))
    else:
        print(sumroute)

Submission status: Wrong Answer

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

for j in range(len(A)):
    A_copy = A[:]
    A_copy.pop(j)
    for i in range(0,len(A_copy)):
        if i == 0:
            wa = abs(A_copy[0])
        elif i == len(A_copy)-1:
            wa = wa + abs(A_copy[i-1]-A_copy[i]) + abs(A_copy[i])
        else:
            wa = wa + abs(A_copy[i-1]-A_copy[i])
    print(wa)

Submission status: Wrong Answer

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

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

s = []
for i in range(0,N):
    n = 0
    B = copy.deepcopy(A)
    del(B[i]) 
    for j in range(0,N-1):
        if j == 0:
            n = abs(B[j])
        elif j == N-2:
            n = n + abs(B[j-1] - B[j]) 
            n = n + abs(B[j])
        else:
            n = n + abs(B[j-1] - B[j])
    s.append(n)
    
for i in s:
    print(i)

Submission status: Wrong Answer

Solution code:
from array import array   
N = int(input())
A = [int(i) for i in input().split()]
# 何も取りやめないときの総コスト
now = 0
cost = 0
for po in A:
    cost += abs(now - po)
    now = po
cost += abs(now)

dist = array('l',[0]+A+[0,0])
print(dist)
# i番目を取りやめる
for i in range(N):
    ans = cost
    ans += (abs(dist[i]-dist[i+2])) - (abs(dist[i]-dist[i+1])+abs(dist[i+1]-dist[i+2]))
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - Traveling Plan
https://beta.atcoder.jp/contests/abc092/tasks/arc093_a

"""
import sys
from sys import stdin

input = stdin.readline


def solve(spots, N):
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])

    ans = []
    spots.append(0)
    spots.insert(0, 0)
    for i in range(1, N):
        if spots[i-1] <= spots[i] <= spots[i+1] or spots[i-1] >= spots[i] >= spots[i+1]:
            ans.append(total_cost)
        else:
            t1 = abs(spots[i] - spots[i-1]) * 2
            ans.append((total_cost - t1))

    spots = spots[:-2]
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])
    ans.append(total_cost)

    return ans


def main(args):
    N = int(input())
    spots = [int(x) for x in input().split()]
    ans = solve(spots, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]+[0]
S = [0]*(n+1)
current = 0
s = 0
print(A)
for i in range(n):
    S[i] = abs(A[i]-current)
    current = A[i]


S[n] = abs(0-current)
print(S)
for i in range(n):
    if i != 0:
        b = S.copy()
        b[i] = 0
        b[i+1] = 0
        print(sum(b)+abs(A[i+1]-A[i-1]))
    else:
        b = S.copy()
        b[i] = 0
        b[i+1] = 0
        print(sum(b)+abs(A[i+1]-0))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split(" ")))

yen = 0
x = 0
for i in a:
    yen += abs(i - x)
    x = i
yen += abs(x)

for i in range(n):
    if(i == 0):
        if((0 <= a[i] and a[i] <= a[i+1]) or (0 >= a[i] and a[i] >= a[i+1])):
            print(yen)
        else:
            print(yen - abs(a[i] * 2))
    elif(i+1 < n):
        if((a[i-1] <= a[i] and a[i] <= a[i+1]) or (a[i-1] >= a[i] and a[i] >= a[i+1])):
            print(yen)
        else:
            print(yen - abs((a[i] - a[i-1]) * 2))
    else:
        if((a[i-1] <= a[i] and a[i] <= 0) or (a[i-1] >= a[i] and a[i] >= 0)):
            print(yen)
        elif(a[i-1] * a[i] < 0):
            print(yen - abs(a[i] * 2))
        else:
            print(yen - abs((a[i-1] - a[i]) * 2))
        break

Submission status: Wrong Answer

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

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

ans = [0] * N

for i in range(N):
    if i == 0:
        if (int(A[i]) * int(A[i+1]) < 0) or (int(A[i+1]) == 0):
            ans[i] = dis - int(A[i]) * 2
        elif int(A[i]) == 0:
            ans[i] = dis
        else:
            if abs(int(A[i+1])) >= abs(int(A[i])):
                ans[i] = dis
            else:
                ans[i] = dis - abs(int(A[i+1]) - int(A[i])) * 2
    elif i == N-1:
        a = int(A[i-1])
        b = int(A[i])
        if (a*b > 0):
            if abs(b)-abs(a) > 0:
                ans[i] = dis - abs(b-a)*2
            else:
                ans[i] = dis
        else:
            ans[i] = dis - abs(b)*2
    else:
        a = int(A[i-1])
        b = int(A[i]) - a
        c = int(A[i+1]) - a
        if (b * c < 0) or (c == 0):
            ans[i] = dis - abs(b) * 2
        elif b == 0:
            ans[i] = dis
        else:
            if abs(c) >= abs(b):
                ans[i] = dis
            else:
                ans[i] = dis - abs(c - b) * 2


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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
m = []
for i in range(n):
    if a[i] <= a[i + 1] <= a[i + 2] or a[i + 2] <= a[i + 1] <= a[i]:
        m.append(0)
    elif a[i] <= a[i + 2] <= a[i + 1]:
        m.append(1)
    elif a[i + 1] <= a[i] <= a[i + 2]:
        m.append(2)
    elif a[i + 1] <= a[i + 2] <= a[i]:
        m.append(3)
    elif a[i + 2] <= a[i] <= a[i + 1]:
        m.append(4)

s = sum(abs(a[i] - a[i + 1]) for i in range(n + 1))
print(m, s)

for i, m0 in enumerate(m):
    if m0 == 0:
        print(s)
    elif m0 == 1:
        print(s - 2 * abs(a[i + 1] - a[i + 2]))
    elif m0 == 2:
        print(s - 2 * abs(a[i] - a[i + 1]))
    elif m0 == 3:
        print(s - 2 * abs(a[i + 1] - a[i + 2]))
    elif m0 == 4:
        print(s - 2 * abs(a[i] - a[i + 1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
m = []
for i in range(n):
    if a[i] <= a[i + 1] <= a[i + 2] or a[i + 2] <= a[i + 1] <= a[i]:
        m.append(0)
    elif a[i + 1] <= a[i] <= a[i + 2] or a[i + 1] <= a[i + 2] <= a[i]:
        m.append(1)
    elif a[i] <= a[i + 2] <= a[i + 1] or a[i + 2] <= a[i] <= a[i + 1]:
        m.append(-1)

s = sum(abs(a[i] - a[i + 1]) for i in range(n + 1))
print(m, s)

for i, m0 in enumerate(m):
    if m0 == 0:
        print(s)
    elif m0 > 0:
        print(s - 2 * abs(a[i + 1] - a[i + 2]))
    elif m0 < 0:
        print(s - 2 * abs(a[i] - a[i + 1]))

Submission status: Wrong Answer

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


head_rm = points[1:]
tail_rm = points[0:len(points)-1]

amount = sum(abs(head_rm - tail_rm)) + abs(points[0]) + abs(points[-1])

points = np.insert(points, 0, 0)
points = np.insert(points, len(points), 0)

for i in range(1,len(points) - 1):
	if (points[i] < points[i-1] and points[i-1] < points[i+1]) or (points[i] > points[i-1] and points[i-1] > points[i+1]):
		print(amount - 2 * abs(points[i-1] - points[i]))
	elif (points[i] < points[i+1] and points[i+1] < points[i-1]) or (points[i] > points[i+1] and points[i+1] > points[i-1]):
		print(amount - 2* abs(points[i+1] - points[i]))
	else:
		print(amount)

Submission status: Wrong Answer

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

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

s = []
for i in range(0,N):
    n = 0
    B = copy.deepcopy(A)
    del(B[i]) 
    for j in range(0,N-1):
        if j == 0:
            n = n + abs(B[j])
        elif j == N-2:
            n = n + abs(B[j-1] - B[j])
            n = n + abs(B[j])
        else:
            n = n + abs(B[j-1] - B[j])
    s.append(n)
    
for i in s:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
# a = []
# for i in range(N):
a = list(map(int, input().split()))
print(a)
for i in range(N):
    a_tmp=copy.deepcopy(a)
    del a_tmp[i]
    a_tmp.insert(0, 0)
    a_tmp.append(0)
    d = 0
    for j in range(N):
        d += abs(a_tmp[j+1] - a_tmp[j])
    print(d)

Submission status: Wrong Answer

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

print(a)
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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

d.append(-a[-1])

for i in range(n):
    s = 0
    for j in range(n+1):
        if j == i:
            s += abs(d[j] + d[j+1])
        elif j == i + 1:
            pass
        else:
            s += abs(d[j])
    print(s)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
  ans = sum(dist)-(dist[i]+dist[i+1])
  ans += abs(lst[i]-lst[i+2])
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    for i in range(n):
        S = A[:i] + A[i + 1:]
        D = [abs(S[i + 1] - S[i]) for i in range(n - 2)]
        print(sum(D) + abs(S[0]) + abs(S[-1]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

copy_idou=idou[:]
copy_idou[0],copy_idou[1]=0,abs(lst[1])
print(sum(copy_idou))

for i in range(1,n-1):
    copy_idou=idou[:]
    copy_idou[i],copy_idou[i+1]=0,(abs(lst[i+1]-lst[i-1]))
    print(sum(copy_idou))

copy_idou=idou[:]
copy_idou[-1],copy_idou[-2]=abs(lst[-2]),0
print(sum(copy_idou))

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

Submission status: Time Limit Exceeded

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

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

for i in range(1,N+1):
    c = copy.copy(b)
    sum_c = 0
    del c[i]
    for j in range(1,len(c)):
        sum_c += abs(c[j]-c[j-1])
    print(sum_c)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))

    As.append(0)
    for i in range(n):
        s = 0
        ans = 0
        for j in range(n+1):
            if j == i:
                continue
            ans += abs(As[j] - s)
            s = As[j]
        print(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):
  ans = 0
  t = 0
  for j in range(n):
    if i == j: continue
    ans += abs(t - a[j])
    t = a[j]
  ans += abs(t)
  print(ans)

Submission status: Time Limit Exceeded

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

full_root = [0] + A + [0]
full_place = [abs(full_root[i] - full_root[i + 1]) for i in range(N + 1)]
# check
for ind in range(1, N + 1):
    if ind == 1:
        res = sum(full_place[2:])
    elif ind == N + 1:
        res = sum(full_place[:-2])
    else:
        res = sum(full_place[:ind - 1] + full_place[ind + 1:])

    print(res + abs(full_root[ind - 1] - full_root[ind + 1]))

Submission status: Time Limit Exceeded

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


root = [0] + A + [0]
# check
for ind in range(1, N + 1):
    target = [r for i, r in enumerate(root) if i != ind]
    res = sum([abs(target[i] - target[i + 1]) for i in range(N)])
    print(res)

Submission status: Time Limit Exceeded

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

# check
for ind in range(N):
    target = [0] + [a for i, a in enumerate(A) if i != ind] + [0]
    res = sum([abs(target[i] - target[i + 1]) for i in range(N)])
    print(res)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
di[0] = abs(ls[0])
di[-1] = abs(ls[-1])
for i in range(1,n):
    di[i] = abs(ls[i] - ls[i-1])
for j in range(n):
    if j == 0:
        if (ls[j])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    elif j == n-1:
        if (ls[j]-ls[j-1])*(-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    else:
        if (ls[j]-ls[j-1])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))

Submission status: Time Limit Exceeded

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

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)
ans = []
for i in range(1, n+1):
    new_a = a.copy()
    new_a.pop(i)
    ans.append(sum([abs(new_a[i] - new_a[i+1]) for i in range(len(new_a) - 1)]))

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# O(N^2)?
N = int(input())
A = [int(x) for x in input().split()]


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

Submission status: Time Limit Exceeded

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

for i in range(n):#とばす番号
    ans = 0
    tmp = 0
    for j in range(n):
        if j == i:
            pass
        elif tmp*s[j] >= 0:#符号が同じとき
            if abs(s[j]) > abs(tmp):#外側へ移動
                ans += abs(tmp - s[j])
                tmp = s[j]
            elif abs(s[j]) < abs(tmp):#内側へ移動
                ans += abs(tmp - s[j])
                tmp = s[j]
        elif tmp*s[j] < 0:#符号が違う時
            ans += abs(tmp - s[j])
            tmp = s[j]
    ans += abs(tmp)
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
  d = 0
  lst = a_lst[:i] + a_lst[i+1:]
  for i, elem in enumerate(lst):
    if i == 0:
      d += abs(elem)
    else:
      d += abs(elem - lst[i-1])
  d += abs(lst[-1])
  print(d)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

a = [0] + a + [0]

for i in range(n):
  my_sum = 0
  l = copy.copy(a)
  del l[i+1]
  for j in range(n):
    my_sum += abs(l[j] - l[j+1])
  print(my_sum)

Submission status: Time Limit Exceeded

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

cost = []

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

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

Submission status: Time Limit Exceeded

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


for i in range(n):
    count = 0
    before = 0
    for j, num in enumerate(a):
        if i == j:
            continue
        count += abs(before - num)
        before = num
    print(count + abs(before))

Submission status: Time Limit Exceeded

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

dist = [abs(a[i + 1] - a[i]) for i in range(len(a) - 1)]

for i in range(1, n + 1):
    ans = sum(dist) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i + 1])
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])

for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        print(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
'''
for i in range(n):
    p = a[:i] + a[i+1:]
    ans = 0
    for j in range(1,len(p)):
        ans += abs(p[j-1] - p[j])
    ans += abs(p[0]) + abs(p[-1])
    print(ans)
'''
abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)


for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(abs1_sum - abs1[0] + abs(p[0]) + abs(p[-1]))
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(abs1_sum - abs1[-1] + abs(p[0]) + abs(p[-1]))
    else:
        print(abs(p[0]) + abs(p[-1]) + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
'''
for i in range(n):
    p = a[:i] + a[i+1:]
    ans = 0
    for j in range(1,len(p)):
        ans += abs(p[j-1] - p[j])
    ans += abs(p[0]) + abs(p[-1])
    print(ans)
'''
abs1 = []
for i in range(1,n):
    abs1.append(abs(a[i-1]-a[i]))

abs2 = []
for i in range(2,n):
    abs2.append(abs(a[i-2]-a[i]))
#print(abs1)
for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(sum(abs1[1:]) + abs(p[0]) + abs(p[-1]))
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(sum(abs1[:n-2]) + abs(p[0]) + abs(p[-1]))
    else:
        print(abs(p[0]) + abs(p[-1]) + sum(abs1[:i-1] + abs1[i+1:]) + abs2[i-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N=int(input())
A=list((map(int,input().split())))
A.insert(0,0)

d=[]
skip_d=[]

for i in range(N):
    d.append(abs(A[i+1]-A[i]))
    if i<N-1:
        skip_d.append(abs(A[i+2]-A[i]))
    else:
        skip_d.append(abs(A[0]-A[i]))

d.append(abs(A[-1]))


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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input().split()
AA=[int(a) for a in A]
answer=AA[1:]
saisho=0
for a in range(N - 2):
    saisho += abs(answer[a + 1] - answer[a])
saisho += abs(answer[0]) + abs(answer[N - 2])
print(saisho)
for a in range(N-2):
    list1=AA[:a+1]
    list2=AA[a+2:]
    list=list1+list2
    whole=0
    for a in range(N-2):
        whole+=abs(list[a+1]-list[a])
    whole+=abs(list[0])+abs(list[N-2])
    print(whole)
answer=AA[:N-1]
saisho=0
for a in range(N - 2):
    saisho += abs(answer[a + 1] - answer[a])
saisho += abs(answer[0]) + abs(answer[N - 2])
print(saisho)

Submission status: Time Limit Exceeded

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

a.append(0)
tmp = 0
ans = 0

for i in range(n):
    for y in range(n+1):
        if i == y:
            pass
        else:
            ans += abs(a[y] - tmp)
            tmp = a[y]
    print(ans)
    tmp = 0
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
#C - Traveling Plan
N = int(input())
A = list(map(int, input().split()))
DP = []
ans = []
DP.append(abs(0-A[0]))
for i in range(1,N):
    DP.append(abs(A[i]-A[i-1]))

for j in range(N):
    DP2 = DP[:]
    #DP2.pop(j)

    if j == 0:
        DP2[j+1] = abs(A[j+1])
        tmp = sum(DP2)-DP2[0]+abs(A[N - 1])
    elif j == N-1:
        tmp = sum(DP2)-DP2[N-1]+abs(A[N - 2])
    else:
        tmp = sum(DP2) + abs(A[N - 1])-DP2[j]-DP2[j+1]+abs(A[j+1]-A[j-1])
    ans.append(tmp)

for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

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

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

d = [0]*(len(a)-1)
for i in range(len(a)-1):
    d[i] = abs(a[i]-a[i+1])

for i in range(len(d)-1):
    print(sum(d[:i]) + sum(d[i+2:]) + abs(a[i] - a[i+2]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    answer = 0
    del_A = copy.copy(A)
    del_A.remove(A[i])
    # del_A.sort()
    # print(del_A)
    answer += abs(del_A[0])
    for j in range(1, N-1):
        answer += abs(del_A[j] - del_A[j-1])
    answer += abs(del_A[-1])
    # MIN = min(0, del_A[0])
    # MAX = max(0, del_A[-1])
    # # print(MIN, MAX)
    # answer = abs(MAX - MIN) * 2
    print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    ans = 0
    a_i = a.copy()
    a_i.pop(i)
    for j in range(n-2):
        ans += abs(a_i[j+1] - a_i[j])
    ans += abs(a_i[0])
    ans += abs(a_i[-1])
    

    print(ans)