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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0] + list(map(int, input().split()))
s.append(0)
res = []
dif = []
for a, b in zip(s, s[1:]):
    dif.append(a - b)
    res.append(abs(a - b))
sres = sum(res)
# print(dif, res, sres)
for i in range(n):
    if dif[i] * dif[i + 1] >= 0:
        print(sres)
    else:
        if i != n - 1:
            y = abs(dif[i])
            print(sres - 2 * y)
        elif dif[i - 1] * dif[i] < 0:
            y = abs(dif[-1])
            print(sres - 2 * y)
        else:
            y = abs(dif[i])
            print(sres - 2 * y)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split(' ')
kaku_kyori=[]
for i in range(len(a)):
  kaku_kyori.append(int(a[i]))
for i in range(len(kaku_kyori)):
    nozoita=kaku_kyori[0:i]+kaku_kyori[i+1:len(kaku_kyori)]
    if max(nozoita)>0 and min(nozoita)>=0:
      print(max(nozoita)*2)
    elif max(nozoita)<0 and min(nozoita)<=0:
      print((0-min(nozoita))*2)
    elif max(nozoita)>0 and min(nozoita)<=0:
      print((0 - min(nozoita)) * 2 + max(nozoita) * 2)

Submission status: Wrong Answer

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

prev = 0

for i in arr:
    if i == 0: break
    res = 0
    for j in arr:
        if i == j:
            continue
        else:
            dest = j
            res += abs(prev - dest)
            prev = dest
    print(res)

Submission status: Wrong Answer

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

max_fee = 0
for i in range(1, n + 2):
    max_fee += abs(a[i] - a[i - 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]:
        print(max_fee)
    else:
        res = max_fee - abs(a[i] - a[i - 1]) * 2
        if i == n:
            res = max_fee - min(abs(a[i]) * 2, abs(a[i] - a[i - 1]) * 2)
        print(res)

Submission status: Wrong Answer

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

b=sorted(a)

for i in a:
    if i==b[0]:
        x=b[1:]
    elif i==b[-1]:
        x=b[:-1]
    else:
        x=b

    ans=0

    if x[0]<0:
        ans+=x[0]*(-2)

    if x[-1]>0:
        ans+=x[-1]*2

    print(ans)

Submission status: Wrong Answer

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

l=b[0]
r=b[-1]

for i in a:
  if i!=l and i!=r:
    if l<0:
      print((r-l)*2)
      
    else:
      print(r*2)
      
  elif i==l:
    l=b[1]
    if l<0:
      print((r-l)*2)
      l=b[0]
      
    else:
      print(r*2)
      l=b[0]
      
  elif i==r:
    r=b[-2]
    if l<0:
      print((r-l)*2)
      r=b[-1]
      
    else:
      print(r*2)
      r=b[-1]

Submission status: Wrong Answer

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

l=b[0]
r=b[-1]

for i in a:
  if i!=l and i!=r:
    if l<0:
      print((r-l)*2)
      
    else:
      print(r*2)
      
  elif i==l:
    l=b[1]
    if l<0:
      print((r-l)*2)
      
    else:
      print(r*2)
      
  elif i==r:
    r=b[-2]
    if l<0:
      print((r-l)*2)
      
    else:
      print(r*2)

Submission status: Wrong Answer

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

    total = 0
    mae = 0

    for i in range(n):
        total += abs(inlis[i] - mae)
        mae = inlis[i]
    total += abs(inlis[-1])
    inlis.append(0)

    #i = 0
    if inlis[0] >= 0 and inlis[1] >= inlis[0]:
        print(total)
    elif inlis[0] <= 0 and inlis[1] <= inlis[0]:
        print(total)
    else:
        print(total - 2 * abs(inlis[0]))

    for j in range(1, n):
        if inlis[j-1] <= inlis[j] <= inlis[j+1] or inlis[j-1]>= inlis[j] >= inlis[j+1]:
            print(total)
        elif inlis[j-1] <= inlis[j] and inlis[j] > inlis[j+1]:
            if inlis[j-1] >= inlis[j+1]:
                print(total - 2 * abs(inlis[j-1] - inlis[j]))
            else:
                print(total- 2 * abs(inlis[j+1] - inlis[j]))
        elif inlis[j-1]>= inlis[j] and inlis[j] < inlis[j+1]:
            if inlis[j-1] >= inlis[j+1]:
                print(total - 2 * abs(inlis[j+1] - inlis[j]))
            else:
                print(total - 2 * abs(inlis[j-1] - inlis[j]))
    



        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]+[int(X) for X in input().split()]+[0]
