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()))
whole=0
for n in range(N-1):
    whole+=abs(A[n]-A[n+1])
whole+=abs(A[0])+abs(A[-1])
answers=[]
for n in range(1,N-1):
    if A[n-1]>A[n] and A[n]>A[n+1]:
        answers.append(whole)
    elif A[n-1]<A[n] and A[n]<A[n+1]:
        answers.append(whole)
    elif A[n]>A[n-1] and A[n-1]>A[n+1]:
        answers.append(whole-2*abs(A[n]-A[n-1]))
    elif A[n+1]>A[n-1] and A[n-1]>A[n]:
        answers.append(whole-2*abs(A[n]-A[n-1]))
    elif A[n-1]<A[n+1] and A[n+1]<A[n]:
        answers.append(whole-2*abs(A[n]-A[n+1]))
    elif A[n-1]>A[n+1] and A[n+1]>A[n]:
        answers.append(whole-2*abs(A[n]-A[n+1]))
    else:
        answers.append(whole)
start=A[1:]
ans_s=0
for n in range(N-2):
    ans_s+=abs(start[n]-start[n+1])
ans_s+=abs(start[0])+abs(start[-1])
print(ans_s)
for ans in answers:
    print(ans)
last=A[:-1]
ans_l=0
for n in range(N-2):
    ans_l+=abs(last[n]-last[n+1])
ans_l+=abs(last[0])+abs(last[-1])
print(ans_l)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

money = 0

last = 0
for a in A:
    money += abs(last - a)
    last = a
money += abs(last)

