Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def concentrate(water, sugar):
    if water+sugar == 0:
        return 0
    else:
        return sugar/(water+sugar)


A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
water_list = []
sugar_list = []

max_cont = E/(E+100)

max_water = F//B+1
for i in range(max_water):
    remain = F - B*i
    if remain < 0:
        break
    else:
        j = remain//A
        for k in range(j+1):
            water_list.append(A*k+B*i)

max_sugar = F//D
for i in range(max_sugar):
    tmp = D*i
    remain = F - tmp
    if remain < 0:
        break
    else:
        j = remain//C
        for k in range(j+1):
            sugar_list.append(D*i+C*k)

water_list = sorted(set(water_list))
sugar_list = sorted(set(sugar_list))
print(water_list)

max_tmp = 0
ans = []
for water in water_list:
    for sugar in sugar_list:
        if water+sugar > F:
            break
        else:
            conc = concentrate(water, sugar)
            if conc > max_cont:
                break
            else:
                if max_tmp < conc:
                    max_tmp = conc
                    ans = [water, sugar]
print(sum(ans), ans[1])


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def concentrate(water, sugar):
    if water+sugar == 0:
        return 0
    else:
        return sugar/(water+sugar)


A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
water_list = []
sugar_list = []

max_cont = E/(E+100)

max_water = F//B+1
for i in range(max_water):
    remain = F - B*i
    if remain < 0:
        break
    else:
        j = remain//A
        for k in range(j+1):
            water_list.append(A*k+B*i)

max_sugar = F//D+1
for i in range(max_sugar):
    tmp = D*i
    remain = F - tmp
    if remain < 0:
        break
    else:
        j = remain//C
        for k in range(j+1):
            sugar_list.append(D*i+C*k)

water_list = sorted(set(water_list))
sugar_list = sorted(set(sugar_list))

max_tmp = 0
ans = [0, 0]
for water in water_list:
    for sugar in sugar_list:
        if water+sugar > F:
            break
        else:
            conc = concentrate(water, sugar)
            if conc > max_cont:
                break
            else:
                if max_tmp <= conc:
                    max_tmp = conc
                    ans = [water, sugar]
print(sum(ans), ans[1])
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

seq = 0
ans = 0
for i in range(1, N+1):
    if A[i] == i:
        seq += 1
    else:
        ans += (seq+1)//2
        seq = 0
ans += (seq+1)//2
print(ans)


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

# print(A)

ans = 0
if all(a != 0 for a in A):
    ans = 0
