Problem: 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.

Submission attempts (in order):
n = int(input())
L = list(map(int,input().split()))
print(L)
LL = sorted(L)

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

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

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

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

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

                
                

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

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

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

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

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

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

                
                

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

diff1 = []
diff2 = []
sum1 = 0
for i in range(n+1):
    sum1 += abs(L[i+1]-L[i])
    diff1.append(abs(L[i+1]-L[i]))

for i in range(n):
    diff2.append(abs(L[i+2]-L[i]))

for i in range(n):
    ans = sum1-(diff1[i]+diff1[i+1]) + diff2[i]
    print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted