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:
import sys
if sys.platform in ['ios', 'win32', 'darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(x) for x in input().split()]

N = INT()
A = MAP()

for i in range(N):
	ans = 0
	for j in range(N):
		if i==j: continue
		n = j
		t = j+1 if i!=j+1 else j+2
		if t >= N: continue
		now, to = n, t
		# print(i, now, to)
		if ans == 0: ans += abs(A[now])
		ans += abs(A[to]-A[now])
	ans += abs(A[to])
	print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
     dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
     dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
cost=abs(a[n-1])
a.append(0)
a.insert(0,0)
print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
cost=abs(a[n-1])
a.append(0)
a.insert(0,0)

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
cost=abs(a[n-1])
tmp=0
ans=0
a.append(0)
a.insert(0,0)
for i in range(n):
    tmp=abs(a[i]-a[i+1])
    cost+=tmp
for i in range(n):
    ans=cost+abs(a[i]-a[i+2])-abs(a[i+1]-a[i])-abs(a[i+1]-a[i+2])
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
cost=abs(a[n-1])
a.append(0)
a.insert(0,0)
for i in range(n):
    tmp=abs(a[i]-a[i+1])
    cost+=tmp
for j in range(n):
    ans=cost+abs(a[j]-a[j+2])-abs(a[j+1]-a[j])-abs(a[j+1]-a[j+2])
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
cost=abs(a[n-1])
a.append(0)
a.insert(0,0)
for i in range(n):
    tmp=abs(a[i]-a[i+1])
    cost+=tmp
for i in range(n):
    ans=cost+abs(a[i]-a[i+2])-abs(a[i+1]-a[i])-abs(a[i+1]-a[i+2])
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
lst1=[0]*(n+2)
lst2=[0]*(n+2)
lst1[1]=abs(a[0])
lst2[1]=abs(a[n-1])
for i in range(1,n):
  lst1[i+1]=lst1[i]+abs(a[i]-a[i-1])
  lst2[i+1]=lst2[i]+abs(a[n-i]-a[n-i-1])
lst1[n+1]=lst[n]+abs(a[n-1])
lst2[n+1]=lst[n]+abs(a[0])
for i in range(n):
  print(lst1[i]+lst2[n-i]+abs(a[min(n-1,i+1)]-a[max(0,i-1)]))

Submission status: Runtime Error

Solution code:
def cc092():
    n = int(input())
    an = list(map(int, input().split()))

    for i in range(0, n):
        bn = except_arr(an, i)
        bn.extend([0])
        pos = 0
        cost = 0
        for j in bn:
            cost += abs(pos-j)
            pos = j
        print(cost)

cc092()

Submission status: Runtime Error

Solution code:
6
-679 -2409 -3258 3095 -3291 -4462

Submission status: Runtime Error

Solution code:
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(de[i]-de[i+1]))
ans=sum(di)
for i in range(1,n+1):
  if max(de[i-1],de[i],de[i+1])==de[i] or min(de[i-1],de[i],de[i+1])==de[i]:
    print(ans-2*min(di[i],di[i+1]))
  else:
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

A_total = sum(A_n)
A_added = [0] + A + [0]
for i in range(1, N + 1):
    if A_added[i + 1] >= A_added[i] and A_added[i] >= A_added[i - 1]:
        print(A_total)
    elif A_added[i + 1] >= A_added[i - 1] and A_added[i - 1] >= A_added[i]:
        print(A_total - 2 * abs(A_added[i] - A_added[i - 1]))
    elif A_added[i] >= A_added[i + 1] and A_added[i + 1] >= A_added[i - 1]:
        print(A_total - 2 * abs(A_added[i + 1] - A_added[i]))
    elif A_added[i] >= A_added[i - 1] and A_added[i - 1] >= A_added[i + 1]:
        print(A_total - 2 * abs(A_added[i] - A_added[i - 1]))
    elif A_added[i - 1] >= A_added[i] and A_added[i] >= A_added[i + 1]:
        print(A_total)
    elif A_added[i - 1] >= A_added[i + 1] and A_added[i + 1] >= A_added[i]:
        print(A_total - 2 * abs(A_added[i] - A_added[i + 1]))

