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()))
X = max(A)
Y = min(A)
a = A.copy()
b = A.copy()
a.remove(X)
b.remove(Y)

for i in range(N):
    if X == A[i]:
        if max(a) < 0 and Y < 0:
            print(2 * abs(Y))
        elif max(a) > 0 and Y > 0:
            print(2 * max(a))
        else:
            print(abs(max(a) - Y) + abs(max(a)) + abs(Y))
    elif Y == A[i]:
        if X < 0 and min(b) < 0:
            print(2 * abs(min(b)))
        elif X > 0 and min(b) > 0:
            print(2 * X)
        else:
            print(abs(X - min(b)) + abs(X) + abs(min(b)))
    else:
        if X < 0 and Y < 0:
            print(2 * abs(Y))
        elif X > 0 and Y > 0:
            print(2 * X)
        else:
            print(abs(X - Y) + abs(X) + abs(Y))

Submission status: Wrong Answer

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

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

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]):
        ans = Sum
    elif A[i] > A[i-1]:
        ans = Sum - 2 * abs(A[i] - max(A[i-1], A[i+1]))
    else:
        ans = Sum - 2 * abs(A[i] - min(A[i-1], A[i+1]))
    print(ans)

Submission status: Wrong Answer

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

s = 0
p = 0
for i in range(N):
    s += abs(p - A[i])
    p = A[i]
if p != 0:
    s += abs(p)

A.append(0)
A.insert(0, 0)
for i in range(1, N+1):
    if A[i] < 0:
        if A[i] < A[i+1]:
            print(s - abs(A[i-1] - A[i])*2)
            continue
    else:
        if A[i] > A[i+1]:
            print(s - abs(A[i-1]-A[i])*2)
            continue
    print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
right=b[-1]
left=b[0]
for i in a:
  if i==right:
    print(max(b[-2],abs(left),b[-2]-left)*2)
  elif i==left:
    print(max(right,abs(right-b[1]),right-b[1])*2)
  else:
    print(max(right,abs(left),right-left)*2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
right=b[-1]
left=b[0]
for i in a:
  if a==right:
    print(max(b[-2],abs(left),b[-2]-left)*2)
  elif a==left:
    print(max(right,abs(right-b[1]),right-b[1])*2)

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = [0] + a + [0]
    diff = [abs(j - i) for i, j in zip(a, a[1:])]
    base = sum(diff)
    ans = [str(base - diff[i] - diff[i - 1] + abs(a[i + 2] - a[i])) for i in range(n)]
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = IR(2)
b = IR(2)
print(min(a)+min(b))
"""

#B
"""
n = I()
d, x = LI()
a = IR(n)
ans = x
for i in a:
    k = 0
    while k * i + 1 <= d:
        ans += 1
        k += 1
print(ans)
"""

#C
n = I()
a = LI()
a.insert(0, 0)
a.append(0)
ans = 0
for i in range(1, n + 2):
    ans += abs(a[i] - a[i - 1])
#print(ans)
for k in range(1, n + 1):
    if a[k - 1] < a[k]:
        if a[k] > a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)
    if a[k - 1] > a[k]:
        if a[k] < a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = IR(2)
b = IR(2)
print(min(a)+min(b))
"""

#B
"""
n = I()
d, x = LI()
a = IR(n)
ans = x
for i in a:
    k = 0
    while k * i + 1 <= d:
        ans += 1
        k += 1
print(ans)
"""

#C
n = I()
a = LI()
a.insert(0, 0)
a.append(0)
ans = 0
for i in range(1, n + 2):
    ans += abs(a[i] - a[i - 1])
print(ans)
for k in range(1, n + 1):
    if a[k - 1] < a[k]:
        if a[k] > a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)
    if a[k - 1] > a[k]:
        if a[k] < a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)

Submission status: Wrong Answer

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

print(A)

cost = 0
pos = 0
for p in range(0, len(A)):
    cost += abs(pos - A[p])
    pos = A[p]

