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:
N = int(input())
A = list(map(int,input().split()))
 
for i in range(N):
  now = 0
  ans = 0
  for j in range(N):
    if i != j:
      next = A[j]
      ans += abs(next - now)
      now = next
  ans += abs(A[-1])
  print(ans)

Submission status: Wrong Answer

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

for i in range(N):
  now = 0
  ans = 0
  B = [A[j] for j in range(N) if j != i]
  for next in A:
    ans += abs(next - now)
    now = next
  ans += abs(B[-1])
  print(ans)

Submission status: Wrong Answer

Solution code:
# ARC093c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

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

    total = 0
    for i in range(1, n+2):
        total += abs(a[i]-a[i-1])
    # print(total)

    for j in range(1, n+1):
        if a[j-1] <= a[j] <= a[j+1] or a[j-1] >= a[j] >= a[j+1]:
            print(total)
            continue
        print(total-abs(a[j]-a[j-1])-abs(a[j+1]-a[j])+abs(a[j+1]-a[j-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
value=sum([round(abs(A[i+1]-A[i])) for i in range(N-1)])+round(abs(A[0]))+round(abs(A[-1]))
for i in range(N):
    if i==0:
        if 0<=A[i]<=A[i+1] or 0>=A[i]>=A[i+1]:
            print(value)
        else:
            print(value-round(min(abs(A[i]-0),abs(A[i+1]-A[i]))))
    elif i==N-1:
        if A[i-1]<=A[i]<=0 or A[i-1]>=A[i]>=0:
            print(value)
        else:
            print(value-2*round(min(abs(A[i]-0),abs(A[i-1]-A[i]))))
    else:
        if A[i-1]<=A[i]<=A[i+1] or A[i-1]>=A[i]>=A[i+1]:
            print(value)
        else:
            print(value-2*round(min(abs(A[i]-A[i-1]),abs(A[i+1]-A[i]))))

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mina = min(a)
a.insert(0, 0), a.append(0)
total = 0
for i in range(N + 1):
    total += abs(a[i] - a[i + 1])

for i in range(N):
    if maxa != a[i + 1] and mina != a[i + 1]:
        print(total)
    else:
        ans = total - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2]) + abs(a[i] - a[i + 2])
        print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mina = min(a)
total = abs(a[0])
for i in range(N - 1):
    total += abs(a[i] - a[i + 1])
total += abs(a[-1])

for i in range(N):
    if maxa != a[i] and mina != a[i]:
        print(total)
    else:
        breaki = a[i]
        tmplst = copy.deepcopy(a)
        ans = abs(tmplst[0])
        del tmplst[tmplst.index(a[i])]
        for j in range(N - 2):
            ans += abs(tmplst[j] - tmplst[j + 1])
        print(ans + abs(tmplst[-1]))

Submission status: Wrong Answer

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

ans = abs(a[0] )

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

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        elif 0 <= a[i+1] <= v or v <= a[i+1] <= 0:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= 0 <= a[i+1] or a[i+1] <= 0 <= v:
            print(ans-abs(v)*2)


        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        else:
            print(ans-2*abs(v))
    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= 0 <= v or v <= 0 <= a[i-1]:
            print(ans-abs(v)*2)
        elif v <= a[i-1] <= 0 or 0 <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

Submission status: Wrong Answer

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

ans = abs(a[0] )

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

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        else:
            print(ans-2*abs(v))
    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]: 
            print(ans)
        else:
            print(ans-2*abs(v))
    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

Submission status: Wrong Answer

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

ans = a[0] 

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

ans += abs(a[-1] - 0)

for i, v in enumerate(a):
    if i == 0:
        if 0 <= v <= a[i+1] or a[i+1] <= v <= 0:
            print(ans)
        else:
            print(ans-2*abs(v))
    elif i == n-1:
        if a[i-1] <= v <= 0 or 0 <= v <= a[i-1]: 
            print(ans)
        else:
            print(ans-2*abs(v))
    else:
        if a[i-1] <= v <= a[i+1] or a[i+1] <= v <= a[i-1]:
            print(ans)
        elif a[i-1] <= a[i+1] <= v or v <= a[i+1] <= a[i-1]:
            print(ans-abs(a[i+1]-v)*2)
        elif v <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= v:
            print(ans-abs(a[i-1]-v)*2)