Submission status: Runtime Error

Solution code:
_,a=open(0)
a=[0]+list(map(int,a.split()))+[0]
A=abs
c=sum(A(j-i)for i,j in zip(a,a[1:]));for i,j,k in zip(a,a[1:],a[2:]):print(c-A(j-i)-A(k-j)+A(k-i))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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 + 2):
    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)
    if a[k - 1] == a[k]:
        print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))
lis = []
lis.append(0)
for hoge in li:
    lis.append(hoge)
lis.append(0)
sumpo = 0
sumpo += abs(li[0])
for i in range(0,n):
    sumpo += abs(li[i]-li[i+1])
for i in range(1,n+1):
    print(sumpo + abs(li[i+1]-li[i-1]) - (abs(li[i]-li[i-1])+abs(li[i+1]-li[i])))

Submission status: Runtime Error

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

def dd_cost(L):
    c = 0
    M = L[:]
    for i in range(len(L)):
        if L[i] < 0:
            L[i] = -1
        elif L[i] > 0:
            L[i] = 1
        else:
            L[i] = 0
    L = np.array(L)
    L = L[1:]-L[:-1]
    for i in range(len(L)):
        if L[i] < 0 or L[i] > 0:
            c += abs(M[i]) * 2
    c += abs(M[-1]) * 2
    print(c)

for i in range(len(A)):
    dd_cost(A[:i]+A[i+1:])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
int a[100010]; 

void input(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int sum = abs(a[0]) + abs(a[n-1]);
    for(int i=1;i<n;i++) sum += abs(a[i] - a[i-1]);
    cout << (sum + abs(a[1]) - (abs(a[0])+abs(a[1]-a[0]))) << endl;
    for(int i=1;i<n-1;i++){
        cout << (sum + abs(a[i+1]-a[i-1]) - (abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))) << endl;
    }
    cout << (sum + abs(a[n-2]) - (abs(a[n-1]-a[n-2])+abs(a[n-1]))) << endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

total = sum(abs(a[i] - a[i + 1]) for i in range(0, n + 1))
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: Runtime Error

Solution code:
import itertools

def f(i1, i2, c):
    return itertools.islice(((x, y) for x, y in itertools.product(i1, i2) if x % 2 == y % 2), c)

a, b = map(int, input().split())
k = 100
grid = [['#' if x < k else '.' for _ in range(k * 2)] for x in range(k * 2)]

for x, y in f(range(0, k - 1), range(k * 2), a - 1):
    grid[x][y] = '.'

for x, y in f(range(k + 1, k * 2), range(k * 2), b - 1):
    grid[x][y] = '#'

for row in grid:
    print(''.join(row))

Submission status: Runtime Error

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*2: x if x <= 0 else 0)(l_sort[1])
    elif l[i] == max(l):
        cost = -min(l)*2 + (lambda x*2: x if x >= 0 else 0)(l_sort[n-2])
    else:
        cost = -min_l*2 + max_l*2
    print(cost)

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
word=[]
word.append('０')
for i in range(1,n+1):
    word.append(input())
    for j in range(0,i):
        if word[j]==word[i]:
            print('No')
            sys.exit()
        else:
            j+=1
    if (i>1)& (word[i-1][len(word[i-1])-1]!=word[i][0]):
        print('No')
        sys.exit()

print('Yes')

Submission status: Runtime Error

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

c=abs(A[i])+abs(A[n-1])
for i in range(n):
    if i<n-1:
        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)+abs(A[i+1]-A[i-1]))
            continue

Submission status: Runtime Error

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

c=abs(A[i])+abs(A[n-1])
for i in range(n):
    if i<n-1:
        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: Runtime Error

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

