Buggy python submission (verdict: Runtime Error):
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-2]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, c = list(map(int, input().split()))
for i in range(n):
    xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-2]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, c = list(map(int, input().split()))
for i in range(n):
    xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-2]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = np.array(sushi1) + np.array(max2[::-1])
ans2 = np.array(sushi2) + np.array(max1[::-1])
print(max(0, ans1, ans2))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Time Limit Exceeded):
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0]*(n+1), [0]*(n+1)
for i in range(n):
    max1[i+1] = max(sushi1[i] - x[i], max1[i])
    max2[i+1] = max(sushi2[i] - (c - x[n-i-1]), max2[i])
sushi1.reverse()
sushi2.reverse()
sushi1.append(0)
sushi2.append(0)
ans = 0 
for i in range(n+1):
    a1 = max1[i] + sushi2[i]
    a2 = max2[i] + sushi1[i]
    ans = max(ans, a1, a2)
print(ans)

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Time Limit Exceeded):
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0]*(n+1), [0]*(n+1)
for i in range(n):
    max1[i+1] = max(sushi1[i] - x[i], max1[i])
    max2[i+1] = max(sushi2[i] - (c - x[n-i-1]), max2[i])
sushi1.reverse()
sushi2.reverse()
sushi1.append(0)
sushi2.append(0)
ans = 0 
for i in range(n+1):
    a1 = max1[i] + sushi2[i]
    a2 = max2[i] + sushi1[i]
    ans = max(ans, a1, a2)
print(ans)

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Time Limit Exceeded):
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0], [0]
for i in range(n):
    max1.append(max(sushi1[i] - x[i], max1[i]))
    max2.append(max(sushi2[i] - (c - x[n-i-1]), max2[i]))
sushi1.reverse()
sushi2.reverse()
sushi1.append(0)
sushi2.append(0)
ans = []
for i in range(n+1):
    ans.append(max1[i]+sushi2[i])
    ans.append(max2[i]+sushi1[i])
ans.append(0)
print(max(ans))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0], [0]
for i in range(n):
    max1.append(max(sushi1[i] - x[i], max1[i]))
    max2.append(max(sushi2[i] - (c - x[n-i-1]), max2[i]))
def ans1(i):
    if i < 0:
        return 0
    elif i == 0:
        return max2[n]
    ans = max2[n-i] + sushi1[i-1]
    return max(ans, ans1(i-1))
def ans2(i):
    if i < 0:
        return 0
    elif i == 0:
        return max1[n]
    ans = max1[n-i] + sushi2[i-1]
    return max(ans, ans2(i-1))
print(max(ans1(n), ans2(n)))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0], [0]
for i in range(n):
    max1.append(max(sushi1[i] - x[i], max1[i]))
    max2.append(max(sushi2[i] - (c - x[n-i-1]), max2[i]))
def ans1(i):
    if i < 0:
        return 0
    elif i == 0:
        return max2[n]
    ans = max2[n-i] + sushi1[i-1]
    return max(ans, ans1(i-1))
def ans2(i):
    if i < 0:
        return 0
    elif i == 0:
        return max1[n]
    ans = max1[n-i] + sushi2[i-1]
    return max(ans, ans1(i-1))
print(max(ans1(n), ans2(n)))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Time Limit Exceeded):
n, c = list(map(int, input().split()))
sushi1 = []
sushi2 = []
c1 = []
c2 = []
c3 = []
c4 = []
k1 = 0
k2 = 0
for i in range(n):
    x, v = list(map(int, input().split()))
    sushi1.append((x, v))
    sushi2.append((c-x, v))
sushi1.sort()
sushi2.sort()
for j in range(n):
    k1 += sushi1[j][1]
    k2 += sushi2[j][1]
    c1.append(k1-sushi1[j][0])
    c2.append(k2-sushi2[j][0])
for k in range(n-1):
    c3.append(c1[k]+max(c2[:n-k-1])-sushi1[k][0])
    c4.append(c2[k]+max(c1[:n-k-1])-sushi2[k][0])
print(max(c1+c2+c3+c4+[0]))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n, c = list(map(int, input().split()))
sushi1 = []
sushi2 = []
c1 = []
c2 = []
c3 = []
c4 = []
k1 = 0
k2 = 0
for i in range(n):
    x, v = list(map(int, input().split()))
    sushi1.append((x, v))
    sushi2.append((c-x, v))
sushi1.sort()
sushi2.sort()
for j in range(n):
    k1 += sushi1[j][1]
    k2 += sushi2[j][1]
    c1.append(k1-sushi1[j][0])
    c2.append(k2-sushi2[j][0])
for k in range(n):
    c3.append(c1[k]+max(c2[:n-k-1])-sushi1[k][0])
    c4.append(c2[k]+max(c1[:n-k-1])-sushi2[k][0])
print(max(c1+c2+c3+c4+[0]))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n, c = list(map(int, input().split()))
sushi1 = []
sushi2 = []
c1 = []
c2 = []
c3 = []
c4 = []
k1 = 0
k2 = 0
for i in range(n):
    x, v = list(map(int, input().split()))
    sushi1.append((x, v))
    sushi2.append((c-x, v))
sushi1.sort()
sushi2.sort()
for j in range(n):
    k1 += sushi1[j][1]
    k2 += sushi2[j][1]
    c1.append(k1-sushi1[j][0])
    c2.append(k2-sushi2[j][0])
for k in range(n):
    c3.append(c1[k]+max(c2[:n-k])-sushi1[k][0])
    c4.append(c2[k]+max(c1[:n-k])-sushi2[k][0])
print(max(c1+c2+c3+c4, 0))

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n, c = list(map(int, input().split()))
sushi1 = []
sushi2 = []
c1 = []
c2 = []
c3 = []
c4 = []
k1 = 0
k2 = 0
for i in range(n):
    x, v = list(map(int, input().split()))
    sushi1.append((x, v))
    sushi2.append((c-x, v))
sushi1.sort()
sushi2.sort()
for j in range(n):
    k1 += sushi1[j][1]
    k2 += sushi2[j][1]
    c1.append(k1-sushi1[j][0])
    c2.append(k2-sushi2[j][0])
for k in range(n):
    c3.append(c1[k]+max(c2[:n-k])-sushi1[k][0])
    c4.append(c2[k]+max(c1[:n-k])-sushi2[k][0])
print(max(c1+c2+c3+c4, 0)

Fixed submission:
import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))