Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split()) 
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

ans = 0
for i in range(N+1):
    for j in range(N+1-i):
        ans = max(ans, Sum_left[i] + Sum_right[j] - XV[i][0] - 2 * (C - XV[N+1-j][0]), Sum_left[i] + Sum_right[j] - 2 * XV[i][0] - (C - XV[N+1-j][0]))

print(ans)

Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,C = map(int,input().split()) 
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

ans = 0
for i in range(N+1):
    for j in range(N+1-i):
        ans = max(ans, Sum_left[i] + Sum_right[j] - XV[i][0] - 2 * (C - XV[N+1-j][0]), Sum
_left[i] + Sum_right[j] - 2 * XV[i][0] - (C - XV[N+1-j][0]))

print(ans)


Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,C = map(int,input().split()) 
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

print(XV)

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

ans = 0
for i in range(N+1):
    for j in range(N+1-i):
        ans = max(ans, Sum_left[i] + Sum_right[j] - XV[i][0] - 2 * (C - XV[N+1-j][0]), Sum
_left[i] + Sum_right[j] - 2 * XV[i][0] - (C - XV[N+1-j][0]))

print(ans)

Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,C = map(int,input().split())
XV = [0,0] + [[int(i) for i in input().split()] for _ in range(N)] + [C,0]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

ans = 0
for i in range(N+1):
    for j in range(N+1-i):
        ans = max(ans, Sum_left[i] + Sum_right[j] - XV[i][0] - 2 * (C - XV[N+1-j][0]), Sum
_left[i] + Sum_right[j] - 2 * XV[i][0] - (C - XV[N+1-j][0]))

print(ans)


Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
XV = [[int(i) for i in input().split()] for _ in range(N)]
ans = 0

Sum_left = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - XV[j][0]
    else:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - (XV[j][0] - XV[j-1][0])
    ans = max(ans,Sum_left[0][j+1])

for i in range(N):
    if i == 0:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (C - XV[-i-1][0])
    else:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (XV[-i][0] - XV[-i-1][0])

for i in range(1,N):
    if Sum_left[i][0] < 0:
        continue
    for j in range(1,N+1-i):
        if Sum_left[0][j] < 0:
            continue
        Sum_left[i][j] = Sum_left[i][0] + Sum_left[0][j]
        ans = max(ans,Sum_left[i][j])



Sum_right = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (C-XV[-1-j][0])
    else:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (XV[-j][0] - XV[-1-j][0])
    ans = max(ans,Sum_right[0][j+1])

for i in range(N):
    if i == 0:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * XV[i][0]
    else:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * (XV[i][0] - XV[i-1][0])

for i in range(1,N):
    if Sum_right[i][0] < 0:
        continue
    for j in range(1,N+1-i):
        if Sum_right[0][j] < 0:
            continue
        Sum_right[i][j] = Sum_right[i][0] + Sum_right[0][j]
        ans = max(ans,Sum_right[i][j])

print(ans)

Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = sys.stdin.readlines()

N,C = map(int,s[0].split())
XV = [[int(j) for j in s[i+1].split()] for i in range(N)]
ans = 0


Sum_left = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - XV[j][0]
    else:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - (XV[j][0] - XV[j-1][0])
    ans = max(ans,Sum_left[0][j+1])

for i in range(N):
    if i == 0:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (C - XV[-i-1][0])
    else:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (XV[-i][0] - XV[-i-1][0])

for i in range(1,N):
    for j in range(1,N+1-i):
        Sum_left[i][j] = Sum_left[i][0] + Sum_left[0][j]
        ans = max(ans,Sum_left[i][j])



Sum_right = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (C-XV[-1-j][0])
    else:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (XV[-j][0] - XV[-1-j][0])
    ans = max(ans,Sum_right[0][j+1])

for i in range(N):
    if i == 0:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * XV[i][0]
    else:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * (XV[i][0] - XV[i-1][0])

for i in range(1,N):
    for j in range(1,N+1-i):
        Sum_right[i][j] = Sum_right[i][0] + Sum_right[0][j]
        ans = max(ans,Sum_right[i][j])

print(ans)

Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
XV = [[int(i) for i in input().split()] for _ in range(N)]
ans = 0


Sum_left = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - XV[j][0]
    else:
        Sum_left[0][j+1] = Sum_left[0][j] + XV[j][1] - (XV[j][0] - XV[j-1][0])
    ans = max(ans,Sum_left[0][j+1])

for i in range(N):
    if i == 0:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (C - XV[-i-1][0])
    else:
        Sum_left[i+1][0] = Sum_left[i][0] + XV[-i-1][1] - 2 * (XV[-i][0] - XV[-i-1][0])

for i in range(1,N):
    for j in range(1,N+1-i):
        Sum_left[i][j] = Sum_left[i][0] + Sum_left[0][j]
        ans = max(ans,Sum_left[i][j])



Sum_right = [[0]*(N+1) for _ in range(N+1)]

for j in range(N):
    if j == 0:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (C-XV[-1-j][0])
    else:
        Sum_right[0][j+1] = Sum_right[0][j] + XV[-1-j][1] - (XV[-j][0] - XV[-1-j][0])
    ans = max(ans,Sum_right[0][j+1])

for i in range(N):
    if i == 0:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * XV[i][0]
    else:
        Sum_right[i+1][0] = Sum_right[i][0] + XV[i][1] - 2 * (XV[i][0] - XV[i-1][0])

for i in range(1,N):
    for j in range(1,N+1-i):
        Sum_right[i][j] = Sum_right[i][0] + Sum_right[0][j]
        ans = max(ans,Sum_right[i][j])

print(ans)

Fixed submission:
N,C = map(int,input().split())
XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]]

Sum_left = [0] * (N+1)
Sum_right = [0] * (N+1)
for i in range(N):
    Sum_left[i+1] = Sum_left[i] + XV[i+1][1]
    Sum_right[i+1] = Sum_right[i] + XV[N-i][1]

Sum_right_maxA = [0] * (N+1)
Sum_right_maxB = [0] * (N+1)
for i in range(1,N+1):
    Sum_right_maxA[i] = max(Sum_right_maxA[i-1], Sum_right[i] - 2 * (C - XV[N+1-i][0]))
    Sum_right_maxB[i] = max(Sum_right_maxB[i-1], Sum_right[i] - (C - XV[N+1-i][0]))

ans = 0
for i in range(N+1):
    ans = max(ans, Sum_left[i] + Sum_right_maxA[N-i] - XV[i][0], Sum_left[i] + Sum_right_maxB[N-i] - 2*XV[i][0])
print(ans)