c=0
for i in range(n):
    if i==0 or i==n-i:
        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: Runtime Error

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
  b = copy.deepcopy(a)
  del b[i]
  cnt = 0
  for j in range(1,n-1):
    cnt += abs(b[j]-b[j-1])
    print(cnt)

Submission status: Runtime Error

Solution code:
n = input()

a = input().split(" ")

m = list()
for index in range(len(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])) + abs(int(line[index]) - int(line[index + 1])))
		elif index == (len(line) - 1):
			cost += abs(int(line[index]))
		elif index != (len(line) - 1) and index != 0 :
			cost += abs(int(line[index]) - int(line[index + 1]))
	print(cost)

Submission status: Runtime Error

Solution code:

n = input()
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])) + abs(int(line[index]) - int(line[index + 1])))
		elif index == (len(line) - 1):
			cost += abs(int(line[index]))
		else:
			cost += abs(int(line[index]) - int(line[index + 1]))
	print(cost)

Submission status: Runtime Error

Solution code:
n = input()

a = list()
z = input().split(" ")
for x in z:
	a.append(int(x))

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):
		if index == 0:
			cost += (abs(0 - (line[index])) + abs((line[index]) - (line[index + 1])))
		elif index == (len(line) - 1):
			cost += abs((line[index]))
		else:
			cost += abs((line[index]) - (line[index + 1]))
	print(cost)

Submission status: Runtime Error

Solution code:
n = input()

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])) + abs(int(line[index]) - int(line[index + 1])))
		elif index == (len(line) - 1):
			cost += abs(int(line[index]))
		else:
			cost += abs(int(line[index]) - int(line[index + 1]))
	print(cost)

Submission status: Runtime Error

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+1):
    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: Runtime Error

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)]
sumS = sum(S)
for i in range(N+1):
    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: Runtime Error

Solution code:
n = int(input())
lis = [0] + list(map(int,input().split())) + [0]
b = 0
for i in range(n+1):
 b += abs(lis[i+1]-lis[i])
for i in range(1,n+1):
 if lis[i-1] <= lis[i] <= lis[i+1] or lis[i-1] => lis[i] => lis[i+1]:
   print(b)
 else:
  print(b-abs(lis[i-1] - lis[i]) - abs(lis[i+1] - lis[i]) + abs(lis[i+1] - lis[i-1]))

Submission status: Runtime Error

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

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

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


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

Submission status: Runtime Error

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



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

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

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


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

Submission status: Runtime Error

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

ifsums = 0

an = [0]

for i in range(n):
    an.append(a[i])
    if i != 0 or n -1:
        ifsums = ifsums +abs(a[i] - a[i-1])
    else:
        ifsums = ifsums + abs(a[i])        
an.append(0)

nal = []

for i in range(1,n+1):
    nal.append(ifsums - ((abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1]))))
    
for i in range(len(nal)):
    print(nal(i))

Submission status: Runtime Error

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

ifsums = 0
for i in range(1,n):
    ifsums = ifsums + abs(a[i] - a[i-1])
nal = []
nal.append(abs(a[1] - a[0]))
nal.append(abs(a[n-1] - a[n-2]))

for i in range(1,n-1):
    nal.append(abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]) - a[i])
    
print(ifsums - max(nal))

Submission status: Runtime Error

Solution code:
n = int(input())
X = map(int, input().split())
# n = 3
# X = [3, 5, -1]

X.insert(0,0)
X.append(0)
Y = []
for i, x in enumerate(X[1:]):
    Y.append(abs(x-X[i]))
sumY = sum(Y)

for i, x in enumerate(X):
    if i not in [0,len(X)-1]:
        ans = sumY - (Y[i-1] + Y[i]) + abs(X[i+1]-X[i-1])
        print(ans)

Submission status: Runtime Error

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

h = a[0]
i = a[1]
s = h + abs(h-i)
if i < h:
    ans.append(-1 * abs(h-i))
else:
    ans.append(0)
