Buggy python submission (verdict: Runtime Error):
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax[0]:
        cummax = (cum - a, a)
    maxes[i]=cummax
    cums[i+1]=cum

# print("cummax: {}, cums: {}".format(cummax, cums))
if cummax[0] == 0:
    print(0)
    exit(1)

resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum, x = (0, 0) if i == 0 else maxes[i-1]
    obsum = cums[N] - cums[i] - (C-b)
    # print("len oa: {} len ob: {} oa sum: {} ob sum: {} score: {}".format(x, C-b, oasum, obsum, obsum + oasum - min(C-b, x)))
    resmax = max(resmax, obsum + oasum - min(C-b, x))
    # print(resmax)

# print(maxes[N-1])
resmax = max(resmax, maxes[N-1][0])
print(resmax)


Fixed submission:
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))

Buggy python submission (verdict: Runtime Error):
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax[0]:
        cummax = (cum - a, a)
    maxes[i]=cummax
    cums[i+1]=cum

# print("cummax: {}, cums: {}".format(cummax, cums))
if cummax[0] == 0:
    print(0)
    exit(1)

resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum, x = (0, 0) if i == 0 else maxes[i-1]
    obsum = cums[N] - cums[i] - (C-b)
    # print("len oa: {} len ob: {} oa sum: {} ob sum: {} score: {}".format(x, C-b, oasum, obsum, obsum + oasum - min(C-b, x)))
    resmax = max(resmax, obsum + oasum - min(C-b, x))
    # print(resmax)

# print(maxes[N-1])
resmax = max(resmax, maxes[N-1][0])
print(resmax)


Fixed submission:
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))

Buggy python submission (verdict: Runtime Error):
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax[0]:
        cummax = (cum - a, a)
    maxes[i]=cummax
    cums[i+1]=cum

print("cummax: {}, cums: {}".format(cummax, cums))
if cummax[0] == 0:
    print(0)
    exit(1)

resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum, x = (0, 0) if i == 0 else maxes[i-1]
    obsum = cums[N] - cums[i] - (C-b)
    print("len oa: {} len ob: {} oa sum: {} ob sum: {} score: {}".format(x, C-b, oasum, obsum, obsum + oasum - min(C-b, x)))
    resmax = max(resmax, obsum + oasum - min(C-b, x))
    # print(resmax)

print(maxes[N-1])
resmax = max(resmax, maxes[N-1][0])
print(resmax)


Fixed submission:
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))

Buggy python submission (verdict: Runtime Error):
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
maxi = 0
cummax = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if cum - a > cummax[0]:
        maxi = i
        cummax = (cum - a, a)
    maxes[i]=cummax
    cums[i+1]=cum

if cummax[0] == 0:
    print(0)
    exit(1)

# print("cummax: {}, cum: {}".format(cummax, cum))
resmax = 0
for i, [b, v] in enumerate(inarr):
    sc, x = (0, 0) if i == 0 else maxes[i-1]
    obsum = cums[N] - cums[i] - (C-b)
    # print("len oa: {} len ob: {} oa sum: {} ob sum: {}".format(x, C-b, sc, obsum))
    resmax = max(resmax, obsum + sc - min(C-b, x))
    # print(resmax)

resmax = max(resmax, maxes[N-1][0])
print(resmax)


Fixed submission:
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))

Buggy python submission (verdict: Runtime Error):
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[0]*N
cums=[0]*(N+1)
cum = 0
maxi = 0
cummax = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if cum - a > cummax[0]:
        maxi = i
        cummax = (cum - a, a)
    maxes[i]=cummax
    cums[i+1]=cum

if cummax[0] == 0:
    print(0)
    exit(1)

# print("cummax: {}, cum: {}".format(cummax, cum))
resmax = 0
for i, [b, v] in enumerate(inarr):
    sc, x = (0, 0) if i == 0 else maxes[i-1]
    obsum = cums[N] - cums[i] - (C-b)
    # print("len oa: {} len ob: {} oa sum: {} ob sum: {}".format(x, C-b, sc, obsum))
    resmax = max(resmax, obsum + sc - min(C-b, x))
    # print(resmax)

resmax = max(resmax, maxes[N-1][0])
print(resmax)


Fixed submission:
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes1=[(0, 0)]*N
maxes2=[(0, 0)]*N
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes1[i]=cummax1
    maxes2[i]=cummax2
    cums[i+1]=cum

# print("{}".format(maxes1))
resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes1[i-1]
    oasum2, x = (0, 0) if i == 0 else maxes2[i-1]
    obsum = cums[N] - cums[i]
    resmax = max(resmax, obsum + oasum1 - 2*(C-b), obsum + oasum2 - (C-b))
    # print(resmax)

# print(maxes1[N-1])
print(max(resmax, maxes1[N-1][0], 0))