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: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N = int(input())
A = tuple([0,] + list(map(int, input().split())) + [0,])
D = []
sum = 0
for i, a in enumarate(A[1:-1]):
  i += 1
  pre = A[i - 1]
  tem = A[i]
  nex = A[i + 1]
  x = abs(pre - tem) + abs(tem - nex)
  sum += x
  D.append(abs(pre - nex) - x)
for d in D:
  print(sum + d)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, *A = map(int, open(0).input().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

for i in range(n):
    ans = l - c[i] - c[i+1]
    ans += abs(b[i] - b[i+2])
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
sum_array = [0 for x in range(n+1)]
now = 0
for i in range(n):
  sum_array[i] = abs(array[i]-now)
  now = array[i]
else:
  sum_array[-1] = abs(now)

for j in range(n):
  if j == 0:
    print(sum_array[-1])
  elif j == n-1:
    print(sum_array[-2]+abs(array[-2]))
  else:
    print(sum_array[-1]-(sum_array[j]-sum_array[j-1])-(sum_array[j+1]-sum_array[j])+(abs(array[j+1]-array[j-1]))

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
natural = [int(i) for i in input().split()]
sortedlist = natural.sorted()

sum = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j=0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-abs(B[0]))
        else:
            print(S-abs(B[1]-B[0]))
    elif j=len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-abs(B[-1]))
        else:
            print(S-abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-abs(B[j-1]-B[j]))
        else:
            print(S-abs(B[j+1]-B[j]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(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-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
        sub = 0
    elif A[i-1] < A[i+1] < A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] < A[i-1] < A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] < A[i-1] < A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] < A[i+1]< A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(cost - sub)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.append(a)
    A.append(0)
    
    sum = 0
    for i in range(n):
        root = list(A[:])
        del root[i+1]
        for j in range(1, n+1):
            sum += abs(root[j]-root[j-1])
        print(sum)
        sum = 0

Submission status: Runtime Error

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

import sys

N = int(sys.stdin.readline())

A = map(lambda x: int(x), sys.stdin.readline().split(' '))

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

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

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

Submission status: Runtime Error

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

import sys

N = int(sys.stdin.readline())

A = sys.stdin.readline().split(' ')


for rem in range(len(A)):
	pay = 0
	B = A.copy()
	del(B[rem])

	for i in range(len(B)):

		a = B[i]
		s = B[i - 1] if i > 0 else 0

		l = a - s
		pay += l if l > 0 else -l

	lastPoint = B[len(B) - 1]
	pay += lastPoint if lastPoint > 0 else -lastPoint

	print(pay)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

#import sys # モジュール属性 argv を取得するため
 
argvs = sys.argv  # コマンドライン引数を格納したリストの取得
argc = len(argvs) # 引数の個数
# デバッグプリント
print argvs
print argc

Submission status: Runtime Error

Solution code:
import sys # モジュール属性 argv を取得するため
 
argvs = sys.argv  # コマンドライン引数を格納したリストの取得
argc = len(argvs) # 引数の個数
# デバッグプリント
print argvs
print argc

Submission status: Runtime Error

Solution code:
print(args)

Submission status: Runtime Error

Solution code:
def main():
    a, b = map(int, input().split())
    s, k = '.#'
    ans = [[k] * 100 for _ in range(50)] + [[s] * 100 for _ in range(50)]
    col = 0
    row = 0
    for _ in range(a - 1):
        ans[row][col] = s
        col += 2
        if col == 100:
            col = 0
            row += 2
    col = 0
    row = 99
    for _ in range(a - 1):
        ans[row][col] = k
        col += 2
        if col == 100:
            col = 0
            row -= 2
    print(100, 100)
    for row in ans:
        print(''.join(row))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
l = input().split(' ')
W = int(l[0])
B = int(l[1])
print('52 100')
u = [0 for i in range(25 * 49)]
i = 0
while W > 1:
  u[i] = 1
  W -= 1
  i += 1
while B > 1:
  if i % 49 == 48:
    i += 1
  u[i] = 2
  B -= 1
  i += 1
print('#' * 100)
for l in range(50):
  print('#', end='')
  for c in range(98):
    w1 = (c % 2 == 1)
    w2 = (l % 2 == 1)
    i = c // 2 + 49 * (l // 2)
    if (u[i] == 1 and (w1 or w2)) or (u[i] == 2 and w1 and w2):
      print('#', end='')
    else:
      print('.', end='')
  print('#')
print('#' * 100)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int a[100002];
int main()
{
	int n, sum = 0, sum2;

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for(int i = 0; i <= n; i++)
	{
		sum += abs(a[i + 1] - a[i]);
	}
	for(int i = 1; i <= n; i++)
	{
		sum2 = sum;
		sum2 -= abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]);
		sum2 += abs(a[i + 1] - a[i - 1]);
		cout << sum2 << endl;
	}
}