for i in range(1, len(A)-1):
    n_cost = 0
    if A[i-1] <= A[i] and A[i] <= A[i + 1]:
        n_cost = cost
    elif A[i] <= A[i - 1] and A[i] <= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i] >= A[i - 1] and A[i] >= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i-1] >= A[i] and A[i] >= A[i + 1]:
        n_cost = cost

    print(n_cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
An = list(map(int,input().split()))
An.append(0)
dis = abs(An[0])
for i in range(N):
    dis += abs(An[i] - An[i+1] )
#print("dis:",dis)
for j in range(N):
    #print("j:",j)
    if j == 0:
        if (0 <= An[j] <= An[j + 1]) or (0 >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1] ) * 2)
    else:
        if (An[j-1] <= An[j] <= An[j + 1]) or (An[j-1] >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1]) - abs(An[j] - An[j - 1]) + abs(An[j - 1] - An[j + 1]) )

Submission status: Wrong Answer

Solution code:
N = int(input())
An = list(map(int,input().split()))
An.append(0)
dis = abs(An[0])
for i in range(N):
    dis += abs(An[i] - An[i+1] )
print("dis:",dis)
for j in range(N):
    #print("j:",j)
    if j == 0:
        if (0 <= An[j] <= An[j + 1]) or (0 >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1] ) * 2)
    else:
        if (An[j-1] <= An[j] <= An[j + 1]) or (An[j-1] >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1]) - abs(An[j] - An[j - 1]) + abs(An[j - 1] - An[j + 1]) )

Submission status: Wrong Answer

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

for i in range(N):
    print((max(a[:i] + a[i+1:] + [0]) - min(a[:i] + a[i+1:] + [0])) * 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==3:
  exit()
al=list(map(int,input().split()))
l1=[]
l2=[]
bl=[0]+al+[0]
for i in range(len(bl)-1):
  l1.append(abs(bl[i]-bl[i+1]))
  if i!=len(bl)-2:
    l2.append(abs(bl[i]-bl[i+2]))
for i in range(len(l2)):
  print(l2[i]+sum(l1[:i])+sum(l1[i+2:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(enumerate(map(int,input().split())),key=lambda x: x[1])

for i in range(N):
    if i == A[0][0]:
        l = A[1][1]
    else:
        l = A[0][1]
        
    if i == A[-1][0]:
        r = A[-2][1]
    else:
        r = A[-1][1]
        
    if r<0:
        print(-l*2)
    elif l<0 and 0<=r:
        print(-l*2+r*2)
    elif 0<=l:
        print(r*2)

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(1,len(A))]
sums=sum(diff)

for i in range(1,n+1):
  if i==n:
    print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
    exit()
  elif A[i]<=A[i+1] and ((A[i]>0 and A[i+1]<0) or (A[i]<0 and A[i+1]>0)):
    print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  elif A[i]<=A[i+1]:
    print(sums)
  else:
    print(sums-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())
x=[int(i) for i in input().split()]

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


if 0<=x[0]<=x[1] or x[1]<=x[0]<=0:
  print(dist)
elif 0<=x[1] and x[0]<=0:
  print(dist-2*abs(x[0]))
elif x[-1]<=0 and 0<=x[0]:
  print(dist-2*abs(x[0]))
else:
  print(dist-2*abs(x[0]-x[1]))
  

for i in range(1,n-1):
  if x[i-1]<=x[i]<=x[i+1] or x[i+1]<=x[i]<=x[i-1]:
    print(dist)
  else:
    print(dist-abs(x[i-1]-x[i])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1]))

if 0<=x[-1]<=x[-2] or x[-2]<=x[-1]<=0:
  print(dist)
elif 0<=x[-2] and x[-1]<=0:
  print(dist-2*abs(x[-1]))
elif x[-2]<=0 and 0<=x[-1]:
  print(dist-2*abs(x[-1]))
else:
  print(dist-2*abs(x[-1]-x[-2]))

Submission status: Wrong Answer

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

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


if 0<=x[0]<=x[1] or x[1]<=x[0]<=0:
  print(dist)
else:
  print(dist-2*abs(x[0]))

for i in range(1,n-1):
  if x[i-1]<=x[i]<=x[i+1] or x[i+1]<=x[i]<=x[i-1]:
    print(dist)
  else:
    print(dist-abs(x[i-1]-x[i])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1]))

if 0<=x[-1]<=x[-2] or x[-2]<=x[-1]<=0:
  print(dist)
elif 0<=x[-2] and x[-1]<=0:
  print(dist-2*abs(x[-1]))
elif x[-2]<=0 and 0<=x[-1]:
  print(dist-2*abs(x[-1]))