Submission status: Wrong Answer

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

s = abs(a[0]) + abs(a[-1])
l = [abs(a[0])]
a.append(0)
for i in range(n-1):
    if a[i] >= 0 and a[i+1] >= 0 or a[i] < 0 and a[i+1] < 0:
        l.append(max(abs(a[i]), abs(a[i+1])) - min(abs(a[i]), abs(a[i+1])))
        s += l[i+1]
    else:
        l.append(abs(a[i]) + abs(a[i+1]))
        s += l[i+1]
l.append(abs(a[-2]))

a = [0]+a
for i in range(1, n+1):
    if 0 <= a[i] <= a[i+1] or 0 > a[i] > a[i+1]:
        print(s)
    elif a[i] <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= a[i]:
        print(s-l[i-1]*2)
    else:
        print(s-l[i]*2)

Submission status: Wrong Answer

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

s = abs(a[0]) + abs(a[-1])
l = [abs(a[0])]
a.append(0)
for i in range(n-1):
    if a[i] >= 0 and a[i+1] >= 0 or a[i] < 0 and a[i+1] < 0:
        l.append(max(abs(a[i]), abs(a[i+1])) - min(abs(a[i]), abs(a[i+1])))
        s += l[i+1]
    else:
        l.append(abs(a[i]) + abs(a[i+1]))
        s += l[i+1]
l.append(abs(a[-2]))

a = [0]+a
for i in range(1, n+1):
    if 0 <= a[i] <= a[i+1] or 0 > a[i] > a[i+1]:
        print(s)
    elif a[i] <= a[i-1] <= a[i+1] or a[i+1] <= a[i-1] <= a[i]:
        print(s-l[i-1]*2)
    else:
        print(s-l[i]*2,2)

Submission status: Wrong Answer

Solution code:
n = int(input())
spots = list(map(int,input().split()))
s_spots = sorted(spots)
pos_1 = s_spots[-1]
pos_2 = s_spots[-2]
neg_1 = s_spots[0]
neg_2 = s_spots[1]

for i in range(n):
  if spots[i] == pos_1:
    print((max(pos_2,0) - min(neg_1,0))*2)
  elif spots[i] == neg_1:
    print((max(pos_1,0) - min(neg_2,0))*2)
  else:
    print((max(pos_1,0) - min(neg_1,0))*2)

Submission status: Wrong Answer

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

A.insert(0,0)
A.append(0)

B = [0]*(N+2)

total=0
last=0
for i in range(1,N+1):
    if(((A[i]-A[i-1])*(A[i+1]-A[i]))>=0):
        B[i]=1
    else:
        B[i]=-1
        total+=abs(last-A[i])
        last=A[i]

total+=abs(last)