else:
    seq = 0
    for i in range(N):
        if A[i] == 0:
            seq += 1
        else:
            ans += (seq+1)//2
            seq = 0
    ans += (seq+1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
s = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
for c in alpha:
    if c in s:
        continue
    else:
        print(c)
        break


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
s = input()
alpha = [chr(i) for i in range(97, 97+26)]
for c in alpha:
    if c in s:
        continue
    else:
        print(c)
        exit()
print("None")
Buggy python submission (verdict: Runtime Error):
print(sum(sorted(list(map(int,input().split()))[:2]))

Fixed submission:
L = list(map(int,input().split()))
L = sorted(L)
print(sum(L[:2]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

ans = []

l1 = A[0::2]
l2 = A[1::2]
if N % 2 == 0:
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(list(map(str, ans))))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = [A[0]]
for i in range(1, N):
    if i % 2 == 0:
        ans.append(A[i])
    else:
        ans.insert(0, A[i])

if N % 2 == 1:
    ans = ans[::-1]

print(" ".join(list(map(str, ans))))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(list(map(str, ans))))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = [A[0]]
for i in range(1, N):
    if i % 2 == 0:
        ans.append(A[i])
    else:
        ans.insert(0, A[i])

if N % 2 == 1:
    ans = ans[::-1]

print(" ".join(list(map(str, ans))))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(list(map(str, ans))))
Buggy python submission (verdict: Runtime Error):
L=int("".join(map(str,list(map(int,input().split()))))
if L%4==0:
      print("YES")
else:
      print("NO")

Fixed submission:
L=list(map(int,input().split()))
V=int("".join(map(str,L)))
if V%4==0:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def ceil(x):
    return int((-x)//1*(-1))


N, A, B = map(int, input().split())
hp = [int(input()) for _ in range(N)]
diff = A-B


def solve1():
    HP = sorted(hp, reverse=True)
    cnt = 0
    while HP:
        HP = list(map(lambda x: x-B, HP))
        HP[0] -= A-B
        HP = list(filter(lambda x: x > 0, HP))
        HP = sorted(HP, reverse=True)
        cnt += 1
        print(HP)
    print(cnt)


def check(x, HP):
    cnt = 0
    for i in range(N):
        if HP[i]-B*x <= 0:
            break
        else:
            cnt += ceil((HP[i]-B*x)/diff)
    #print("x->", x)
    # print(cnt)
    #print(cnt <= x)
    return cnt <= x


def solve2():
    HP = sorted(hp, reverse=True)
    mi = HP[0]//A
    ma = ceil(HP[0]/B)
    #print("mi,ma->", mi, ma)
    while mi <= ma:
        mid = (mi+ma)//2
        if check(mid, HP):
            ma = mid-1
        else:
            mi = mid+1
    print(mi)


solve2()


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def ceil(x):
    return int((-x)//1*(-1))


N, A, B = map(int, input().split())
hp = [int(input()) for _ in range(N)]
diff = A-B


def check(x, HP):
    cnt = 0
    for i in range(N):
        if HP[i]-B*x <= 0:
            break
        else:
            cnt += ceil((HP[i]-B*x)/diff)
    return cnt <= x


def solve2():
    HP = sorted(hp, reverse=True)
    mi = HP[0]//A
    ma = ceil(HP[0]/B)
    while mi <= ma:
        mid = (mi+ma)//2
        if check(mid, HP):
            ma = mid-1
        else:
            mi = mid+1
    print(mi)


solve2()
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    l = list(input().split())
    for j in range(1, W+1):
        grid[i][j] = l[j-1]

for i in grid:
    print(" ".join(i))


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    for j, c in enumerate(input()):
        grid[i][j+1] = c

for i in grid:
    print("".join(i))
Buggy python submission (verdict: Runtime Error):
import sys


def input(): return sys.stdin.readline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-d[-1])


Fixed submission:
N, K = list(map(int, input().split()))

nums = []
for _ in range(N):
    nums.append(list(map(int, input().split())))

nums = sorted(nums, key=lambda x: x[0])

acc = [0]*N
acc[0] = nums[0][1]
for i in range(1, N):
    acc[i] += acc[i-1]+nums[i][1]


for i in range(N):
    if acc[i] >= K:
        print(nums[i][0])
        exit()
Buggy python submission (verdict: Runtime Error):
def log_2(n):
    t = 0
    while n:
        if n % 2 == 1:
            break
        t += 1
        n //= 2
    return t


def solve(A, B, C)->int:

    s = A+B+C
    odd = log_2(s-C)
    even = log_2(s+A)

    if odd == even:
        return odd
    else:
        return odd+1


A, B, C = map(int, input().split())
A, B, C = sort([A, B, C])

ans = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    ans = 0
elif A == B == C:
    ans = -1
else:
    ans = solve(A, B, C)
print(ans)


Fixed submission:
def log_2(n):
    t = 0
    while n:
        if n % 2 == 1:
            break
        t += 1
        n //= 2
    return t


def solve(A, B, C)->int:

    s = A+B+C
    odd = min(log_2(s-A), log_2(s-B), log_2(s-C))
    even = min(log_2(s+A), log_2(s+B), log_2(s+C))

    if odd == even:
        return odd
    else:
        return odd+1


A, B, C = map(int, input().split())

ans = 0
if A % 2 == 1 or A % 2 == 1 or A % 2 == 1:
    ans = 0
elif A == B == C:
    ans = -1
else:
    ans = solve(A, B, C)
print(ans)
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = int(input())
node = [0]*(N+1)
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    node[a] += 1
    node[b] += 1

if all(x % 2 == 0 for x in node):
    print("YES")
else:
    print("NO")


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
node = [0]*(N+1)
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    node[a] += 1
    node[b] += 1

if all(x % 2 == 0 for x in node):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            printf("GREATER\n");
        }
        else{
            printf("LESS\n");
        }
    }
}


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a = int(input())
b = int(input())
if a == b:
    print("EQUAL")
elif a < b:
    print("LESS")
else:
    print("GREATER")

Buggy python submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d\n",&a);
    scanf("%d\n",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            printf("GREATER\n");
        }
        else{
            printf("LESS\n");
        }
    }
}


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a = int(input())
b = int(input())
if a == b:
    print("EQUAL")
elif a < b:
    print("LESS")
else:
    print("GREATER")

Buggy python submission (verdict: Runtime Error):
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d\n",&a);
    scanf("%d\n",&b);
    if(a==b){
        printf("EQUAL\n");
    }else{
        if (a>b){
            print("GREATER\n");
        }
        else{
            pritn("LESS\n");
        }
    }
}


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a = int(input())
b = int(input())
if a == b:
    print("EQUAL")
elif a < b:
    print("LESS")
else:
    print("GREATER")
Buggy python submission (verdict: Time Limit Exceeded):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X = int(input())

ans = float('inf')


def bfs(s, g):
    Q = [[s, 0]]

    while Q:
        p = Q.pop(0)
        time = p[1]
        cur = p[0]
        if abs(cur) > X:
            continue
        if cur == g:
            return time
        else:
            time += 1
            Q.append([cur+time, time])
            Q.append([cur-time, time])
            Q.append([cur, time])


print(bfs(0, X))


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X = int(input())

ans = float('inf')
pos = 0
time = 0
while pos < X:
    time += 1
    pos = (time)*(time+1)//2

diff = pos - X
print(time)

Buggy python submission (verdict: Time Limit Exceeded):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X = int(input())

ans = float('inf')