for i in range(N):
    if i == 0:
        t1 = A[i]
        t2 = A[i + 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    elif i == N - 1:
        t1 = A[i]
        t2 = A[i - 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    else:
        t1 = A[i + 1] - A[i]
        t2 = A[i] - A[i - 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t2) * 2)
        else:
            print(money)

Submission status: Wrong Answer

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

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

for k in anslist:
    print(k)

Submission status: Wrong Answer

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

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

for k in anslist:
    print(k)

Submission status: Wrong Answer

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

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

for k in anslist:
    print(k)

Submission status: Wrong Answer

Solution code:

n = int(input())
a = list(map(int,input().split()))
ans = 0
anslist = [0] * n
for j in range(n + 1):
    if j == 0:
        ans += abs(a[0])
    elif j == n:
        ans += abs(a[n - 1])
    else:
        ans += abs(a[j]-a[j - 1])

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

for k in anslist:
    print(str(k))

Submission status: Wrong Answer

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

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

for k in anslist:
    print(str(k))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
a = list(map(int,input().split()))
ans = [0] * n
print(ans)
for i in range(n):
    ac = copy.copy(a)
    del ac[i]
    for j in range(n):
        if j == 0:
            ans[i] += abs(ac[0])
        elif j == n - 1:
            ans[i] += abs(ac[n - 2])
        else:
            ans[i] += abs(ac[j]-ac[j - 1])

for k in ans:
    print(str(k))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(0)
whole=0
numbers=[]
for n in range(N+1):
    whole+=abs(A[n+1]-A[n])
for n in range(N-1):
    if A[n]<=A[n+1] and A[n+1]<=A[n+2]:
        numbers.append(0)
    elif A[n]>=A[n+1] and A[n+1]>=A[n+2]:
        numbers.append(0)
    else:
        numbers.append(abs(A[n]-A[n+1])*2)
for number in numbers:
    print(whole-number)
answer=0
del A[-2]
for n in range(N):
    answer+=abs(A[n+1]-A[n])
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
b = sorted(a)
a_max = b[-1]
a_min = b[0]

cost = 0
for i in range(n+1):
  cost += abs(a[i+1]-a[i])
  
for i in range(1,n+1):
  if a[i]==a_max:
    print(cost - 2*(b[-1]-b[-2]))
  elif a[i]==a_min:
    print(cost - 2*(abs(b[0])-abs(b[1])))
  else:
    print(cost)

Submission status: Wrong Answer

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

s = 0

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
print(L)
LL = sorted(L)

posi = [x for x in L if x > 0]
nega = [x for x in L if x < 0]

max_posi,max_nega,sec_posi,sec_nega = 0,0,0,0
if len(posi) >=2:
    max_posi = LL[-1]
    sec_posi = LL[-2]
if len(posi) == 1:
    max_posi = LL[-1]
if len(nega) >=2:
    max_nega = LL[0]
    sec_nega = LL[1]
if len(nega) == 1:
    max_nega = LL[0]

if max_posi and max_nega:    
    sum1 = max_posi*2 + abs(max_nega)*2
elif max_posi and not max_nega:
    sum1 = max_posi*2
elif not max_posi and max_nega:
    sum1 = abs(max_nega)*2

print(max_posi,sec_posi,max_nega,sec_nega,sum1)    

for i in range(n):
    if max_posi and max_nega:
        if L[i] != max_posi and L[i] != max_nega:
            print(sum1)
        elif L[i] == max_posi:
            if sec_posi:
                print(sec_posi*2 + abs(max_nega)*2)
            else:
                print(abs(max_nega)*2)
        elif L[i] == max_nega:
            if sec_nega:
                print(abs(sec_nega)*2 + max_posi*2)
            else:
                print(max_posi*2)
    else:
        if max_posi:
            if L[i] == max_posi:
                if sec_posi:
                    print(sec_posi*2)
                else:
                    print(abs(max_posi)*2)
            else:
                print(sum1)
        elif max_nega:
            if L[i] == max_nega:
                if sec_nega:
                    print(abs(sec_nega)*2)
                else:
                    print(abs(max_nega)*2)

Submission status: Wrong Answer

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

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,a):
  tripCourse = [0] + a + [0]
  wholeSum = sum(abs(tripCourse[i+1] - tripCourse[i]) for i in range(n+1))
  res = [wholeSum]*n
  for i in range(n):
    if tripCourse[i+1] == 0:
      continue
    elif tripCourse[i+1] > max(tripCourse[i+2],tripCourse[i]) or tripCourse[i+1] < min(tripCourse[i],tripCourse[i+2]):
      res[i] -= abs(tripCourse[i+1] - tripCourse[i+2]) + abs(tripCourse[i] - tripCourse[i+1]) - abs(tripCourse[i+2]-tripCourse[i])
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  ans = solve(N,a)
  for i in range(N):
    print(ans[i])
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,a):
  tripCourse = [0] + a + [0]
  wholeSum = sum(abs(tripCourse[i+1] - tripCourse[i]) for i in range(n+1))
  res = [wholeSum]*n
  for i in range(n):
    if tripCourse[i+1] == 0:
      continue
    elif tripCourse[i+1] > max(tripCourse[i],tripCourse[i-1]) or tripCourse[i+1] < min(tripCourse[i],tripCourse[i+2]):
      res[i] -= abs(tripCourse[i+1] - tripCourse[i+2]) + abs(tripCourse[i] - tripCourse[i+1]) - abs(tripCourse[i+2]-tripCourse[i])
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  ans = solve(N,a)
  for i in range(N):
    print(ans[i])
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
now = 0
dis = 0
for i in A:
    dis += abs(now-i)
    now = i
ans = dis+abs(now)
B = [0]
B.extend(A)
B.append(0)
print(B)
for i in range(1,N+1):
    if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:
        print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