for i in range(1,N+1):
    if(B[i]==1):
        print(total)
    else:
        print(total-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

Submission status: Wrong Answer

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

F = [0]
for i in range(1, N+1):
    F.append(abs(A[i] - A[i-1]) + F[i-1])

B = [0]
for i in range(1, N+1):
    B.append(abs(A[N+1-i] - A[N+2-i]) + B[i-1])
B.reverse()

for i in range(1, N+1):
    print(abs(A[i+1]-A[i-1]) + F[i-1] + B[i])

Submission status: Wrong Answer

Solution code:
import copy
 
n = int(input())
natural = [int(i) for i in input().split()]
sortedlist = sorted(natural)
 

 
for i in range(n):
  sum = 0
  removed = copy.deepcopy(sortedlist)
  removed.remove(natural[i])
  for j in range(n-1):
    if j == 0:
      sum += abs(removed[j])
    else:
      sum += abs(removed[j]-removed[j-1])
  sum += abs(removed[n-2])
  print(sum)

Submission status: Wrong Answer

Solution code:
# ARC093C - Traveling Plan
def main():
    N = int(input())
    A = list(map(int, input().rstrip().split()))
    for i in range(N):
        ans = 0
        cur = 0
        for j in range(N):
            if i == j:
                continue
            ans += max(cur, A[j]) - min(cur, A[j])
            cur = A[j]
    print(ans + abs(cur))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
max1=b[-1]
max2=max(b[-2],0)
min1=b[0]
min2=min(b[1],0)
lackmax=(max2-min1)*2
lackmin=(max1-min2)*2
normal=(max1-min1)*2
for i in range(n):
    if a[i]==max1:
        print(lackmax)
    elif a[i]==min1:
        print(lackmin)
    else:
        print(normal)

Submission status: Wrong Answer

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

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split(' ')))
X = sorted(A)
MAX = X[N-1]
MAX_SEC = X[N-2]
MIN = X[0]
MIN_SEC = X[1]
for x in A:
  if not (x == MAX or x == MIN):
    print(abs(min(MIN,0))*2 + abs(max(0,MAX))*2)  
  elif x == MIN:
    print(abs(min(MIN_SEC,0))*2 + abs(max(0,MAX))*2)
  elif x == MAX:
     print(abs(min(MIN,0))*2 + abs(max(0,MAX_SEC))*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
dd = list(map(int, input().split()))
d = [0]
d.extend(dd)
d.append(0)

diff = [abs(d[i + 1] - d[i]) for i in range(N + 1)]

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

s = sum(diff)
for i in range(N):
    print(s - dd[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = abs(A[0]) + abs(A[-1])
for i in range(N-1):
  s += abs(A[i+1] - A[i])
#print(s)
for i in range(N):
  b = A[i]
  if i == 0:
    a = 0
  else:
    a = A[i-1]
  if i == N-1:
    c = 0
  else:
    c = A[i+1]
  if a < b and b < c:
    print(s)
  elif a < c and c < b:
    print(s-(b-c)*2)
  elif b < a and a < c:
    print(s-(a-b)*2)
  elif b < c and c < a:
    print(s-(c-b)*2)
  elif c < a and a < b:
    print(s-(b-a)*2)
  else:
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = abs(A[0]) + abs(A[-1])
for i in range(N-1):
  s += abs(A[i+1] - A[i])
#print(s)
for i in range(N):
  b = A[i]
  if i == 0:
    a = 0
  else:
    a = A[i-1]
  if i == N-1:
    c = 0
  else:
    c = A[i+1]
  if a < b and b < c:
    print(s)
  elif a < c and c < b:
    print(s-(b-c)*2)
  elif b < a and a < c:
    print(s-(c-a)*2)
  elif b < c and c < a:
    print(s-(c-b)*2)
  elif c < a and a < b:
    print(s-(b-a)*2)
  else:
    print(s)

Submission status: Wrong Answer

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

#普通に総和を出す
sum = 0
for i,(a, dif) in enumerate(zip(A, diff)):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - dif) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(N):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)

Submission status: Wrong Answer

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

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

for i in range(1,n+1):
  if a[i] == max(a) or a[i] == min(a):
    print(s - 2 * min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1])))
  else:
    print(s)

Submission status: Wrong Answer

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

s = sum([abs(a[i]-a[i+1]) for i in range(n+1)])
for i in range(1,n+1):
  if a[i] == max(a) or a[i] == min(a):
    print(s - 2 * min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1])))
  else:
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(abs(A[1])*2)
    print(abs(A[0])*2)
    exit()

normal_costs = [abs(A[0]), ]
for i in range(N-1):
    normal_costs.append(abs(A[i+1]-A[i]))
normal_costs.append(abs(A[N-1]))

default_cost = sum(normal_costs)

for i in range(N):
    if i == 0:
        print(abs(A[i])+sum(normal_costs[1:]))
        continue
    elif i == N-1:
        print(sum(normal_costs[:N-1])+abs(A[N-2]))
        continue

    cost = default_cost - abs(A[i+1]-A[i]) - abs(A[i]-A[i-1]) \
        + abs(A[i+1]-A[i-1])
    print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(abs(A[1])*2)
    print(abs(A[0])*2)
    exit()

normal_costs = [abs(A[0]), ]
for i in range(N-1):
    normal_costs.append(abs(A[i+1]-A[i]))
normal_costs.append(abs(A[N-1]))

new_costs = [0, ]
for i in range(1, N-1):
    new_costs.append(abs(A[i+1]-(A[i-1])))