Cost = [abs(A[T+1]-A[T]) for T in range(N+1)]
Total = sum(Cost)
for T in range(0,N):
    if A[T]<A[T+2]<A[T+1] or A[T+1]<A[T+2]<A[T]:
        print(Total-2*Cost[T+1])
    elif A[T+1]<A[T]<A[T+2] or A[T+2]<A[T]<A[T+1]:      
        print(Total-2*Cost[T])
    else:
        print(Total)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    cost = 0
    pre = 0
    for a in A[1:]:
        cost += abs(a - pre)
        pre = a
    print(cost)

    for i, a in enumerate(A):
        if i == 0 or i == N + 1: continue
        print(cost - abs(a - A[i - 1]) - abs(a - A[i + 1]) + abs(A[i + 1] - A[i - 1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

    for n in range(1, N + 1):
        if n == N:
            print(sm - (abs(A[n] - A[n - 1]) + abs(A[n])) + abs(A[n - 1]))
        elif A[n + 1] <= 0 < A[n] or A[n] < 0 <= A[n + 1]:
            print(sm - (abs(A[n] - A[n - 1]) + abs(A[n] - A[n + 1])) + abs(A[n - 1] - A[n + 1]))
        else:
            print(sm)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

    for n in range(1, N + 1):
        if n == N and (A[n - 1] <= 0 < A[n] or A[n] < 0 <= A[n - 1]):
            print(sm - abs(A[n]) * 2)
        elif A[n + 1] <= 0 < A[n] or A[n] < 0 <= A[n + 1]:
            print(sm - abs(A[n - 1] - A[n]) * 2)
        else:
            print(sm)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

    for n in range(1, N + 1):
        if n == N and A[n - 1] <= 0 < A[n] or A[n] < 0 <= A[n - 1]:
            print(sm - abs(A[n]) * 2)
        elif A[n + 1] <= 0 < A[n] or A[n] < 0 <= A[n + 1]:
            print(sm - abs(A[n - 1] - A[n]) * 2)
        else:
            print(sm)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
A = sorted(a)
L = A[:2]
U = A[N-2:]
for i in range(N):
    l = L[0]
    u = U[1]
    if a[i] == l:
        l = L[1]
    elif a[i] == u:
        u = L[1]
    if l > 0:
        l = 0
    if u < 0:
        u = 0
    print(abs(l*2)+u*2)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

l = [0,*a,0]

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

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

Submission status: Wrong Answer

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

for i in range(N):
    if i == 0:
        if A[i]*A[i+1] > 0:
            tmp = ans 
        else:
            tmp = ans - abs(A[0]) + abs(A[1])
        print(tmp)
    elif i == N-1:
        tmp = ans - abs(A[i]-A[i-1]) - abs(A[i]) + abs(A[i-1])
        print(tmp)
    else:
        if A[i]*A[i-1] > 0 and A[i+1]*A[i-1] > 0 and A[i+1]*A[i]:
            print(ans)
        else:
            tmp = ans - abs(A[i]-A[i-1]) - abs(A[i] - A[i+1]) + abs(A[i-1]-A[i+1])
            print(tmp)

Submission status: Wrong Answer

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


for i in range(n):
    delete=A[i]
    A.pop(i)
    cost=0
    for j in range(n-1):
        if j==0:
            cost+=abs(A[j])
        elif j==n-2:
            cost+=abs(A[j]-A[j-1])+abs(A[j])
        else:
            cost+=abs(A[j]-A[j-1])

    A.insert(i, delete)
    print(cost)

Submission status: Wrong Answer

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

dis=0
d=[0]*n

for i in range(1,n+1):
    dis+=abs(a[i]-a[i-1])
    if a[i+1]<a[i] and a[i-1]<a[i]:
        d[i-1]=2*(a[i]-max(a[i-1],a[i+1]))
    if a[i+1]>a[i] and a[i-1]>a[i]:
        d[i-1]=2*(min(a[i-1],a[i+1])-a[i])
dis+=a[n+1]-a[n]

for i in range(n):
    print(dis-d[i])

Submission status: Wrong Answer

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

sorted_a = sorted(a_lst)
criteria_d = abs(sorted_a[-1] - min(sorted_a[0], 0)) * 2

for a in a_lst:
  if a == sorted_a[-1]:
    print(abs(sorted_a[-2] - min(sorted_a[0], 0)) * 2)
  elif a == min(sorted_a[0], 0):
    print(abs(sorted_a[-1] - min(sorted_a[1], 0)) * 2)
  else:
    print(criteria_d)

Submission status: Wrong Answer

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

a = [0] + a + [0]
cost = 0

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + [int(i) for i in input().split()] + [0]
d1a = [abs(a[i + 1] - a[i]) for i in range(n + 1)]
d2a = [abs(a[i + 1] - a[i - 1]) for i in range(1, n + 1)]
sum_a = sum(a)
for i in range(1, n + 1):
    print(sum_a + d2a[i - 1] - (d1a[i - 1] + d1a[i]))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
data = [0] + a + [0]
dif = []
plus = [0]*(n+2)
total = 0
for i in range(n+1):
    total += abs(data[i]-data[i+1])
    if data[i] <= data[i+1]:
        plus[i+1] = 1
ans = 0
for i in range(1, n+1):
    if plus[i] != plus[i+1]:
        if (data[i-1] > 0 and data[i] < 0) or (data[i-1] < 0 and data[i] > 0):
            ans = total - 2*min(abs(data[i]-data[i+1]), abs(data[i-1]-data[i]))
        elif data[i] == data[i+1]:
            ans = total
        else:
            ans = total - 2*abs(data[i]-data[i-1])
    else:
        ans = total
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
#n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
data = [0] + a + [0]
dif = []
plus = [0]*(n+2)
total = 0
for i in range(n+1):
    total += abs(data[i]-data[i+1])
    if data[i] <= data[i+1]:
        plus[i+1] = 1
ans = 0
for i in range(1, n+1):
    if plus[i] != plus[i+1]:
        if data[i+1] == 0 and ((data[i-1] > 0 and data[i] < 0) or (data[i-1] < 0 and data[i] > 0)):
            ans = total - 2*abs(data[i])
        elif data[i] == 0 and data[i+1] == 0:
            ans = total
        else:
            ans = total - 2*abs(data[i]-data[i-1])
    else:
        ans = total
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
print(a)
sum = 0
for i in range(n+1):
    sum += abs(a[i]-a[i+1])
for i in range(1, n+1):
    print(sum - 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()))
cost = [abs(A[i] - A[i+1]) for i in range(N-1)]
print(cost)
print(sum(cost)-cost[0]+abs(A[1])+abs(A[-1]))
for i in range(1, N-1):
    print(sum(cost) - (cost[i-1] + cost[i]) + abs(A[i+1] - A[i-1]) + abs(A[0]) + abs(A[-1]))
print(sum(cost)-cost[-1]+abs(A[-2]+abs(A[0])))

Submission status: Wrong Answer

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

tmp = a[0]

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

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

Submission status: Wrong Answer

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



# 0 3 5 -1 0
# 0 5 -1 0
# 0 3 -1 0
# 0 3 5 0

Submission status: Wrong Answer

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

A = [0] + A + [0] # 数はN+2こ
kane = []
for i in range(1, N+2):
    kane.append(abs(A[i] - A[i-1]))
skane = sum(kane)

print(kane)

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

Submission status: Wrong Answer

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

ans = abs(0 - A[0])
for i in range(N):
  ans += abs(A[i] - A[i+1])
  
for i in range(N):
  if i == 0:
    if A[0] * A[1] >= 0: #同符号
      print(ans)
    else:
      print(ans - 2*abs(A[0]))
  else:
    if (A[i] - A[i-1]) * (A[i+1] - A[i]) >= 0:
      print(ans)
    else:
      print(ans - 2*min(abs(A[i+1] - A[i]),abs(A[i] - A[i-1])))

Submission status: Wrong Answer

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

ans = abs(0 - A[0])
for i in range(N):
  ans += abs(A[i] - A[i+1])
  
for i in range(N):
  if i == 0:
    if A[0] * A[1] >= 0: #同符号
      print(ans)
    else:
      print(ans - 2*abs(A[0]))
  else:
    if (A[i] - A[i-1]) * (A[i+1] - A[i]) >= 0:
      print(ans)
    else:
      print(ans - 2*abs(A[i] - A[i-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def calc(a, n, total):
    if n == 0:
        pre = 0
    else:
        pre = a[n - 1]
    return total - (abs(a[n] - pre) + abs(a[n] - a[n + 1])) + abs(pre - a[n + 1])

pre = 0
for i in range(n):
    if i == n - 1:
        print(total - abs(a[i]) - abs(a[i - 1] - a[i]) + abs(a[i - 1]))
    elif (pre >= a[i] and a[i] >= a[i + 1]) or(pre <= a[i] and a[i] <= a[i + 1]):
        print(total)
    else:
        print(calc(a, i, total))

Submission status: Wrong Answer

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

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

def calc(a, n, total):
    return total - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1])

pre = 0
for i in range(n):
    if i == n - 1:
        print(total - abs(a[i]) - abs(a[i - 1] - a[i]) + abs(a[i - 1]))
    elif (pre >= a[i] and a[i] >= a[i + 1]) or(pre <= a[i] and a[i] <= a[i + 1]):
        print(total)
    else:
        print(calc(a, i, total))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
C = []
c = 0
for i in range(n+1):
  c += 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]:
    print(c)
  elif A[i] < A[i-1] < A[i+1] or A[i] < A[i+1] < A[i-1]:
    print(c - abs(min(A[i-1], A[i+1]) - A[i])*2)
  elif A[i-1] < A[i+1] < A[i] or A[i+1] < A[i-1] < A[i]:
    print(c - abs(A[i] - max(A[i+1], A[i-1]))*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
C = []
c = 0
for i in range(n+1):
  c += 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]:
    print(c)
  elif A[i] < A[i-1] < A[i+1] or A[i] < A[i+1] < A[i-1]:
    print(c - (min(A[i-1], A[i+1]) - A[i])*2)
  elif A[i-1] < A[i+1] < A[i] or A[i+1] < A[i-1] < A[i]:
    print(c - (A[i] - max(A[i+1], A[i-1]))*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.append(0)
ary = []
for i, a in enumerate(A):
    if i == 0:
        ary.append(abs(0-a))
    else:
        ary.append(ary[-1]+abs(A[i-1]-a))
print(ary)
for i in range(N):
    ans = 0
    if i != 0:
        ans = ary[i-1]
        ans += abs(A[i-1]-A[i+1])
    else:
        ans += abs(A[1])
    ans += ary[-1]-ary[i+1]
    print(ans)

Submission status: Wrong Answer

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

sum_DP = sum(DP)

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

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

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

Submission status: Wrong Answer

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

A_abs = [abs(A[0]-0)]
A_abs.extend([abs(A[i] - A[i-1]) for i in range(1, N)])
A_abs.append(abs(0 - A[-1]))

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

Submission status: Wrong Answer

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

A_abs = [abs(A[0]-0)]
A_abs.extend([abs(A[i] - A[i-1]) for i in range(1, N)])
A_abs.append(abs(0 - A[-1]))
print(A_abs)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
A=deque(map(int,input().split()))
A.appendleft(0)
A.append(0)
s=0
for i in range(1,N+2):
    s+=abs(A[i]-A[i-1])
print(s)
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(s)
    elif(A[i-1]>A[i]<A[i+1] or A[i-1]<A[i]>A[i+1]):
        print(s-((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 = [0] + list(map(int, input().split())) + [0]
money = 0
now = 0
for i in a:
    money += abs(now - i)
    now = i


for i in range(1, n+1):
    if a[i-1] <= a[i+1]:
        if a[i - 1] <= a[i] <= a[i + 1]:
            print(money)
        elif a[i] < a[i - 1]:
            print(money - 2 * (a[i - 1] - a[i]))
        elif a[i + 1] < a[i]:
            print(money - 2 * (a[i + 1] - a[i]))
    else:
        if a[i + 1] <= a[i] <= a[i - 1]:
            print(money)
        elif a[i] < a[i + 1]:
            print(money - 2 * (a[i + 1] - a[i]))
        elif a[i - 1] < a[i]:
            print(money - 2 * (a[i] - a[i - 1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
asort = sorted(a)
mn = asort[0]
mx = asort[-1]
for i in range(n):

    if mn != a[i] and mx != a[i]:
        if (mn >= 0 and mx >= 0) or (mn < 0 and mx < 0):
            print(2 * max(abs(mx),abs(mn)))
        else:
            print(2 * abs(mx - mn))
    elif asort[0] == a[i]:
        if (asort[1] >= 0 and mx >= 0) or (asort[1] < 0 and mx < 0):
            print(2 * max(abs(mx),abs(asort[1])))
        else:
            print(2 * abs(asort[1] - mx))
    elif asort[-1] == a[i]:
        if (mn >= 0 and asort[-2] >= 0) or (mn < 0 and asort[-2] < 0):
            print(2 * max(abs(mn),abs(asort[-2])))
        else:
            print(2 * abs(mn - asort[-2]))

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+1] - a[i])

for i in range(1,n+1):
    if (a[i] - a[i-1])*(a[i+1] - a[i]) < 0:
        if abs(a[i] - a[i-1]) < abs(a[i+1] - a[i]):
            print(s - 2*abs(a[i] - a[i-1]))
        else:
            print(s - 2*(a[i+1] - a[i]))
    else :
        print(s)

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+1] - a[i])

for i in range(1,n+1):
    if (a[i] - a[i-1])*(a[i+1] - a[i]) < 0:
        print(s - 2*abs(a[i] - a[i-1]))
    else :
        print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
li = [int(i) for i in input().split()]
ans = [0] * N
sum = abs(li[0]) + abs(li[N-1])
for i in range(1,N) :
    sum += abs(li[i] - li[i-1])
for i in range(N) :
    k = 0
    if i == 0 :
        ans[i] = sum
    elif i == N-1 :
        k = sum - abs(li[i]) - abs(li[i] - li[i-1]) + abs(li[i-1])
        ans[i] = k
    else :
        k = sum - abs(li[i] - li[i-1]) - abs(li[i+1] - li[i]) + abs(li[i+1] - li[i-1])
        ans[i] = k
for i in range(N) :
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
CUSUM=[0]*(N+2)
if N > 2:
  for i in range(N):
    if i == 0:
      CUSUM[1] = abs(A[0])
    else:
      CUSUM[i+1] = abs(A[i-1] - A[i])
  CUSUM[N+1] = abs(A[N-1])
  M = sum(CUSUM)
  #print(CUSUM)
  for i in range(N):
    if i == 0:
      ANS =  M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i+1])
    elif i == N-1:
      ANS = M - CUSUM[-1] - CUSUM[-2] + abs(A[i-1])
    else:
      ANS = M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i-1] - A[i+1])
    print(ANS)
else:
  print(abs(A[0]))
  print(abs(A[1]))