for x in range(2, n+1):
    j = a[x]
    s += abs(i-j)
    if j < i:
        ans.append(-1 * abs(i-j))
    else:
        ans.append(0)
    h = i
    i = j

for x in ans:
    print(s+x)

Submission status: Runtime Error

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

h = a[0]
i = a[1]
s = h + abs(h-i)
if i < h:
    ans[0] = -1 * abs(h-i)
else:
    ans[0] = 0
for x in range(2, n+1):
    j = a[x]
    s += abs(i-j)
    if j < i:
        ans[x] = -1 * abs(i-j)
    else:
        ans[x] = 0
    h = i
    i = j

for x in ans:
    print(s+x)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)
kaisa = deque()
ans = list()

for i in range(len(a)):
    if i == 0:
        continue
    diff = a[i] - a[i - 1]
    kaisa.append(diff)


for i in range(n):
    ans = kaisa.copy()
    new_num = kaisa[i] + kaisa[i + 1]
    ans.remove(kaisa[i])
    ans.remove(kaisa[i + 1])
    ans.insert(i, new_num)
    print(sum([abs(n) for n in ans]))

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)
kaisa = deque()
ans = deque()

for i in range(len(a)):
    if i == 0:
        continue
    diff = a[i] - a[i - 1]
    kaisa.append(diff)


for i in range(n):
    ans = kaisa.copy()
    new_num = kaisa[i] + kaisa[i + 1]
    ans.remove(kaisa[i])
    ans.remove(kaisa[i + 1])
    ans.insert(i, new_num)
    print(sum([abs(n) for n in ans]))

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)
kaisa = deque()
ans = deque()
double_kaisa = deque()
for i in range(len(a)):
    if i == 0:
        continue
    diff = a[i] - a[i - 1]
    kaisa.append(diff)