default_cost = sum(normal_costs)

for i in range(N):
    if i == 0:
        print(abs(A[i])+sum(normal_costs[1:]))
        continue
    elif i == N-1:
        print(sum(normal_costs[:-2])+abs(A[-2]))
        continue
    cost = default_cost - normal_costs[i+1] - normal_costs[i] \
        + new_costs[i]
    print(cost)

Submission status: Wrong Answer

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

new_costs = [0, ]
for i in range(1, N-1):
    new_costs.append(abs(A[i+1]-(A[i-1])))
default_cost = sum(normal_costs)

for i in range(N):
    if i == 0:
        print(abs(A[i])+sum(normal_costs[1:]))
        continue
    elif i == N-1:
        print(sum(normal_costs[:-2])+abs(A[-2]))
        continue
    cost = default_cost - normal_costs[i+1] - normal_costs[i] \
        + new_costs[i]
    print(cost)

Submission status: Wrong Answer

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


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

for i in range(1, N + 1):
    d1 = abs(A[i - 1] - A[i])
    d2 = abs(A[i + 1] - A[i])
    d3 = abs(A[i - 1] - A[i + 1])
    print(sum - d1 - d2 + d3)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
line = input().split(' ')
a = [int(element) for element in line]
tempMin = copy.deepcopy(a)
tempMax = copy.deepcopy(a)

minV = min(a)
tempMin.remove(minV)
minV2nd = min(tempMin)
maxV = max(a)
tempMax.remove(maxV)
maxV2nd = max(tempMax)

for i in range(n):
    high = maxV
    low = minV
    if a[i] == minV:
        low = minV2nd
    if a[i] == maxV:
        high = maxV2nd
    print(i, low, high)
    if low < 0 and 0 < high:
        print (2 * abs(high - low))
    else:
        print (2 * max(abs(low), abs(high)))

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
line = input().split(' ')
a = [int(element) for element in line]

for element in a:
    temp = copy.deepcopy(a)
    temp.remove(element)
    maxV = max(temp)
    minV = min(temp)
    if minV < 0 and 0 < maxV:
        print ( 2 * abs(maxV - minV) )
    else:
        print ( 2 * max(abs(maxV), abs(minV)) )

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int, input().split()))
def abs(m):
  if m>0:
    return m
  return(-m)
def mysum(data):
  ans = 0
  data = [0] + data+[0]
  for j in range(len(data)-1):
    ans += abs(data[j] - data[j+1])
for i in range(len(lis)):
  tmp = lis[:i-1] + lis[i:]
  print(mysum(tmp))

Submission status: Wrong Answer

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

def main():
    try:
        N = int,raw_input()
        A = map(int,raw_input().split())
        for i in range(len(A)):
            distance = 0
            now_pos = 0
            for index,a in enumerate(A):
                if i is not index:
                    distance = now_pos + abs(distance - a)
                    now_pos = a

            print distance + abs(now_pos)

    except:
        traceback.print_exc()
        return 0

main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# get a integer
num = int(raw_input())
# get two integers separated with half-width break
array = map(int, raw_input().split())
# get a string
#s = raw_input()

for i in range(0,num):
    state = 0
    way = 0
    for j in range(0,num):
        if i != j:
            if not (j+1 < num and state <= array[j] and array[j] <= array[j+1]) \
                and not (j+1 < num and state >= array[j] and array[j] >= array[j+1]):
                way += abs(array[j] - state)
                state = array[j]
    way += abs(state)
    print(way)

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n):
        fix = [0] + a[0:i] + a[i + 1:n] + [0]
        ans[i] = sum([abs(fix[j] - fix[j - 1]) for j in range(1, n + 1)])
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import numpy

N = int(input())
p = [int(x) for x in input().split()]
p = [0] + p + [0]

for i in range(1, N + 1):
    q = p[:i] + p[i+1:]
    print(numpy.sum(numpy.abs(numpy.diff(q))))

Submission status: Time Limit Exceeded

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

for i in range(N):
    newlist.pop(i)
    for j in range(len(newlist)-1):
        count=count+abs(newlist[j+1]-newlist[j])
    print(count+abs(newlist[-1])+abs(newlist[0]))
    newlist=copy.copy(shelter)
    count=0

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
spot_num = int(input())
spot_place = [ int(p) for p in input().split(" ") ]

