Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1):
    if red_count + 1 - i < 0:
        print(0)
        continue
    b_dif = math.factorial(k-1) / (math.factorial(i-1) * math.factorial(k-i))
    
    r_dif = math.factorial(red_count + 1)  /  (math.factorial(i) * math.factorial(red_count + 1 - i))

    
    print(int(r_dif * b_dif % mod))

Fixed submission:

from scipy.misc import comb
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1) :
    if red_count + 1 - i < 0 :
        print(0)
        
    else:

        print(comb(red_count+1, i , exact = True)*comb(k-1, i-1, exact=True) % mod)

Buggy python submission (verdict: Runtime Error):
import math
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1):
    if red_count + 1 - i < 0:
        print(0)
        continue
    b_dif = math.factorial(k-1) / (math.factorial(i-1) * math.factorial(k-i))
    
    a_dif = math.factorial(red_count + 1)  /  (math.factorial(i) * math.factorial(red_count + 1 - i))

    print(int(a_dif * b_dif % mod))

Fixed submission:

from scipy.misc import comb
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1) :
    if red_count + 1 - i < 0 :
        print(0)
        
    else:

        print(comb(red_count+1, i , exact = True)*comb(k-1, i-1, exact=True) % mod)

Buggy python submission (verdict: Runtime Error):
import math
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1):
    if red_count == 0:
        print(1)
        continue
    b_dif = math.factorial(k-1) / (math.factorial(i-1) * math.factorial(k-i))
    
    a_dif = math.factorial(red_count + 1)  /  (math.factorial(i) * math.factorial(red_count + 1 - i))

    print(int(a_dif * b_dif % mod))

Fixed submission:

from scipy.misc import comb
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1) :
    if red_count + 1 - i < 0 :
        print(0)
        
    else:

        print(comb(red_count+1, i , exact = True)*comb(k-1, i-1, exact=True) % mod)

Buggy python submission (verdict: Runtime Error):
import math
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1):
    b_dif = math.factorial(k-1) / (math.factorial(i-1) * math.factorial(k-i))
    
    a_dif = math.factorial(red_count + 1)  /  (math.factorial(i) * math.factorial(red_count + 1 - i))

    print(int(a_dif * b_dif % mod))

Fixed submission:

from scipy.misc import comb
n , k = map(int, input().split())

mod = 10 ** 9 + 7
red_count = n - k 
for i in range(1, k+1) :
    if red_count + 1 - i < 0 :
        print(0)
        
    else:

        print(comb(red_count+1, i , exact = True)*comb(k-1, i-1, exact=True) % mod)
Buggy python submission (verdict: Runtime Error):
s = int(input())
checker = True
for i in range(3):
    if s[i] == s[i+1]:
        checker=False

if checker:
    print("Good")
else:
    print("bad")

Fixed submission:
s = input()
checker = True
for i in range(3):
    a , b = int(s[i]), int(s[i+1])
    if a == b:
        checker=False

if checker:
    print("Good")
else:
    print("Bad")
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