for i in range(n):
    ans = kaisa.copy()
    new_num = kaisa[i] + kaisa[i + 1]
    ans.remove(kaisa[i])
    ans.remove(kaisa[i + 1])
    ans.insert(i, new_num)
    print(sum([abs(n) for n in ans]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in N:
	abs=abs(A-)

D,X =  map(int, input().split())
N_chocolate=0
for i in range (N):
	A= int(input())
	if A == 1:
		N_chocolate=N_chocolate+D-1
	else:
		N_chocolate=N_chocolate+int(D/A)
output=N_chocolate+X+N
print (output)

Submission status: Runtime Error

Solution code:
N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
money=0
for i in range(N+1):
  money+=abs(list_A[i+1]-list_B[i])
for i in range(1,N+1):
  Money=money-abs(list_A[i]-list_A[i-1])-abs(list_A[i+1]-list_A[i])+abs(list_A[i+1]-list_A[i-1])
  print(Money)

Submission status: Runtime Error

Solution code:
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
A.append(0)
A.appendleft(0)
for i in range(1, N+1):
    a = A[i]
    dis = 0
    del A[i]
    for j in range(N):
        dis += abs(A[j+1]-A[j])
    A.insert(i, a)
    print(dis)

Submission status: Runtime Error

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

# AtCoder Beginner Contest
# Problem C


if __name__ == '__main__':
    spot_count = int(input())
    mod_spots = [0] + list(map(int, input().split())) + [0]

    # FIXME: TLE
    for i in range(spot_count):
        tmp = mod_spots[i + 1]
        # # mod_spots[i + 1] = 0
        # # min_value = min(mod_spots[1:-1])
        # # max_value = max(mod_spots[1:-1])
        # min_value = min(mod_spots[1:len(mod_spots) - 1])
        # max_value = max(mod_spots[1:len(mod_spots) - 1])
        # # cost = 0

        # # if min_value * max_value > 0:
        # if (min_value > 0 and max_value > 0) or (min_value < 0 and max_value < 0):
        #     # cost = max(abs(max_value), abs(min_value)) * 2
        #     print(max(abs(max_value), abs(min_value)) * 2)
        # # elif min_value * max_value < 0:
        # elif (min_value < 0 and max_value > 0) or (min_value > 0 and max_value < 0):
        #     # cost = abs(max_value) + abs(min_value)
        #     print((abs(max_value) + abs(min_value)) * 2)
        # elif (min_value == 0 and max_value != 0) or (max_value == 0 and min_value != 0):
        #     print(max(abs(max_value), abs(min_value)) * 2)
        # else:
        #     # cost = 0
        #     print(0)

        if mod_spots[i] <= mod_spots[i + 2]:
            mod_spots[i + 1] = mod_spots[i]
        elif (mod_spots[i] > 0) and mod_spots[i + 2] > 0:
            mod_spots[i + 1] = 0
        else:
            mod_spots[i + 1] = mod_spots[i]

        # cost = sum([abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)])
        # hoge = [abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)]
        hoge = {j: abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)}
        print(sum(hoge.values())
        mod_spots[i + 1] = tmp
        # print(cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = input()
A = np.array(map(int, input().split()))


A = np.append(np.append([0], A), [0])
total_sum = 0
for i in range(0, len(A) - 1):
    total_sum += np.abs(A[i + 1] - A[i])

for i in range(1, len(A) - 1):
    partial_sum = total_sum - np.abs(A[i + 1] - A[i]) - np.abs(A[i] - A[i - 1]) + np.abs(A[i + 1] - A[i - 1])
    print(partial_sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = input()
A = np.array(map(int, raw_input().split()))


A = np.append(np.append([0], A), [0])
total_sum = 0
for i in range(0, len(A) - 1):
    total_sum += np.abs(A[i + 1] - A[i])

for i in range(1, len(A) - 1):
    partial_sum = total_sum - np.abs(A[i + 1] - A[i]) - np.abs(A[i] - A[i - 1]) + np.abs(A[i + 1] - A[i - 1])
    print partial_sum

Submission status: Runtime Error

Solution code:
import itertools as it

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

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

L.append(L[-1] + abs(A[-2] - A[0]))

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

Submission status: Runtime Error

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

b=copy.deepcopy(a)
a.append(0)
b.insert(0,0)

a=np.array(a)
b=np.array(b)
ab=np.abs(a-b)
sumab=np.sum(ab)
temp=ab

np.insert(a,0,0)
for i in range(N):
    ab=temp
    ans=sumab-np.sum(ab[i:i+1])
    ans+=a[i+2]-a[i]
    print(ans)


    print(ans)

Submission status: Runtime Error

Solution code:
 = int(input())
A = list(map(int, input().split()))
A_index = [i for i in range(N)]
dic = dict(zip(A_index, A))

for j in range(len(A)):
    if j < len(A)-1:
        dic[j] = dic[j+1]
    else:
        del dic[j]

    for i in range(0,len(dic)):
        if i == 0:
            wa = abs(dic[0])
        elif i == len(dic)-1:
            wa = wa + abs(dic[i-1]-dic[i]) + abs(dic[i])
        else:
            wa = wa + abs(dic[i-1]-dic[i])
    print(wa)
    dic[j] = A[j]

Submission status: Runtime Error

Solution code:
n = int(input())
 
spot = input().split()

for i in range(len(spot)):
    spot = int(spot)

for i in range(n):
    total = 0
 
    pos = 0
    
    for l in range(n):
        if i != l:
            money = pos - spot[l]
            pos = spot[l]
            
            if money < 0:
                money *= -1
            total += money
 
    if pos < 0:
        pos *= -1
    total += pos
    
    print(total)

Submission status: Runtime Error

Solution code:
n = int(input())
 
spot = input().split()

for i in range(len(spot)):
    spot = int(spot)

for i in range(n):
    total = 0
 
    pos = 0
    
    for l in range(n):
        if i != l:
            money = pos - int(spot[l])
            pos = int(spot[l])
            
            if money < 0:
                money *= -1
            total += money
 
    if pos < 0:
        pos *= -1
    total += pos
    
    print(total)