for i in range(spot_num):
  total_price = 0
  current_place = 0

  for j in range(spot_num):
    if i == j:
      continue
    total_price += abs(spot_place[j] - current_place)
    current_place = spot_place[j]

  print(total_price + abs(0 - current_place))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
A=[0]+A+[0]
dist=[0]*(N+1)
for i in range(N+1):
    dist[i]=abs(A[i]-A[i+1])
for i in range(1,N+1):
    if A[i]<min(A[i-1],A[i+1]) or A[i]>max(A[i-1],A[i+1]):
        print(sum(dist)-2*min(dist[i-1],dist[i]))
    else:
        print(sum(dist))

Submission status: Time Limit Exceeded

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

A.insert(0,0)
A.append(0)
_A = []

for i in range(1,N+1):
  _A.append(abs(A[i] - A[i-1]))
_A.append(abs(0-A[N]))
S = sum(_A)


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

Submission status: Time Limit Exceeded

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

A.insert(0,0)
A.append(0)
_A = []
for i in range(1,N+1):
  _A.append(abs(A[i] - A[i-1]))
_A.append(abs(0-A[N]))
allS = sum(_A)


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

Submission status: Time Limit Exceeded

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

A.insert(0,0)
A.append(0)
_A = []
for i in range(1,N+1):
  _A.append(abs(A[i] - A[i-1]))
_A.append(abs(0-A[N]))
allS = sum(_A)


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

Submission status: Time Limit Exceeded

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


for i in range(N):
    price = 0
    now = 0
    cnt = 0
    while True:
        if (cnt == i):
            cnt += 1
            continue
        if (cnt == N):
            price += abs(now)
            break
        price += abs(A[cnt] - now)
        now = A[cnt]
        cnt += 1

    print(price)

Submission status: Time Limit Exceeded

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


arr=np.array(l)
arr2=np.append(np.hstack((0,arr)),0)
differ=sum(abs(np.diff(arr2)))
for i in range(1,n+1):
    difference=abs(np.diff(arr2)[i]+np.diff(arr2)[i-1])-abs(np.diff(arr2)[i])-abs(np.diff(arr2)[i-1])
    print(differ+difference)

Submission status: Time Limit Exceeded

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