def bfs(s, g):
    Q = [[s, 0]]

    while Q:
        p = Q.pop(0)
        time = p[1]
        if p[0] == g:
            return time
        else:
            time += 1
            Q.append([p[0]+time, time])
            Q.append([p[0]-time, time])
            Q.append([p[0], time])


print(bfs(0, X))


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X = int(input())

ans = float('inf')
pos = 0
time = 0
while pos < X:
    time += 1
    pos = (time)*(time+1)//2

diff = pos - X
print(time)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())

T = sorted(T)
j = 0
ans = 0
while j < N:
    t = T[j]
    ret = bisect.bisect_right(T, t+K, lo=j, hi=N)
    if ret-j > C:
        ret = C
    j += ret-j
    ans += 1
print(ans)


Fixed submission:
import bisect
N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())

T = sorted(T)
j = 0
ans = 0
while j < N:
    t = T[j]
    ret = bisect.bisect_right(T, t+K, lo=j, hi=min(j+C, N))
    if ret-j > C:
        ret = C
    j += ret-j
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B > N or y_A+y_B > N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")


Fixed submission:
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B >= N or y_A+y_B >= N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")


Fixed submission:
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B >= N or y_A+y_B >= N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

odd = len(list(filter(lambda x: x % 2 != 0, A)))
even = N - odd

ans = "YES"


if odd == 1 and even == 0:
    odd = odd
elif odd % 2 == 1:
    ans = "NO"
else:
    even += odd//2
    while True:
        if even == 1:
        if even % 2 == 1:
            ans = "NO"
            break
        even //= 2
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

odd = len(list(filter(lambda x: x % 2 != 0, A)))
even = N - odd

ans = "YES"


if odd == 1 and even == 0:
    odd = odd
elif odd % 2 == 1:
    ans = "NO"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def floor(a, b):
    return (-a)//b*(-1)


def inc_list(i, l):
    for j in range(i):
        l[j] += 1
    return l


def inc_mult(i, n, l):
    for _ in range(n):
        l = inc_list(i, l)
    return l


N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0
for i in reversed(range(N)):
    a = A.pop(-1)
    b = B.pop(-1)
    inc = floor(a, b)*b - a
    A = inc_mult(i, inc, A)
    ans += inc

print(ans)


Fixed submission:
def floor(a, b):
    return (-a)//b*(-1)


N = int(input())
A = []
B = []
total_add = 0
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0
for i in reversed(range(N)):
    a = A.pop(-1)
    a += total_add
    b = B.pop(-1)
    inc = b*floor(a, b)-a
    total_add += inc

print(total_add)

Buggy python submission (verdict: Time Limit Exceeded):
def floor(a, b):
    return (-a)//b*(-1)


def inc_list(i, l):
    if i >= len(l):
        print("err")
        return l
    for j in range(i):
        l[j] += 1
    return l


def inc_mult(i, n, l):
    for _ in range(n):
        l = inc_list(i, l)
    return l


N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0
for i in reversed(range(N)):
    a = A[i]
    b = B[i]
    inc = floor(a, b)*b - a
    A = inc_mult(i, inc, A)
    ans += inc

print(ans)


Fixed submission:
def floor(a, b):
    return (-a)//b*(-1)


N = int(input())
A = []
B = []
total_add = 0
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0
for i in reversed(range(N)):
    a = A.pop(-1)
    a += total_add
    b = B.pop(-1)
    inc = b*floor(a, b)-a
    total_add += inc

print(total_add)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)


Fixed submission:
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import heapq
from math import sqrt
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def calc(b1, b2):
    x1, y1, r1 = b1
    x2, y2, r2 = b2
    d = sqrt((x1-x2)**2+(y1-y2)**2)
    return max(d-(r1+r2), 0)


sx, sy, gx, gy = map(int, input().split())
N = int(input())
barriers = [[sx, sy, 0]] + [list(map(int, input().split()))
                            for _ in range(N)]+[[gx, gy, 0]]

mat = [[0]*(N+2) for _ in range(N+2)]

for row in range(N+2):
    for col in range(row+1, N+2):
        d = calc(barriers[row], barriers[col])
        mat[row][col] = d
        mat[col][row] = d

# 視点からの距離
dist = [float('inf')]*(N+2)
dist[0] = 0

# 最短経路での一つ前のノード
prev = defaultdict(lambda: None)

Q = []
# Q->[dist from　start,node])
heapq.heappush(Q, (0, 0))

while Q:
    dist_to_node, node = heapq.heappop(Q)
    if dist[node] < dist_to_node:
        continue
    else:
        for v in range(N+2):
            weight = mat[node][v]
            alt = dist_to_node+weight
            if dist[v] > alt:
                dist[v] = alt
                prev[v] = node
                heapq.heappush(Q, (alt, v))
print(dist[-1])


Fixed submission:
N, x = map(int, input().split())
l = list(map(int, input().split()))

before = sum(l)
l[0] = min(x, l[0])
for i in range(1, N):
    s = l[i-1]+l[i]
    if s > x:
        l[i] = x-l[i-1]

print(before-sum(l))