Buggy python submission (verdict: Time Limit Exceeded):
N, C = list(map(int,input().split()))
x_list = [0]
v_list = []

for i in range(N):
    x, v = list(map(int,input().split()))
    x_list.append(x)
    v_list.append(v)

max_c = 0

# 時計回りスタート
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
#        print(c)
        if max_c < c:
            max_c = c
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
#        print(c)
        if max_c < c:
            max_c = c
            
# 反時計回りスタート
# xとvの置き換えることで対応する
x_list = [x_list[0]] + [C-x for x in x_list[1:][::-1]]
v_list = v_list[::-1]
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
#        print(c)
        if max_c < c:
            max_c = c
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
#        print(c)
        if max_c < c:
            max_c = c

            
print(max_c)

Fixed submission:
# kopipe
from numpy import array as n

N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
a = max(n(r1)+n(l2[::-1]))
b = max(n(r2)+n(l1[::-1]))
print(max(a,b))

Buggy python submission (verdict: Time Limit Exceeded):
N, C = list(map(int,input().split()))
x_list = [0]
v_list = []

for i in range(N):
    x, v = list(map(int,input().split()))
    x_list.append(x)
    v_list.append(v)

max_c = 0

threshold_x = max(x_list)

# 時計回りスタート
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    th = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
        th += x_tmp[j+1] - x_tmp[j]
        if th > threshold_x:
            break
#        print(c)
        if max_c < c:
            max_c = c
    if th > threshold_x:
        break
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
        th += x_tmp[j+1] - x_tmp[j]
        if th > threshold_x:
            break
#        print(c)
        if max_c < c:
            max_c = c
    if th > threshold_x:
        break
            
# 反時計回りスタート
# xとvの置き換えることで対応する
x_list = [x_list[0]] + [C-x for x in x_list[1:][::-1]]
v_list = v_list[::-1]
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    th = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
        th += x_tmp[j+1] - x_tmp[j]
        if th > threshold_x:
            break
#        print(c)
        if max_c < c:
            max_c = c
    if th > threshold_x:
        break
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
        th += x_tmp[j+1] - x_tmp[j]
        if th > threshold_x:
            break
#        print(c)
        if max_c < c:
            max_c = c
    if th > threshold_x:
        break

            
print(max_c)

Fixed submission:
# kopipe
from numpy import array as n

N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
a = max(n(r1)+n(l2[::-1]))
b = max(n(r2)+n(l1[::-1]))
print(max(a,b))

Buggy python submission (verdict: Time Limit Exceeded):
N, C = list(map(int,input().split()))
x_list = [0]
v_list = []

for i in range(N):
    x, v = list(map(int,input().split()))
    x_list.append(x)
    v_list.append(v)

max_c = 0

# 時計回りスタート
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
#        print(c)
        if max_c < c:
            max_c = c
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
#        print(c)
        if max_c < c:
            max_c = c
            
# 反時計回りスタート
# xとvの置き換えることで対応する
x_list = [x_list[0]] + [C-x for x in x_list[1:][::-1]]
v_list = v_list[::-1]
for i in range(N):
#    print("------")
#    print(i)
    c = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
#        print(c)
        if max_c < c:
            max_c = c
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
#        print(c)
        if max_c < c:
            max_c = c

            
print(max_c)

Fixed submission:
# kopipe
from numpy import array as n

N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
a = max(n(r1)+n(l2[::-1]))
b = max(n(r2)+n(l1[::-1]))
print(max(a,b))

Buggy python submission (verdict: Runtime Error):
max_c = 0

for i in range(N):
#    print("------")
#    print(i)
    c = 0
    x_tmp = x_list.copy()
    v_tmp = v_list.copy()
    for j in range(i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j+1] - x_tmp[j]
#        print(c)
        if max_c < c:
            max_c = c
    
    x_tmp = x_tmp[i:]
    v_tmp = v_tmp[i:]
    
    v_tmp = v_tmp[::-1]
    
    x_tmp = [x_tmp[0]+C] + x_tmp[1:][::-1]
    
#    print(x_tmp)
#    print(v_tmp)
    
    for j in range(N - i):
        c += v_tmp[j]
#        print(v_tmp[j],"を食べた")
        c -= x_tmp[j] - x_tmp[j+1]
#        print(c)
        if max_c < c:
            max_c = c

Fixed submission:
# kopipe
from numpy import array as n

N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
a = max(n(r1)+n(l2[::-1]))
b = max(n(r2)+n(l1[::-1]))
print(max(a,b))