arr=np.array(l)
arr2=np.append(np.hstack((0,arr)),0)
for i in range(1,n+1):
    arr3=np.copy(arr2)
    arr3=np.delete(arr3,i)
    diff=np.diff(arr3)
    print(sum(abs(diff)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for h in range(1, n+1):
    ans = 0
    memo = a.pop(h)    # 削除
    for i in range(n):
        ans += abs(a[i]-a[i+1])
    a.insert(h, memo)
    print(ans)

Submission status: Time Limit Exceeded

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


for i in range(N):
    a = A[:i] + A[i+1:]
    a.append(0)
    ans = 0
    current = 0
    for dest in a:
        ans += abs(dest - current)
        current = dest
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A= [int(j) for j in input().split()]
import numpy as np


def python_list_add(in1, in2):
    wrk = np.abs(np.array(in1) - np.array(in2))
    return wrk.tolist()

for i in range(N):
    L1 = A[:i]+A[i+1:]+[0]
    L2 = [0]+A[:i]+A[i+1:]
    print(sum(python_list_add(L1,L2)))

Submission status: Time Limit Exceeded

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

for i in range(n):
    tmp=0
    ans=0
    for j in range(n):
        if i==j:
            continue
        ans+=abs(tmp-a_input[j])
        tmp=a_input[j]
    if i==n-1:
        ans+=abs(a_input[-2])
    else:
        ans+=abs(a_input[-1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array([0] + input().split(), np.int32)
B = np.append(A[1:], 0)
S = np.abs(A - B).sum()

ans = [0] * (N + 1)
for i in range(1, N + 1):
    j = (i + 1) % (N + 1)
    d0 = A[i] - A[i - 1]
    d1 = A[j] - A[i - 1]
    f0 = d0 >= 0
    f1 = d1 >= 0
    # print(d0, d1)
    # i - 1, i, i + 1の並び
    if f0 == f1 and abs(d0) <= abs(d1):
        ans[i] = S
    # i - 1, i + 1, iの並び
    elif f0 == f1 and abs(d0) > abs(d1):
        ans[i] = S - 2 * abs(A[j] - A[i])
    # i, i - 1, i + 1の並び
    else:
        ans[i] = S - 2 * abs(d0)
print('\n'.join(str(x) for x in ans[1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.append(0)
for i in range(N):
    ans = 0
    tmp = 0
    for index, a in enumerate(A):
        if i != index:
            ans += abs(tmp-a)
            tmp = a
    print(ans)

Submission status: Time Limit Exceeded

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

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

for j in range(N):
  ans=cost
  if 0<j<N-1:
    ans -= abs(A[j]-A[j-1])
    ans -= abs(A[j+1]-A[j])
    ans += abs(A[j+1]-A[j-1])
  elif j==0:
    ans -= abs(A[0])
    ans -= abs(A[1]-A[0])
    ans += abs(A[1])
  else:
    ans -= abs(A[-1]-A[-2])
    ans -= abs(A[-1])
    ans += abs(A[-2])
  print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  pos=0
  cost=0
  for j in range(N):
    if j==i:
      pass
    else:
      #print(j,A[j])
      cost += abs(A[j]-pos)
      pos= A[j]
  if i==N-1:
    cost += abs(A[-2])
  else:
    cost += abs(A[-1])  
  print(cost)

Submission status: Time Limit Exceeded

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

for i in range(N):
  pos=0
  cost=0
  for j in range(N):
    if j==i:
      pass
    else:
      #print(j,A[j])
      cost += abs(A[j]-pos)
      pos= A[j]
  if i==N-1:
    cost += abs(A[-2])
  else:
    cost += abs(A[-1])  
  print(cost)

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

Submission status: Time Limit Exceeded

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

j = 1
sm = abs(A[1])
while j < N:
        sm += abs(A[j]-A[j+1])
        j += 1
print(sm)

for i in range(1,N):
    j = 0
    sm = abs(A[0])
    while j < N:
        if j+1 == i and j+2 < N+1:
            sm += abs(A[j]-A[j+2])
            j += 2
        else:
            sm += abs(A[j]-A[j+1])
            j += 1
    print(sm)

Submission status: Time Limit Exceeded

Solution code:
def cs(x):
    ans = 0
    for i in range(len(x)-1):
        ans += abs(x[i+1]-x[i])
    return ans


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

for i in range(1, len(a)-1):
    print(cs(a[:i] + a[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s= list(map(int,input().split()))
s.insert(0,0)
s.append(0)
for i in range(len(s)-2):
    tmp=s[:]
    del tmp[i+1]
    tmp_sum=0
    for i in range(len(tmp)-1):
        tmp_sum+=abs(tmp[i]-tmp[i+1])
    if i ==(len(tmp)-2):
        print(tmp_sum)

Submission status: Time Limit Exceeded

Solution code:
def main(n: int, a: list):
    for i in range(n):
        _a = a.copy()
        del (_a[i])
        _a.insert(0, 0)
        _a.append(0)

        _sum = 0

        for j in range(n):
            _sum += abs(_a[j] - _a[j + 1])

        print(_sum)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)

Submission status: Time Limit Exceeded

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

a.append(0)

for i in range(n):
    cost=0
    pv=0
    nx=0
    for j in range(len(a)):
        if i == j:
            continue
        pv, nx = nx, a[j]
        cost+=abs(pv-nx)

    print(cost)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

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

#print(a)


for i in range(1,len(a)-1):
    ans = 0
    for j in range(1,len(a)):
        if(j-1 != i and j != i):
            ans += abs(a[j]-a[j-1])
        elif(j == i):
            ans += abs(a[j+1]-a[j-1])
            j+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ARC093C - Traveling Plan
N = int(input())
A = list(map(int, input().rstrip().split()))
for i in range(N):
    ans = 0
    cur = 0
    for j in range(N):
        if i == j:
            continue
        ans += max(cur, A[j]) - min(cur, A[j])
        cur = A[j]
    print(ans + abs(cur))