else:
  print(dist-2*abs(x[-1]-x[-2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

max_l = max(l)
min_l = min(l)

l_sort = sorted(l)


def lMax(v):
    return (lambda x: x*2 if x >= 0 else 0)(v)


def lMin(v):
    return (lambda x: -x*2 if x <= 0 else 0)(v)


for i in range(n):
    if l[i] == min_l:
        print(lMax(max_l) + lMin(l_sort[1]))
    elif l[i] == max_l:
        print(lMax(l_sort[n-2]) + lMin(min_l))
    else:
        print(lMax(max_l) + lMin(min_l))

Submission status: Wrong Answer

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

max_l = max(l) if max(l) >= 0 else 0
min_l = min(l) if min(l) <= 0 else 0

l_sort = sorted(l)

for i in range(n):
    if l[i] == min(l):
        cost = max(l)*2 + (lambda x: -x*2 if x <= 0 else 0)(l_sort[1])
    elif l[i] == max(l):
        cost = -min(l)*2 + (lambda x: x*2 if x >= 0 else 0)(l_sort[n-2])
    else:
        cost = -min_l*2 + max_l*2
    print(cost)

Submission status: Wrong Answer

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

for i in range(n):
    l_tmp = l_in.copy()
    l_tmp.remove(l_tmp[i])
    if max(l_tmp) <= 0:
        cost = -(min(l_tmp)*2)
    elif min(l_tmp) >= 0:
        cost = max(l_tmp)*2
    else:
        cost = max(l_tmp)*2 - min(l_tmp)*2
    print(cost)

Submission status: Wrong Answer

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

l = sorted(l_in)
max_l = l[n-1] if l[n-1] >= 0 else 0
min_l = l[0] if l[0] <= 0 else 0

cost = 0

for i in range(n):
    if l_in[i] == min_l:
        if l[1] >= 0:
            cost = abs(max_l*2)
        else:
            cost = abs(max_l*2)+abs(l[1]*2)
    elif l_in[i] == max_l:
        if l[n-2] <= 0:
            cost = abs(min_l*2)
        else:
            cost = abs(l[n-2]*2) + abs(min_l*2)
    else:
        cost = abs(max_l*2) + abs(min_l*2)

    print(cost)

Submission status: Wrong Answer

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

l = sorted(l_in)
max_l = l[n-1]
min_l = l[0]

cost = 0

for i in range(n):
    if l_in[i] == min_l:
        if l[1] >= 0:
            cost = abs(max_l*2)
        else:
            cost = abs(max_l*2)+abs(l[1]*2)
    elif l_in[i] == max_l:
        if l[n-2] <= 0:
            cost = abs(min_l*2)
        else:
            cost = abs(l[n-2]*2) + abs(min_l*2)
    else:
        cost = abs(max_l*2) + abs(min_l*2)

    print(cost)

Submission status: Wrong Answer

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

for i in range(N):
    li = copy.deepcopy(A_list)
    del li[i]
    ans = abs(li[0] + li[N-2])
    for m in range(N-2):
        ans += abs(li[m] - li[m+1])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = [0] * n
summ = sum([abs(a[i]-a[i+1]) for i in range(n-1)])
summ += abs(a[0]) + abs(a[-1])
for i in range(1, n-1):
  ans[i] = summ -abs(a[i-1]-a[i])-abs(a[i+1]-a[i])+abs(a[i-1]-a[i+1])
ans[0] = summ - abs(a[0]) -abs(a[0]-a[1]) + abs(a[1])
ans[-1] = summ - abs(a[-1]) -abs(a[-1]-a[-2])+abs(a[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
  if i == 0:
    b.append(abs(a[i]))
  if i == n - 1:
    b.append(abs(a[i]))
  else:
    b.append(abs(a[i] - a[i - 1]))
  

sd = sum(b)

for j in range(n):
  if j == 0:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1]))
  if j == n - 1:
    print(sd - b[j + 1] - b[j] + abs(a[j]))
  else:
    print(sd - b[j] - b[j + 1] + abs(a[j + 1] - a[j - 1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
ans=0
for i in range(n+1):
    ans+=abs(a[i]-a[i+1])
for i in range(1,n+1):
    print(ans-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 = list(map(int,input().split()))
a = [0] + a +[0]
s = 0

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

for j in range(1,n):
    print(s-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 = list(map(int,input().split()))
a = [0] + a +[0]
s = 0

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

for j in range(1,n+1):
    print(s-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

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()
B = [abs(0 - A[0])]
for i in range(1, N):
    B.append(abs(A[i - 1] - A[i]))
else:
    B.append(abs(A[-1] - 0))

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()
B = [abs(0 - A[0])]
for i in range(1, N):
    B.append(abs(A[i - 1] - A[i]))
else:
    B.append(abs(A[-1] - 0))

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

Submission status: Wrong Answer

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

c=0
for i in range(n):
    if i==0 or i==n-1:
        c+=abs(A[i])
    else:
        c+=abs(A[i+1]-A[i])

for i in range(n):
    if i==0:
        if 0 <= A[i] <= A[i+1]:
            print(c)
            continue
        else:
            print(c-abs(A[i]*2))
            continue
    elif i==n-1:
        if A[i-1] <= A[i] <= 0:
            print(c)
            continue
        else:
            print(c-abs(A[i]*2))
            continue
    else:
        if A[i-1] <= A[i] <= A[i+1]:
            print(c)
            continue
        else:
            print(c-abs(A[i]*2))
            continue

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
s1 = 0
s2 = 0
s3 = 0
ma = max(A)
mi = min(A)

A1 = [0] + A + [0]
for i in range(len(A1)-1):
    s1 += abs(A1[i] - A1[i+1])

A2 = A[:]
A2.pop(A2.index(ma))
A2 = [0] + A2 + [0]
for i in range(len(A2)-1):
    s2 += abs(A2[i] - A2[i+1])

A3 = A[:]
A3.pop(A3.index(mi))
A3 = [0] + A3 + [0]
for i in range(len(A3)-1):
    s3 += abs(A3[i] - A3[i+1])

for a in A:
    if a == ma:
        print(s2)
    elif a == mi:
        print(s3)
    else:
        print(s1)

Submission status: Wrong Answer

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

amounts = [0] * N

for n in range(N):
    spot = A[:n] + A[(n+1):]
    print(*spot)

    amount = 0
    for i in range(1, N - 1):
        amount += abs(spot[i-1] - spot[i])
    amount += abs(spot[0])
    amount += abs(spot[N - 2])
    amounts[n] = amount

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

Submission status: Wrong Answer

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

s=[]
for i in a:
    s.append(i)
s.sort()
n=s[0]
m=s[-1]


for i in a:
    if n==i:
        n=s[1]
    if m==i:
        m=s[-2]
    
    if n*m>=0:
        if n>=0:
            print(2*m)
        else:
            print((-2)*n)
    else:
        print(2*(m-n))
    
    n=s[0]
    m=s[-1]

Submission status: Wrong Answer

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

b = max(a)
c = min(a)

aa =sorted(a)
bb = aa[-2]
cc = aa[1]

for i in range(n):
    if a[i] != b and a[i] != c:
        print(abs(max(b, 0) - min(c, 0)) * 2)
    elif a[i] ==b:
        print(abs(max(bb, 0) - min(c, 0)) * 2)
    else:
        print(abs(max(b, 0) - min(cc, 0)) * 2)

Submission status: Wrong Answer

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

A = [0] + A + [0]

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

print(allcost)

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)

Submission status: Wrong Answer

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

def cost_f(a,b):
  if a <= 0 <= b:
    return (abs(a) + b) * 2
  elif a > 0 and b > 0:
    return b * 2
  elif a < 0 and b < 0:
    return a * 2
  else:
    return 0

for _a in a:
  if _a == a_sort[n-1]:
    cost = cost_f(a_sort[0], a_sort[n - 2])
  elif _a == a_sort[0]:
    cost = cost_f(a_sort[1], a_sort[n - 1])
  else:
    cost = cost_f(a_sort[0], a_sort[n - 1])
  print(cost)

Submission status: Wrong Answer

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

all = 0
last = 0
diff = []

for i in range(N):
  all += abs(A[i] - last)
  diff.append(abs(A[i+1] - last) - abs(A[i+1] - A[i]) - abs(A[i] - last))
  last = A[i]

for i in range(N):
  print(all + diff[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
min1 = 0
min2 = 0
max1 = 0
max2 = 0
 
for a in A:
  if(a <= min1):
    min2 = min1
    min1 = a
  elif(a >= max1):
    max2 = max1
    max1 = a
 
for a in A:
  if(a == min1):
    print(2*(max1 - min2))
  elif(a == max1):
    print(2*(max2 - min1))
  else:
    print(2*(max1 - min1))

Submission status: Wrong Answer

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

min1 = 0
min2 = 0
max1 = 0
max2 = 0

for a in A:
  if(a <= min1):
    min2 = min1
    min1 = a
  elif(a >= max1):
    max2 = max1
    max1 = a

for a in A:
  if(a == min1):
    print(max1 - min2)
  elif(a == max1):
    print(max2 - min1)
  else:
    print(max1 - min1)

Submission status: Wrong Answer

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

# calc dif
a_zero = [0,] + a + [0,]
a_d = []

for i in range(1, N + 2) :
    a_d.append(abs(a_zero[i] - a_zero[i - 1]))
    
a_d_sum = sum(a_d)

for i in range(N) :
    if i == N - 1 :
        if a[i] >= a[i - 1] :
            print(a_d_sum)
        else :
            print(a_d_sum - a_d[i] * 2)
    else :
        if abs(a[i]) <= abs(a[i + 1]) and ((a[i] >= 0 and a[i + 1] >= 0) or (a[i] < 0 and a[i + 1] < 0)):
            print(a_d_sum)
        else :
            print(a_d_sum - a_d[i] * 2)

Submission status: Wrong Answer

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

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

print(total)

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

Submission status: Wrong Answer

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

for i in range(N):
    sum = 0
    b = a[:i]+a[i+1:]
    for j in range(N-1):
        if j ==0:
            sum+=abs(b[j]-0)
        elif j ==N-2:
            sum+=abs(2*b[j]-b[j-1])
        else:
            sum+=abs(b[j]-b[j-1])
    print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.append(0)
cost=[]
for i in range(N+1):
    if i==0:
        cost.append(abs(a[i]))
    else:
        cost.append(abs(a[i-1]-a[i]))
cost.append(abs(a[N]))
print(cost)
S=sum(cost)
for i in range(N):
    print(S-cost[i+1]-cost[i+2]+abs(a[i+2]-a[i]))

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)

a = input().split(" ")
m = list()
for index, x in enumerate(a):
	l = a[:]
	del l[index]
	m.append(l)


for line in m:
	cost = 0
	for index, x in enumerate(line):
		x = int(x)
		if index == 0:
			cost += abs(0 - int(line[index]))
		elif index == (len(line) - 1):
			cost += abs(int(line[index]))
		else:
			cost += abs(int(line[index]) - int(line[index + 1]))
	print(cost)

Submission status: Wrong Answer

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

S = [abs(A[i]-A[i+1]) for i in range(N+1)]
sumS = sum(S)
for i in range(N):
    cost = sumS + abs(S[i-1]-S[i+1]) - (abs(S[i-1]-S[i])+abs(S[i]-S[i+1]))
    print(cost)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

sumA = [0 for i in range(N+1)]

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split(" ")))
for i in range (1 , n + 1):
    current = a[:]
    current.pop(i-1)
    money = abs(0 - current[0])
    if 2 < n:
        for j in range (1,len(current)):
            money = abs(current[ j - 1] - current[j]) + money
        money = money + abs(current[len(current) - 1])
    print(money)

Submission status: Wrong Answer

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

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

dist_sum = sum(distance)

print(dist_sum - distance[0] + abs(A[1]) + abs(A[-1]))

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]):
        result = dist_sum + abs(A[-1]) + abs(A[0])
    
    else:
        result = dist_sum + abs(A[-1]) + abs(A[0]) - 2*abs(A[i-1] - A[i])
    
    print(result)

print(dist_sum  - distance[-1] + abs(A[-2]) + abs(A[0]))

Submission status: Wrong Answer

Solution code:

N=int(input())

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

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


for k in range(1,N+1):
    mae=A[k-1]
    usiro=A[k+1]
    if abs(mae)<= abs(A[k])<=abs(usiro):
        print(tujyo)
    else:
        print(tujyo-abs(A[k]-mae)-abs(usiro-A[k])+abs(usiro-mae))

Submission status: Wrong Answer

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

if n == 2:
    print(abs(a[0]) + abs(a[0]-a[1]) + abs(a[1]))
else:
    for i in range(len(a)):
        b = a[:]
        b.remove(b[i])
        #print(b)
        cost = abs(b[0])
        for j in range(len(b)-1):
            #print(b[j],b[j+1])
            cost += abs(b[j] - b[j+1])
        cost += abs(b[-1])
        print(cost)