ans = b - (b // c + b//d - b//(c*d // math.gcd(c, d))) - ( a - 1  - ((a-1) // c + (a-1)//d - (a-1)//(c * d //math.gcd(c, d))))  

print(ans)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

ans = b - (b // c + b//d - b//(c*d // fractions.gcd(c, d))) - ( a - 1  - ((a-1) // c + (a-1)//d - (a-1)//(c * d //fractions.gcd(c, d))))  

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
now_time = 0
global tf
tf = False

def finish_work(now_time, works):
    global tf
    if len(works) == 0 or tf == True:
        tf = True
        return True
    sums = sum([i[0] for i in works]) 
    maxs = max ([i[1] for i in works])
    if maxs < sums:
        return 0
    for index, i in enumerate(works):
        if now_time + i[0] <= i[1]:
            work_list = works.copy()
            work_list.pop(index)
            finish_work(now_time + i[0], work_list)

works = []

for i in range(n):
    a = list(map(int, input().split()))
    works.append(a)

for index, i in enumerate(works):
    
    if now_time + i[0] <= i[1]:
        work_list = works.copy()
        work_list.pop(index)
        finish_work(now_time + i[0], work_list)

if tf:
    print("Yes")
else:
    print("No")

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

ans = b - (b // c + b//d - b//(c*d // fractions.gcd(c, d))) - ( a - 1  - ((a-1) // c + (a-1)//d - (a-1)//(c * d //fractions.gcd(c, d))))  

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
kobaisu =int( (C * D )/ math.gcd(C, D))

bk =  B - B//C - B//D + B//kobaisu

ak = (A-1) - (A-1)//C - (A-1)//D + (A-1)//kobaisu

print(bk-ak)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

ans = b - (b // c + b//d - b//(c*d // fractions.gcd(c, d))) - ( a - 1  - ((a-1) // c + (a-1)//d - (a-1)//(c * d //fractions.gcd(c, d))))  

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())

count = 0
for i in range(A, B+1):
    if i % C != 0 and i % D != 0:
        count+=1

print(count)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

ans = b - (b // c + b//d - b//(c*d // fractions.gcd(c, d))) - ( a - 1  - ((a-1) // c + (a-1)//d - (a-1)//(c * d //fractions.gcd(c, d))))  

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

li = []
for i in range(n):
    li.append(list(map(str, input().split())))
    li[i].append(i+1)

li.sort( key = lambda li : (li[0], -int(li[1])))
for i in li:
    print(li[2])


Fixed submission:
n = int(input())

li = []
for i in range(n):
    li.append(list(map(str, input().split())))
    li[i].append(i+1)

li.sort( key = lambda li : (li[0], -int(li[1])))
for i in li:
    print(i[2])
Buggy python submission (verdict: Time Limit Exceeded):
n, m= map(int, input().split())

gates = [list(map(int, input().split())) for _ in range(m)]
count=0
for i in range(1, n+1):
    tf = True
    for j in gates:
        if j[0] > i or j[1] < i:
            tf = False
            break
        
    if tf:
        count+=1

print(count)


Fixed submission:
n, m= map(int, input().split())

gates = [list(map(int, input().split())) for _ in range(m)]
up = min([i[1] for i in gates])
down = max([i[0] for i in gates])


if up >= down:
    print(up-down+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
li = list(map(int, input().split()))
temp = li.copy()
for i in range(n-1):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = sum(li)
li = temp
for i in reversed(range(1,n)):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = max(ans, sum(li))

Fixed submission:
n = int(input())
li = list(map(int, input().split()))
mainus_li = [i for i in li if i<0]
li = [abs(i) for i in li]
ans = sum(li)
if len(mainus_li) %2 == 1:
    ans -= 2*min(li)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = 0
li = ["A", "C", "G", "T"]
count = 0
for i in s:
    if i in li:
        count += 1
    else:
        if count > ans:
            ans = count
        count = 0
if count == len(ans):
    print(count)
else:
    print(ans)


Fixed submission:
s = input()
ans = 0
li = ["A", "C", "G", "T"]
count = 0
for i in s:
    if i in li:
        count += 1
    else:
        if count > ans:
            ans = count
        count = 0

if count > ans:
    ans = count
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
li = [i for i in s]
pos = []
for i in range(len(li)-1):
    if li[i]== "A" and li[i+1] == "C":
        pos.append(i)
for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy+=[r-1, l-1]
    pos_copy.sort()
    print(pos_copy.index(r-1)  - pos_copy.index(l-1) - 1)


Fixed submission:

n, q= map(int, input().split())
s = input()

li = [list(map(int, input().split())) for _ in range(q)]
pos = [0]*n
count=0
for i in range(1, n):   
    if s[i-1] == "A" and s[i]=="C":
        count+=1
    pos[i] = count

for i in li:
    print(pos[i[1]-1]-pos[i[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
li = [i for i in s]
pos = []
for i in range(len(li)-1):
    if li[i ]== "A" and li[i+1] == "C":
        pos.append(i)


for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy.append(l-1)
    pos_copy.append(r-1)
    pos_copy.sort()
    print(pos_copy.index(r-1)  - pos_copy.index(l-1) - 1)


Fixed submission:

n, q= map(int, input().split())
s = input()

li = [list(map(int, input().split())) for _ in range(q)]
pos = [0]*n
count=0
for i in range(1, n):   
    if s[i-1] == "A" and s[i]=="C":
        count+=1
    pos[i] = count

for i in li:
    print(pos[i[1]-1]-pos[i[0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for _ in range(500000):
    temp1 = s.count("01")
    ans += temp1
    s = s.replace("01", "")
    temp2 = s.count("10")
    ans += temp2
    s = s.replace("10", "")
    if temp1 == 0 and temp2 == 0:
        break
    
print(ans*2)


Fixed submission:

s = input()

blue = s.count("1")
red = s.count("0")

print(2*min(blue, red))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
while 1:
    
    temp1 = s.count("01")
    ans += temp1
    s = s.replace("01", "")
    temp2 = s.count("10")
    ans += temp2
    s = s.replace("10", "")
    if temp1 == 0 and temp2 == 0:
        break
    
print(ans*2)


Fixed submission:

s = input()

blue = s.count("1")
red = s.count("0")

print(2*min(blue, red))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
global ans
ans = sum([a, b, c])
def count(a_use, b_use, c_use, non_use):
  global ans
  if a_use and b_use and c_use:
    cost = abs(sum(a_use)-a)+abs(sum(b_use)-b)+abs(sum(c_use)-c) + 10*((len(a_use)-1) + (len(b_use)-1) +(len(c_use)-1) )
    ans = min(cost, ans)
  for i in range(len(non_use)):
    temp = non_use[:]
    temp.pop(i)
    use = [non_use[i]]
    count(a_use+use, b_use, c_use, temp)
    count(a_use, b_use+use, c_use, temp)
    count(a_use, b_use, c_use+use, temp)
    count(a_use, b_use, c_use, temp)
count([], [], [], l)
print(ans)

Fixed submission:
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
INF = 10**9
def count(a_sum, b_sum, c_sum, cur):
  if cur == n:
    return (abs(a_sum -a) + abs(b_sum -b) +abs(c_sum -c)) -30 if min(a_sum, b_sum, c_sum) > 0 else INF
  else:
    ans1 = count(a_sum, b_sum, c_sum, cur+1)
    ans2 = count(a_sum+l[cur], b_sum, c_sum, cur+1) + 10 
    ans3 = count(a_sum, b_sum+l[cur], c_sum, cur+1) + 10
    ans4 = count(a_sum, b_sum, c_sum+l[cur], cur+1) + 10
    return min(ans1, ans2, ans3, ans4)

print(count(0, 0, 0, 0))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
li = list(map(int, input().split()))
 
li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]
move_cost.sort()
for i in range(n-1):
    if len(move_cost) == 0:
        break
    move_cost = move_cost[:-1]
 
print(sum(move_cost))

Fixed submission:
n, m = map(int, input().split())
li = list(map(int, input().split()))
 
li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]
move_cost.sort()
if n > 1:
    move_cost = move_cost[:-n+1]

print(sum(move_cost))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
li = list(map(int, input().split()))

li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]


for i in range(n-1):
    if len(move_cost) == 0:
        break
    move_cost.remove(max(move_cost))

print(sum(move_cost))

Fixed submission:
n, m = map(int, input().split())
li = list(map(int, input().split()))
 
li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]
move_cost.sort()
if n > 1:
    move_cost = move_cost[:-n+1]

print(sum(move_cost))
Buggy python submission (verdict: Runtime Error):
n, m= map(int, input().split())

p_y_li = [list(map(int, (input() + " {}".format(i)).split())) for i in range(m)]

p_y_li.sort(key = lambda x : x[1])

li = [0 for _ in range(m)]
for i in range(m):
    ans = ""
    p = p_y_li[i][0]
    li[p-1] += 1
    x = li[p-1]
    ans = str(p).zfill(6) + str(x).zfill(6)
    p_y_li[i].append(ans)

p_y_li.sort(key = lambda x : x[2])
for i in p_y_li:
    print(i[3])

Fixed submission:
n, m= map(int, input().split())

p_y_li = [list(map(int, (input() + " {}".format(i)).split())) for i in range(m)]

p_y_li.sort(key = lambda x : x[1])

li = [0 for _ in range(n)]
for i in range(m):
    ans = ""
    p = p_y_li[i][0]
    li[p-1] += 1
    x = li[p-1]
    ans = str(p).zfill(6) + str(x).zfill(6)
    p_y_li[i].append(ans)

p_y_li.sort(key = lambda x : x[2])
for i in p_y_li:
    print(i[3])
Buggy python submission (verdict: Runtime Error):
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
ans = []

for cx in range(101):
    for cy in range(101):
        for i in li:
            if i[2] != 0:
                ans.append([cx, cy, i[2] + abs(i[0]-cx) + abs(i[1] -cy)])
                break

for i in li:
    if len(ans) ==1:
        break
    for j in reversed (range(len(ans[:]))):
        if ans[j][2] - abs(i[0]-ans[j][0]) - abs(i[1]-ans[j][1]) != i[2]:
            ans.pop(j)


print(" ".join(map(str, ans[0])))

Fixed submission:

n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
ans = []

for cx in range(101):
    for cy in range(101):
        for i in li:
            if i[2] != 0:
                ans.append([cx, cy, i[2] + abs(i[0]-cx) + abs(i[1] -cy)])
                break

for i in li:
    if len(ans) ==1:
        break
    if i[2] != 0:
        for j in reversed (range(len(ans[:]))):
            if ans[j][2] - abs(i[0]-ans[j][0]) - abs(i[1]-ans[j][1]) != i[2]:
                ans.pop(j)
    if i[2] == 0:
        for j in reversed (range(len(ans[:]))):
            if ans[j][2] - abs(i[0]-ans[j][0]) - abs(i[1]-ans[j][1]) > i[2]:
                ans.pop(j)

print(" ".join(map(str, ans[0])))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int, input().split()))
odd = V[::2]
even = V[1::2]

#最大出現する数と数字を検索する
def count(l):
  maximam = 0
  for i in set(l):
    count = l.count(i)
    if count > maximam:
      num = [i]
      maximam = count
    elif count == maximam:
      num.append(i)

  return maximam, num

odd_count = count(odd)
even_count = count(even)

if odd_count[1] == even_count[1] and len(odd_count[1]) ==1:
  if odd_count[0] == N//2:
    ans = N // 2
  else:
    even = [i if i != even_count[1][0] else -1 for i in even]
    odd = [i if i != odd_count[1][0] else -1 for i in odd]
    even_count2 = count(odd)
    odd_count2 = count(even)
    ans = N - max(odd_count[0] + even_count2[0], odd_count2[0] + even_count[0])
else:
  ans = N - (odd_count[0] + even_count[0])
  
print(ans)

Fixed submission:
import collections

N = int(input())
V = list(map(int, input().split()))
odd = V[::2]
even = V[1::2]
odd_count =  collections.Counter(odd).most_common()
even_count = collections.Counter(even).most_common()

if odd_count[0] == even_count[0]:
  if len(odd_count) == 1:
    ans = N//2
  elif odd_count[1][1] == odd_count[0][1] or even_count[1][1] == even_count[0][1]:
    ans = N-(odd_count[0][1] + even_count[0][1])
  else:
    ans = N-max(odd_count[0][1] + even_count[1][1], odd_count[1][1]+ even_count[0][1])
else:
  ans = N-(odd_count[0][1] + even_count[0][1])

print(ans)
Buggy python submission (verdict: Runtime Error):

n, k = map(int, input().split())
li = list(map(int, input().split()))
li.append(0)
li.sort()
zero_index = li.index(0)
if zero_index == 0:
    print(li[k])
elif zero_index == len(li) -1:
    print(abs(li[-k-1]))
else:
    near_zero_small = li[zero_index-1]
    near_zero_big = li[zero_index+1]
    li.pop(zero_index)
    ans = 0
    cost = 0
    for i in range(n):
        minimam = li[i]
        maximam = li[i+k-1]
        if (minimam > 0 and maximam > 0 ):
            if minimam == near_zero_big:
                cost = maximam
        elif (minimam < 0 and maximam < 0 ):
            if minimam == near_zero_big:
                cost = abs(minimam)
        else:
            cost = min(abs(minimam), maximam)*2 + max(abs(minimam), maximam)
        if ans > cost or ans == 0:
            ans = cost
    print(ans)

Fixed submission:
n, i = map(int, input().split())

print(n-i+1)
Buggy python submission (verdict: Runtime Error):

n, k = map(int, input().split())
li = list(map(int, input().split()))
li.append(0)
li.sort()
zero_index = li.index(0)
if zero_index == 0:
    print(li[k])
elif zero_index == len(li) -1:
    print(abs(li[-k-1]))
else:
    near_zero_small = li[zero_index-1]
    near_zero_big = li[zero_index+1]
    li.pop(zero_index)
    ans = 0
    cost = 0
    for i in range(n):
        minimam = li[i]
        maximam = li[i+k-1]
        if (minimam > 0 and maximam > 0 ):
            if minimam == near_zero_big:
                cost = maximam
        elif (minimam < 0 and maximam < 0 ):
            if minimam == near_zero_big:
                cost = abs(minimam)
        else:
            cost = min(abs(minimam), maximam)*2 + max(abs(minimam), maximam)
        if ans > cost or ans == 0:
            ans = cost
    print(ans)

Fixed submission:

n, k = map(int, input().split())
li = list(map(int, input().split()))
li.append(0)
li.sort()
zero_index = li.index(0)
if zero_index == 0:
    print(li[k])
elif zero_index == len(li) -1:
    print(abs(li[-k-1]))
else:
    near_zero_small = li[zero_index-1]
    near_zero_big = li[zero_index+1]
    li.pop(zero_index)
    ans = 0
    cost = 0
    for i in range(n-k+1):
        minimam = li[i]
        maximam = li[i+k-1]
        if (minimam > 0 and maximam > 0 ):
            if minimam == near_zero_big:
                cost = maximam
        elif (minimam < 0 and maximam < 0 ):
            if minimam == near_zero_big:
                cost = abs(minimam)
        else:
            cost = min(abs(minimam), maximam)*2 + max(abs(minimam), maximam)
        if ans > cost or ans == 0:
            ans = cost
    print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())
 
count = 0
for i in s:
    count+=1
    if i != "1" or count == n:
        print(i)
        break
else:
    print(1)

Fixed submission:

a,b= map(int, input().split())
print((a-1) * (b-1))
Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())

count = 0
for i in s:
  	count += 1
    if i != "1" or (count == n):
        print(i)
        break
else:
    print(1)

Fixed submission:
s = input()
n = int(input())
 
count = 0
for i in s:
    count+=1
    if i != "1" or count == n:
        print(i)
        break
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())

count = 0
for i in s:
  	count += 1
    if i != "1" or count == n:
        print(i)
        break
else:
    print(1)

Fixed submission:
s = input()
n = int(input())
 
count = 0
for i in s:
    count+=1
    if i != "1" or count == n:
        print(i)
        break
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
input(s)
ans = 0
for i in s:
    if i == "+":
        ans += 1
    else:
        ans-=1
print(ans)

Fixed submission:
s = input()
ans = 0
for i in s:
    if i == "+":
        ans += 1
    else:
        ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      for k in range(len(s)):
        if j+k == len(s):
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break


Fixed submission:
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      temp = []
      for k in range(5):
        if j+k == len(s) or len(temp)>=K:
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
mid = (len(li)//2)-1

for i in range(n):
    temp = li[:i] + li[i+1:]
    temp.sort()
    print(temp[mid])

Fixed submission:
n = int(input())
li = list(map(int, input().split()))
mid_id = (len(li)//2)
temp = li.copy()
temp.sort()
mid1 = temp[mid_id-1]
mid2 = temp[mid_id]
for i in li:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)

Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
li = list(map(int, input().split()))

print(min(sum(li[:x]), sum(li[x+1:])))

Fixed submission:
n = int(input())
li = list(map(int, input().split()))
mid_id = (len(li)//2)
temp = li.copy()
temp.sort()
mid1 = temp[mid_id-1]
mid2 = temp[mid_id]
for i in li:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = [0] + A  + [0]
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
for i in range(N):
  ans = sum(cost) - cost[i] - cost[i+1]
  ans += abs(A[i]-A[i+2])
  print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = [0] + A  + [0]
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
cost_sum = sum(cost)
for i in range(N):
  ans = cost_sum - cost[i] - cost[i+1]
  ans += abs(A[i]-A[i+2])
  print(ans)