for i in range(1,N+1):
    if i==1:
        print(tot-abs(A[1])-abs(A[2]-A[1])+A[2])
    elif i==N:
        print(tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1]))
    else:
        print(tot-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:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
        
def main():
    plan=[0]
    n = int(input())
    plan+=list(map(int,input().split()))
    plan.append(0)
    pay_sum = 0
    for i in range(1,n+2):
        pay_sum += abs(plan[i] - plan[i-1])
    
    for i in range(1,n+1):
        result = abs(plan[i-1] - plan[i+1])
        result -= abs(plan[i-1] - plan[i])
        result -= abs(plan[i+1] - plan[i])
        print(pay_sum - result)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    A = [0] + A + [0] ## append start and goal (1-indexed table)
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for i in range(1,n+1):
        _sum += abs(prev - A[i])
        prev = A[i]
        diff[i-1] = abs(A[i-1] - A[i+1]) - (abs(A[i]-A[i-1]) + abs(A[i+1] - A[i]))
    ## add the cost until goal.
    _sum += abs(A[n])
    print(A)
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    A = [0] + A + [0] ## append start and goal (1-indexed table)
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for i in range(1,n):
        _sum += abs(prev - A[i])
        prev = A[i]
        diff[i-1] = abs(A[i-1] - A[i+1]) - (abs(A[i]-A[i-1]) + abs(A[i+1] - A[i]))
    ## add the cost until goal.
    _sum += abs(A[i] - A[i+1])
    
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if min(A[-2],0) <=  A[N-1] <= max(A[-2], 0):
    print(S)
elif A[N-1] < min(A[-2],0):
    print(S+2*(A[N-1] - min(A[-2],0)))
elif max(A[-2], 0) < A[N-1]:
    print(S+2*(max(A[-2], 0) - A[N-1]))

Submission status: Wrong Answer

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

all_price = 0
now = 0
for i in range(N + 1):
    if (i == N):
        all_price += abs(A[i - 1])
        break
    all_price += abs(A[i] - now)
    now = A[i]


for i in range(N):
    if (i == 0):
        if (A[i] >= 0 and A[i] <= A[i + 1]):
            print(all_price)
            continue
        elif (A[i] < 0 and A[i] <= A[i + 1]):
            print(all_price - abs(A[i]) * 2)
            continue
        elif (A[i] >= 0 and A[i] > A[i + 1]):
            print(all_price - abs(A[i] - A[i + 1]) * 2)
            continue
        elif (A[i] < 0 and A[i] > A[i + 1]):
            print(all_price)
            continue

    elif (i == N - 1):
        if (A[i - 1] > A[i] and A[i] >= 0):
            print(all_price)
            break
        elif (A[i - 1] > A[i] and A[i] < 0 and A[i - 1] < 0):
            print(all_price - abs(A[i] - A[i - 1]) * 2)
            break
        elif (A[i - 1] > A[i] and A[i] < 0 and A[i - 1] >= 0):
            print(all_price - abs(A[i]) * 2)
        elif (A[i - 1] <= A[i] and A[i] >= 0):
            print(all_price - abs(A[i] - A[i - 1]))
            break
        elif (A[i - 1] <= A[i] and A[i] < 0):
            print(all_price)
            break

    else:
        if (A[i - 1] >= A[i] and A[i] >= A[i + 1]):
            print(all_price)
        elif (A[i - 1] >= A[i] and A[i] < A[i + 1]):
            print(all_price - abs(A[i] - A[i - 1]) * 2)
        elif (A[i - 1] < A[i] and A[i] >= A[i + 1] and A[i - 1] >= A[i + 1]):
            print(all_price - 2 * abs(A[i] - A[i - 1]))
        elif (A[i - 1] < A[i] and A[i] >= A[i + 1] and A[i - 1] < A[i + 1]):
            print(all_price - 2 * abs(A[i] - A[i + 1]))
        elif (A[i - 1] < A[i] and A[i] < A[i + 1]):
            print(all_price)

Submission status: Wrong Answer

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

money = [0]
for i in range(n+1):
    money.append(abs(a[i]-a[i+1]))
print(money)
ans = sum(money)
for i in range(n):
    print(ans - sum(money[i+1:i+3]) + abs(a[i]-a[i+2]))

Submission status: Wrong Answer

Solution code:
import itertools

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

acc = []
prev = 0
for a in A:
  t = abs(a - prev)
  acc.append(t)
  prev = a
  

ans = []
for i in range(N):
  t = 0
  if 0 < i:
    t += acc[i-1]
  
  if i < N-1:
    t += acc[N-1] - acc[i]
    
  ans.append(t)
  
print("\n".join(map(str,ans)))

Submission status: Wrong Answer

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

S = sum(dis)
print(S)
for i in range(1, n+1):
    A = a[i-1]
    B = a[i]
    C = a[i+1]
    if A > C:
        A, C = C, A
    if A<=B<=C:
        print(S)
    else:
        print(S-2*min(abs(A-B), abs(C-B)))

Submission status: Wrong Answer

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

b=a+[0]

c= sorted(b)
d_max = max(b)
d_min = min(b)

ans=0

for i in range(n):
    if a[i]==d_max:
        ans = abs(c[n-1])*2 + abs(d_min)*2
    elif a[i]==d_min:
        ans = abs(d_max)*2 + abs(c[1])*2
    else:
        ans = abs(d_max)*2 + abs(d_min)*2

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

diff = np.diff(A)

rev = [x < 0 for x in diff]

is_true = []
for i in range(len(rev) - 1):
    is_true.append(rev[i] & rev[i + 1])

whole = np.abs(diff).sum()

result = []
for i in range(N):
    if is_true[i]:
        result.append(whole)
    else:
        result.append(whole - np.abs(diff)[i] * 2)

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

Submission status: Wrong Answer

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

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

for i in range(1,n+1):
  sa=0
  if a[i+1]<a[i-1]<a[i]:
    sa=(a[i-1]-a[i+1])-(a[i]-a[i-1])-(a[i]-a[i+1])
  elif a[i]<a[i-1]<a[i+1]:
    sa=(a[i+1]-a[i-1])-(a[i-1]-a[i])-(a[i+1]-a[i])
  print(sum+sa)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline

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

d=[0]*(n+1)
d[1]=abs(s[0])
for i in range(2,n+1):
    d[i]=d[i-1]+abs(s[i-1]-s[i-2])
ans=abs(s[n-1])+d[n]-d[2]+d[0]+s[1]
print(ans)
for i in range(1,n-1):
    ans=abs(s[n-1])+d[i]+d[n]-d[i+2]+abs(s[i+1]-s[i-1])
    print(ans)
ans=d[n-1]+abs(s[n-2])
print(ans)

Submission status: Wrong Answer

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

maxA = max(a)
minA = min(a)

totalCost = abs(a[-1]) + abs(a[0])
l = []

for i in range(n-1):
    totalCost += abs(a[i] - a[i+1])
    if i != 0:
        if (a[i-1] < a[i] and a[i] > a[i+1]) or (a[i-1] > a[i] and a[i] < a[i+1]):
            l.append(a[i])

# print(l)
# print(totalCost)
# print("-----")

for i in range(n):
    if i == n-1:
        if a[i] < 0 and 0 < a[i-1]:
            # print("bbb")
            ans = totalCost - abs(a[i])*2

        elif a[i] > 0 and 0 > a[i-1]:
            # print("ddd")
            ans = totalCost - abs(a[i])*2

        elif a[i] < 0 and a[i] < a[i-1]:
            # print("aaa")
            ans = totalCost - abs(a[i]- a[i-1])*2
        
        elif a[i] > 0 and a[i-1] < a[i]:
            # print("ccc")
            ans = totalCost - abs(a[i]- a[i-1])*2
        else:
            ans = totalCost
        
    elif a[i] in l:
        ans = totalCost - abs(a[i-1] - a[i])*2
    else:
        ans = totalCost
    print(ans)

Submission status: Wrong Answer

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

maxA = max(a)
minA = min(a)

totalCost = abs(a[-1]) + abs(a[0])
l = []

for i in range(n-1):
    totalCost += abs(a[i] - a[i+1])
    if i != 0:
        if (a[i-1] < a[i] and a[i] > a[i+1]) or (a[i-1] > a[i] and a[i] < a[i+1]):
            l.append(a[i])

# print(l)
# print(totalCost)
# print("-----")

for i in range(n):
    if a[i] in l:
        ans = totalCost - abs(a[i-1] - a[i])*2
    else:
        ans = totalCost
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

d_sum = abs(A[0])+abs(A[-1])
for i in range(1, n):
    d_sum += abs(A[i-1]-A[i])

print(d_sum-abs(A[0])-abs(A[0]-A[1])+abs(A[1]))
for i in range(1, n-1):
    print(d_sum - abs(A[i-1]- A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1]-A[i+1]))
print(d_sum-abs(A[-1]-abs(A[-1]-A[-2])+abs(A[-2])))

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]<=0 and a[i+1]>=0 or  a[i]<=0 and a[i+1]>=0:
   print(cnt-2*abs(a[i]-a[i+1]))
  else:
   print(cnt)
 elif i<=n-2: #ok
  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(cnt)
  elif a[i]>=a[i-1]>=a[i+1] or a[i+1]>=a[i-1]>=a[i]:
   print(cnt-2*abs(a[i]-a[i-1]))
  elif a[i]>=a[i+1]>=a[i-1] or a[i-1]>=a[i+1]>=a[i]:
   print(cnt-2*(abs(a[i]-a[i+1])))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<a[i-1]:#ok
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  elif a[i]>=0 and a[i-1]>=0 and a[i-1]>a[i] or a[i]<=0 and a[i-1]<=0 and a[i]>a[i-1]:#ok
   print(cnt)
  else:
   print(cnt-2*abs(a[i]))

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]<=0 and a[i+1]>=0 or  a[i]<=0 and a[i+1]>=0:
   print(cnt-2*abs(a[i]-a[i+1]))
  else:
   print(cnt)
 elif i<=n-2:
  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(cnt)
  elif a[i]>=a[i-1]>=a[i+1] or a[i+1]>=a[i-1]>=a[i]:
   print(cnt-2*abs(a[i]-a[i-1]))
  elif a[i]>=a[i+1]>=a[i-1] or a[i-1]>=a[i+1]>=a[i]:
   print(cnt-2*(abs(a[i]-a[i+1])))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<a[i-1]:
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  elif a[i]>=0 and a[i-1]>=0 and a[i-1]>a[i] or a[i]<=0 and a[i-1]<=0 and a[i]>a[i-1]:
   print(cnt)
  else:
   print(cnt+abs(a[i-1])-abs(a[i])-abs(a[i]-a[i-1]))

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]<=0 and a[i+1]>=0 or  a[i]<=0 and a[i+1]>=0:
   print(cnt-2*abs(a[i]-a[i+1]))
  else:
   print(cnt)
 elif i<=n-2:
  if a[i]>=0 and a[i+1]>=0 and a[i+1]>a[i] or a[i]<=0 and a[i+1]<=0 and a[i]>a[i+1]:
   print(cnt)
  else:
   print(cnt-2*abs(a[i]-a[i-1]))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<a[i-1]:
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  elif a[i]>=0 and a[i-1]>=0 and a[i-1]>a[i] or a[i]<=0 and a[i-1]<=0 and a[i]>a[i-1]:
   print(cnt)
  else:
   print(cnt+abs(a[i-1])-abs(a[i])-abs(a[i]-a[i-1]))

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]<=0 and a[i+1]>=0 or  a[i]<=0 and a[i+1]>=0:
   print(cnt-2*abs(a[i]-a[i+1]))
  else:
   print(cnt)
 elif i<=n-2:
  if a[i]>=0 and a[i+1]>=0 and a[i+1]>a[i] or a[i]<=0 and a[i+1]<=0 and a[i]>a[i+1]:
   print(cnt)
  else:
   print(cnt-2*abs(a[i]-a[i-1]))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<a[i-1]:
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  else:
   print(cnt+abs(a[i-1])-abs(a[i])-abs(a[i]-a[i-1]))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[a[0]]
    ans=abs(a[0])
    for i in range(n-1):
        b.append(a[i+1]-a[i])
        ans+=abs(a[i+1]-a[i])
    b.append(-1*a[n-1])
    ans+=abs(a[n-1])
    for i in range(n):
        if b[i]*b[i+1]>=0:
            print(ans)
        else:
            print(ans-b[i]-b[i+1]+abs(b[i]+b[i+1]))
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]
A = A + list(map(int, input().split()))
A.append(0)
print(A)
sumOfRoute = 0
tmp = 0
for a in A:
    sumOfRoute += abs(tmp-a)
    tmp = a

prev = 0
for i in range(1, N+1):
    nexti = A[i+1]
    print(sumOfRoute + abs(prev - nexti) - abs(A[i] - nexti) - abs(prev - A[i]))
    prev = A[i]

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.append(0)
A.insert(0,0)
A_sort = sorted(A)
S = (abs(A_sort[0] - A_sort[-1]))*2
for i in range(len(A)):
    if i == 0 or i == len(A)-1:
        pass
    else:
        print (S + abs(A[i-1]-A[i+1]) - (abs(A[i-1]-A[i]) + abs(A[i]-A[i+1])))