stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int main() 

{

	int sx,sy,tx,ty,ssx,ssy,ttx,tty;

	while(~scanf("%d%d%d%d",&sx,&sy,&tx,&ty))

	{

		ssx=sx;

		ssy=sy;

		//ttx=tx;

		//tty=ty;

		while(ssy<ty)

		{

			ssy++;

			cout<<'U';

		}

		while(ssx<tx)

		{

			ssx++;

			cout<<'R';

		}

		while(ssy>sy)

		{

			ssy--;

			cout<<'D';

		}

		while(ssx>sx)

		{

			ssx--;

			cout<<'L';

		}

		

		ssx--;

		cout<<'L';

		while(ssy<ty+1)

		{

			ssy++;

			cout<<'U';

		}

		while(ssx<tx)

		{

			ssx++;

			cout<<'R';

		}

		ssy--;

		cout<<'D';

		ssx++;

		cout<<'R';

		while(ssy>sy-1)

		{

			ssy--;

			cout<<'D';

		}

		while(ssx>sx)

		{

			ssx--;

			cout<<'L';

		}

		cout<<'U'<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.192859316146954x):
#include<cstdio>//https://vjudge.net/contest/215848#overview

#include<cmath>

#include<malloc.h>

#include<stdlib.h>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	int sx,sy,tx,ty;

	while(~scanf("%d %d %d %d",&sx,&sy,&tx,&ty))

	{

		int a,b,c,d,e,f,g,k;

		a=tx-sx;b=ty-sy;c=a+1;d=b+1;

		e=a;f=b;g=c;k=d;

		while(b--)

		{

			printf("U");

		}

		while(a--)

		{

			printf("R");

		}//第一次到达终点 

		while(f--)

		{

			printf("D");

		}

		while(e--)

		{

			printf("L");

		}//第一次回到起点 

		printf("L");

		while(d--)

		{

			printf("U");

		}

		while(c--)

		{

			printf("R");

		}

		printf("DR");//第二次到达终点 

		while(k--)

		{

			printf("D");

		}

		while(g--)

		{

			printf("L");

		}

		printf("U");//第二次回到起点 

		printf("\n");

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

using namespace std;

int main()

{

    int sx,sy,tx,ty;

    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);

    for(int i=1;i<=(ty-sy);i++)printf("U");

    for(int i=1;i<=(tx-sx);i++)printf("R");

    for(int i=1;i<=(ty-sy);i++)printf("D");

    for(int i=1;i<=(tx-sx);i++)printf("L");

    printf("L");

    for(int i=1;i<=(ty-sy)+1;i++)printf("U");

    for(int i=1;i<=(tx-sx)+1;i++)printf("R");

    printf("D");

    printf("R");

    for(int i=1;i<=(ty-sy)+1;i++)printf("D");

    for(int i=1;i<=(tx-sx)+1;i++)printf("L");

    printf("U\n");

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.055845391680782x):
#include<cstdio>

#include<string.h>

#include<math.h>

using namespace std;

void move(int d, char ch)

{

    while(d)

    {

        printf("%c",ch);

        d--;

    }

}

int main()

{

    int x1,x2,y1,y2,x,y,i;

    while(scanf("%d %d %d %d",&x1,&y1,&x2,&y2)!=EOF)

    {

        int x=x2-x1;

        int y=y2-y1;

        for(i=1;i<=4;i++)

        {

            if(i==1)

            {

                move(y,'U');

                move(x,'R');

            }

            else if(i==2)

            {

                move(y,'D');

                move(x,'L');

            }

            else if(i==3)

            {

                printf("L");

                move(y+1,'U');

                move(x+1,'R');

                printf("D");

            }

            else

            {

                printf("R");

                move(y+1,'D');

                move(x+1,'L');

                printf("U");

            }

        }

        printf("\n");

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;



int main(){

    int a,b,c,d;

    cin>>a>>b>>c>>d;

    for(int x=0; x<d-b; x++){

        cout<<"U";

    }

    for(int x=0; x<c-a; x++){

        cout<<"R";

    }

    for(int x=0; x<d-b; x++){

        cout<<"D";

    }

    for(int x=0; x<c-a+1; x++){

        cout<<"L";

    }

    for(int x=0; x<d-b+1; x++){

        cout<<"U";

    }

    for(int x=0; x<c-a+1; x++){

        cout<<"R";

    }

    cout<<"DR";

    for(int x=0; x<d-b+1; x++){

        cout<<"D";

    }

    for(int x=0; x<c-a+1; x++){

        cout<<"L";

    }

    cout<<"U";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.104017559704009x):
#include<cstdio>

#include<string.h>

#include<math.h>

using namespace std;

void move(int d, char ch)

{

    while(d)

    {

        printf("%c",ch);

        d--;

    }

}

int main()

{

    int x1,x2,y1,y2,x,y,i;

    while(scanf("%d %d %d %d",&x1,&y1,&x2,&y2)!=EOF)

    {

        int x=x2-x1;

        int y=y2-y1;

        for(i=1;i<=4;i++)

        {

            if(i==1)

            {

                move(y,'U');

                move(x,'R');

            }

            else if(i==2)

            {

                move(y,'D');

                move(x,'L');

            }

            else if(i==3)

            {

                printf("L");

                move(y+1,'U');

                move(x+1,'R');

                printf("D");

            }

            else

            {

                printf("R");

                move(y+1,'D');

                move(x+1,'L');

                printf("U");

            }

        }

        printf("\n");

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<algorithm>

using namespace std;

int main(){

    int a,b,c,n;

    while(cin>>a>>b>>c,a||b||c){

        cin>>n;

        int f[300];

        fill(f,f+300,2);

        int m=a+b+c;

        int x[1000],y[1000],z[1000];

        bool r[1000];

        for(int i=0;i<n;i++){

            cin>>x[i]>>y[i]>>z[i]>>r[i];

            x[i]--;y[i]--;z[i]--;

        }





        int cnt=0;

        while(cnt<100000){



            for(int i=0;i<n;i++){

                int a=x[i],b=y[i],c=z[i];

                bool Flag=r[i];

                if(Flag){



                    f[a]=f[b]=f[c]=1;

                }

                else{

                    if(f[b]==1&&f[c]==1){



                        f[a]=0;

                    }

                    if(f[a]==1&&f[c]==1){



                        f[b]=0;

                    }

                    if(f[a]==1&&f[b]==1){



                        f[c]=0;

                    }

                }

            }

            cnt++;

        }

        for(int i=0;i<m;i++)cout<<f[i]<<endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.2897648873340657x):
#include<bits/stdc++.h>

using namespace std;

bool solve(){

    int A,B,C,N,t[1000][3],r[1000];

    cin>>A>>B>>C;

    if(A==0&&B==0&&C==0)return false;

    cin>>N;

    for(int i=0;i<N;i++){

        for(int j=0;j<3;j++){

            cin>>t[i][j];

            t[i][j]--;

        }

        cin>>r[i];

    }



    int S[1000]={0};

    for(int _=0;_<N;_++){

        for(int i=0;i<N;i++){

            if(r[i]){

                for(int j=0;j<3;j++){

                    S[t[i][j]]=1;

                }

            }

            else{

                int sum=0;

                for(int j=0;j<3;j++){

                    if(S[t[i][j]]==1)sum++;

                }

                if(sum!=2)continue;

                for(int j=0;j<3;j++){

                    if(S[t[i][j]]!=1)S[t[i][j]]=-1;

                }

            }

        }

    }



    for(int i=0;i<A+B+C;i++){

        if(S[i]==-1)cout<<0<<endl;

        else if(S[i])cout<<1<<endl;

        else cout<<2<<endl;

    }

    return true;

}



int main(){

    while(solve());

}
// Slower C++ solution:
#include<cstdio>  

#include<cmath>  

#include<iostream>  

#include<cstring>  

#include<iostream>  

#include<cstdlib>  

#include<string>  

using namespace std;  

#define LL long long   

const int MaxN = 1e5 + 7;  

LL a[MaxN], b[MaxN];    

LL x[MaxN], v[MaxN];  

  

int main()  

{  

    LL n, c;  

    scanf("%lld %lld", &n, &c);  

    for(int i = 1; i <= n; i++)   

        scanf("%lld %lld", &x[i], &v[i]);  

      

    for(LL i = 1; i <= n; i++)   

        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);  // 顺时针走到i点时的能量  

    x[n + 1] = c;  

    for(LL i = n; i >= 1; i--)   

        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]);  // 逆时针走到i点时的能量  

  

    for(LL i = 2; i <= n; i++)   

        a[i] = max(a[i-1], a[i]);  //走或者不走（和走之前的值进行比较）  

    for(LL i = n-1; i >= 1; i--)   

        b[i] = max(b[i], b[i + 1]);  

  

    LL ans = 0;  

    for(LL i = 1; i <= n; i++) {  

        ans = max(ans, a[i] - x[i] + b[i + 1]);  // 顺时针走后并返回一次的值  

        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);  // 逆时针走后返回一次的值  

        ans = max(ans, a[i]);  // 顺时针的最大值  

        ans = max(ans, b[i]); //逆时针的最大值  

    }  

  

    printf("%lld\n", ans);  

} 

// Faster C++ solution for the same problem (measured speedup: 5.184021716017744x):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

typedef long long ll;

int n;

ll rod;

struct Sushi{ll pos,val;}poi[MAXN+5];

ll a[MAXN+5],b[MAXN+5];

int main()

{

	scanf("%d%lld",&n,&rod);

	for(int i=1;i<=n;i++)

		scanf("%lld%lld",&poi[i].pos,&poi[i].val);

	poi[n+1].pos=rod;poi[n+1].val=0;

	for(int i=1;i<=n;i++)

		a[i]=a[i-1]-(poi[i].pos-poi[i-1].pos)+poi[i].val;

	for(int i=n;i>=1;i--)

		b[i]=b[i+1]-(poi[i+1].pos-poi[i].pos)+poi[i].val;

	for(int i=2;i<=n;i++)

		a[i]=max(a[i],a[i-1]);

	for(int i=n-1;i>=1;i--)

		b[i]=max(b[i],b[i+1]);

	ll ans=0;

	for(int i=1;i<=n;i++)

	{

		ans=max(ans,max(a[i],b[i]));

		ans=max(ans,max(a[i]-poi[i].pos+b[i+1],b[i]-(rod-poi[i].pos)+a[i-1]));

	}

	printf("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

long long c,x[100005],maxx,shun[100005],ni[100005];

long long v[100005],val[100005],rval[100005];

int main()

{

	int i,j,n;

	while(scanf("%d%lld",&n,&c)!=EOF)

	{

		memset(shun,0,sizeof(shun));

		memset(ni,0,sizeof(ni));

		memset(val,0,sizeof(val));

		memset(rval,0,sizeof(rval));

    for(i=1;i<=n;i++)

    {

        scanf("%lld%d",&x[i],&v[i]);

        val[i]=val[i-1]+v[i];

        shun[i]=max(shun[i-1],val[i]-x[i]);

    }

    for( i=n;i>=1;i--)

    {

    	

        rval[i]=rval[i+1]+v[i];

        ni[i]=max(ni[i+1],rval[i]-c+x[i]);

    }

    maxx=0;

    for(i=n;i>=1;i--)

    {

        maxx=max(maxx,rval[i]-2*(c-x[i])+shun[i-1]);

        maxx=max(maxx,ni[i]);

    }

    for(i=1;i<=n;i++)

    {

        maxx=max(maxx,val[i]-2*x[i]+ni[i+1]);

        maxx=max(maxx,shun[i]);

    }

   printf("%lld\n",maxx);

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.261756857962969x):
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int maxn = 100010;



int n;LL c;

LL d[maxn],v[maxn];

LL mmax[maxn],maxx[maxn];

LL sum1[maxn],sum2[maxn];



int main() {

    scanf("%d%lld",&n,&c);

    for(int i=1;i<=n;i++) scanf("%lld%lld",&d[i],&v[i]);

    for(int i=n;i>=1;i--) sum2[i] = sum2[i+1]+v[i];

    for(int i=1;i<=n;i++) sum1[i] = sum1[i-1]+v[i];



    LL ans = 0;

    for(int i=n;i>=1;i--) {

        mmax[i] = max(mmax[i+1],sum2[i]-(c-d[i]));

        ans = max(ans,mmax[i]);

        //printf("%lld ",mmax[i]);

    }//puts("");



    for(int i=1;i<=n;i++)  {

        maxx[i] = max(maxx[i-1],sum1[i]-d[i]);

        ans = max(ans,maxx[i]);

    }



    for(int i=1;i<=n;i++) {

        ans = max(ans,sum1[i]-2*d[i]+mmax[i+1]);

    }

    for(int i=n;i>=1;i--) {

        ans = max(ans,sum2[i]-2*(c-d[i])+maxx[i-1]);

    }



    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

long long c,x[100005],maxx,shun[100005],ni[100005];

long long v[100005],val[100005],rval[100005];

int main()

{

	int i,j,n;

	while(scanf("%d%lld",&n,&c)!=EOF)

	{

		memset(shun,0,sizeof(shun));

		memset(ni,0,sizeof(ni));

		memset(val,0,sizeof(val));

		memset(rval,0,sizeof(rval));

    for(i=1;i<=n;i++)

    {

        scanf("%lld%d",&x[i],&v[i]);

        val[i]=val[i-1]+v[i];

        shun[i]=max(shun[i-1],val[i]-x[i]);

    }

    for( i=n;i>=1;i--)

    {

    	

        rval[i]=rval[i+1]+v[i];

        ni[i]=max(ni[i+1],rval[i]-c+x[i]);

    }

    maxx=0;

    for(i=n;i>=1;i--)

    {

        maxx=max(maxx,rval[i]-2*(c-x[i])+shun[i-1]);

        maxx=max(maxx,ni[i]);

    }

    for(i=1;i<=n;i++)

    {

        maxx=max(maxx,val[i]-2*x[i]+ni[i+1]);

        maxx=max(maxx,shun[i]);

    }

   printf("%lld\n",maxx);

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.208509220424417x):
#include<cstdio>

#include<deque>

#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;



typedef long long LL;

const int MAXN=100000+5;

const int INF=0x3f3f3f3f;



LL x[MAXN],v[MAXN];

LL dp1[MAXN],dp2[MAXN];



int main()

{

    LL n,c;

    cin>>n>>c;

    for(int i=1;i<=n;i++)

        cin>>x[i]>>v[i];

    LL sm=0;

    for(int i=1;i<=n;i++)

    {

        sm+=v[i]-(x[i]-x[i-1]);

        dp1[i]=max(sm,dp1[i-1]);

    }

    x[n+1]=c;

    sm=0;

    for(int i=n;i>=1;i--)

    {

        sm+=v[i]-(x[i+1]-x[i]);

        dp2[i]=max(sm,dp2[i+1]);

    }

    LL ans=max(dp1[n],dp2[1]);

    for(int i=n;i>=2;i--)

        ans=max(ans,dp2[i]+dp1[i-1]-(c-x[i]));

    for(int i=1;i<=n-1;i++)

        ans=max(ans,dp1[i]-x[i]+dp2[i+1]);

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

long long c,x[100005],maxx,shun[100005],ni[100005];

long long v[100005],val[100005],rval[100005];

int main()

{

	int i,j,n;

	while(scanf("%d%lld",&n,&c)!=EOF)

	{

		memset(shun,0,sizeof(shun));

		memset(ni,0,sizeof(ni));

		memset(val,0,sizeof(val));

		memset(rval,0,sizeof(rval));

    for(i=1;i<=n;i++)

    {

        scanf("%lld%d",&x[i],&v[i]);

        val[i]=val[i-1]+v[i];

        shun[i]=max(shun[i-1],val[i]-x[i]);

    }

    for( i=n;i>=1;i--)

    {

    	

        rval[i]=rval[i+1]+v[i];

        ni[i]=max(ni[i+1],rval[i]-c+x[i]);

    }

    maxx=0;

    for(i=n;i>=1;i--)

    {

        maxx=max(maxx,rval[i]-2*(c-x[i])+shun[i-1]);

        maxx=max(maxx,ni[i]);

    }

    for(i=1;i<=n;i++)

    {

        maxx=max(maxx,val[i]-2*x[i]+ni[i+1]);

        maxx=max(maxx,shun[i]);

    }

   printf("%lld\n",maxx);

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.263416012638314x):
#include<bits/stdc++.h> 

using namespace std;

typedef long long ll;

#define INF 0x3f3f3f3f

#define Max int(1e5+10)

ll x[Max],v[Max],a[Max],b[Max];

int main()  

{  

    ll n,c;

    while(~scanf("%lld%lld",&n,&c))

	{

	    for(ll i=1;i<=n;i++)

	     {

	     	scanf("%lld%lld",&x[i],&v[i]);

	     	a[i]=a[i-1]-x[i]+x[i-1]+v[i];

		 }

		 x[n+1]=c;

		 for(ll i=n;i>0;i--)

	     	b[i]=b[i+1]-x[i+1]+x[i]+v[i];

	     for(ll i=2;i<=n;i++)

		     a[i]=max(a[i-1],a[i]);

		for(ll i=n-1;i>0;i--)

		     b[i]=max(b[i+1],b[i]);	 	

		ll ma=0;

		 for(ll i=1;i<=n;i++)

		 {

		 	ma=max(ma,a[i]);

		 	ma=max(ma,b[i]);

		 	ma=max(ma,a[i]-x[i]+b[i+1]);

		 	ma=max(ma,b[i]-(c-x[i])+a[i-1]);

		 }

		 printf("%lld\n",ma);

	} 

    return 0;  

      

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

long long c,x[100005],maxx,shun[100005],ni[100005];

long long v[100005],val[100005],rval[100005];

int main()

{

	int i,j,n;

	while(scanf("%d%lld",&n,&c)!=EOF)

	{

		memset(shun,0,sizeof(shun));

		memset(ni,0,sizeof(ni));

		memset(val,0,sizeof(val));

		memset(rval,0,sizeof(rval));

    for(i=1;i<=n;i++)

    {

        scanf("%lld%d",&x[i],&v[i]);

        val[i]=val[i-1]+v[i];

        shun[i]=max(shun[i-1],val[i]-x[i]);

    }

    for( i=n;i>=1;i--)

    {

    	

        rval[i]=rval[i+1]+v[i];

        ni[i]=max(ni[i+1],rval[i]-c+x[i]);

    }

    maxx=0;

    for(i=n;i>=1;i--)

    {

        maxx=max(maxx,rval[i]-2*(c-x[i])+shun[i-1]);

        maxx=max(maxx,ni[i]);

    }

    for(i=1;i<=n;i++)

    {

        maxx=max(maxx,val[i]-2*x[i]+ni[i+1]);

        maxx=max(maxx,shun[i]);

    }

   printf("%lld\n",maxx);

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.209434221986829x):
#include<iostream>

#include<cmath>

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

long long a[100010],b[100010],x[100010],v[100010];



int main()

{

//	cout<<a[0]<<" "<<b[0];

	long long n,c;

	cin>>n>>c;

	cin>>x[1]>>v[1];

	a[1]=v[1]-x[1];

	for(int i=2;i<=n;i++){

		cin>>x[i]>>v[i];

		a[i]=a[i-1]-x[i]+v[i]+x[i-1];

	}

	b[1]=v[n]-(c-x[n]);

	for(int i=2;i<=n;i++){

		b[i]=b[i-1]-(c-x[n-i+1])+v[n-i+1]+(c-x[n-i+2]);

	}

	long long ans=0;

	for(int i=2;i<=n;i++){

		a[i]=max(a[i-1],a[i]);

		b[i]=max(b[i-1],b[i]);

		ans=max(ans,max(a[i],b[i]));

	}

	long long ans1=0,ans2=0;

	for(int i=1;i<=n;i++){

		if(i<n){

			ans1=max(ans1, a[i]-x[i]+b[n-i] );

			ans2=max(ans2, b[i]-(c-x[n-i+1])+a[n-i] );

		}

		else{

			ans1=max(ans1, a[i]);

			ans2=max(ans2, b[i]);

		}

	}

	cout<<max( ans, max(ans1,ans2) )<<endl;

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

long long c,x[100005],maxx,shun[100005],ni[100005];

long long v[100005],val[100005],rval[100005];

int main()

{

	int i,j,n;

	while(scanf("%d%lld",&n,&c)!=EOF)

	{

		memset(shun,0,sizeof(shun));

		memset(ni,0,sizeof(ni));

		memset(val,0,sizeof(val));

		memset(rval,0,sizeof(rval));

    for(i=1;i<=n;i++)

    {

        scanf("%lld%d",&x[i],&v[i]);

        val[i]=val[i-1]+v[i];

        shun[i]=max(shun[i-1],val[i]-x[i]);

    }

    for( i=n;i>=1;i--)

    {

    	

        rval[i]=rval[i+1]+v[i];

        ni[i]=max(ni[i+1],rval[i]-c+x[i]);

    }

    maxx=0;

    for(i=n;i>=1;i--)

    {

        maxx=max(maxx,rval[i]-2*(c-x[i])+shun[i-1]);

        maxx=max(maxx,ni[i]);

    }

    for(i=1;i<=n;i++)

    {

        maxx=max(maxx,val[i]-2*x[i]+ni[i+1]);

        maxx=max(maxx,shun[i]);

    }

   printf("%lld\n",maxx);

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.152831921340295x):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

const int MAXN = 1e5+100;

ll Left[MAXN];

ll MaxLeft[MAXN];

ll Right[MAXN];

ll MaxRight[MAXN];

ll x[MAXN],v[MAXN];



int main()

{

    ios::sync_with_stdio(false);

    int N;

    ll C;

    cin>>N>>C;

    for(int i=1;i<=N;++i)   cin>>x[i]>>v[i];

    x[N+1]=C;

    for(int i=1;i<=N;++i)

    {

        MaxLeft[i]=Left[i]=Left[i-1]+v[i]-(x[i]-x[i-1]);

        MaxRight[i]=Right[i]=Right[i-1]+v[N-i+1]-(x[N-i+2]-x[N-i+1]);

    }

    for(int i=2;i<=N;++i)

    {

        MaxLeft[i]=max(MaxLeft[i-1],MaxLeft[i]);

        MaxRight[i]=max(MaxRight[i-1],MaxRight[i]);

    }

    ll ans=0;

    for(int i=1;i<=N;++i)

    {

        ans=max(ans,Left[i]);

        ans=max(ans,Right[i]);

        ans=max(ans,Left[i]-x[i]+MaxRight[N-i]);

        ans=max(ans,Right[i]-(C-x[N-i+1])+MaxLeft[N-i]);

    }

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



#define int long long



#define rep(i,n) for(int i=0;i<(n);i++)

#define pb push_back

#define all(v) (v).begin(),(v).end()

#define fi first

#define se second

typedef vector<int>vint;

typedef pair<int,int>pint;

typedef vector<pint>vpint;



template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}

template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}



const int INF=1001001001001001001ll;



int N,C;

int X[555555],V[555555];

int S[555555];



int ans;



void solve()

{

    for(int i=0;i<N;i++) S[i+1]=S[i]+V[i];

    int ma=-INF;

    for(int i=N-1;i>=0;i--)

    {

        chmax(ans,S[i+1]-X[i]);

        chmax(ans,S[i+1]-2*X[i]+ma);

        chmax(ma,S[N]-S[i]+X[i]-C);

    }

}



signed main(){

    cin>>N>>C;

    vector<int> x(N),v(N);

    for(int i=0;i<N;i++) cin>>x[i]>>v[i];



    for(int t=0;t<2;t++)

    {

        for(int i=0;i<N;i++)

        {

            X[i]=x[i];

            V[i]=v[i];

        }

        solve();

        for(int i=0;i<N;i++) x[i]=C-x[i];

        reverse(all(x));

        reverse(all(v));

    }

    cout<<ans<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.271678751070078x):
//Zory in 2018

//*******************头文件*******************

#include<cstdio>

#include<cstring>

#include<cmath>

#include<queue>

#include<vector>

#include<set>

#include<queue>

#include<algorithm>

typedef long long ll;

typedef unsigned long long ull;

ll mymax(ll x,ll y) {return x>y?x:y;}

int mymin(int x,int y) {return x<y?x:y;}

int myabs(int x) {return x>0?x:-x;}

//*******************全局常量*******************

const int MAXN=110000;

//*******************全局定义*******************

ll f[MAXN],g[MAXN];//顺时针，逆时针

ll x[MAXN],v[MAXN];

//*******************实现*******************



//*******************主函数*******************

int main()

{

	//freopen("tmp.in","r",stdin);

    int n;ll c;scanf("%d%lld",&n,&c);

    for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&v[i]);



    ll ans=0,sum;

    sum=0;for(int i=1;i<=n;i++) sum+=v[i],f[i]=sum-x[i],ans=mymax(ans,f[i]);

    sum=0;for(int i=n;i>=1;i--) sum+=v[i],g[i]=sum-(c-x[i]),ans=mymax(ans,g[i]);



    ll mx;

    mx=0;for(int i=n-1;i>=1;i--) mx=mymax(mx,g[i+1]),ans=mymax(ans,f[i]+mx-x[i]);

    mx=0;for(int i=2;i<=n;i++) mx=mymax(mx,f[i-1]),ans=mymax(ans,g[i]+mx-(c-x[i]));



    printf("%lld",ans);

}
// Slower C++ solution:
#include<iostream>

#include<stdio.h>

#include<algorithm>

#include<math.h>

using namespace std;

int a[10001];

int main()

{

    int n,b,c,m=0;

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d",&a[i]);

    for(int i=1;i<=n;i++)

 {   if(a[i]==1)continue;

   else

   {

     int t=0;

    b=sqrt(a[i]);

    for(int j=2;j<=b;j++)

    if(a[i]%j==0)t++;

    if(t==0)m++;

   }

 }

    printf("%d\n",m);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.18334362706072x):
#include<cstdio>

int isPrime(int x){

int i;

if(x<2)return 0;

else if(x==2)return 1;

if(x%2==0)return 0;

for(i=3;i*i<=x;i+=2){

if(x%i==0)return 0;

}

return 1;

}

int main(){

int n,x,i;

int cnt=0;

scanf("%d",&n);

for(i=0;i<n;i++){

scanf("%d",&x);

if(isPrime(x))cnt++;

}

printf("%d\n",cnt);

return 0;

}
// Slower C++ solution:
#include<iostream>

#include<stdio.h>

#include<string.h>

using namespace std;



bool isprime(int k)

{

    if(k<2) return 0;

    else if(k==2) return 1;

    if(k%2==0) return 0;

    for(int i=3;i*i<=k;i+=2)

    {

        if(k%i==0) return 0;

    }

    return 1;

}



int main()

{

	int n,m,ans=0;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		scanf("%d",&m);

		if(isprime(m)) ans++;

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.141452792904107x):
#include<cstdio>

int isPrime(int x){

int i;

if(x<2)return 0;

else if(x==2)return 1;

if(x%2==0)return 0;

for(i=3;i*i<=x;i+=2){

if(x%i==0)return 0;

}

return 1;

}

int main(){

int n,x,i;

int cnt=0;

scanf("%d",&n);

for(i=0;i<n;i++){

scanf("%d",&x);

if(isPrime(x))cnt++;

}

printf("%d\n",cnt);

return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include <algorithm>



using namespace std;

vector<int> n;



int main(void)

{

    int count,temp,ans=0,rant=0;



    cin>>count;

    for(int i=0;i<count;i++)

    {

        cin>>temp;

        rant=rant>temp?rant:temp;

        n.push_back(temp);

    }



  vector<bool> pri(++rant,0);



   for(int i=2;i*i<rant;i++)

  {

      if(!pri.at(i))

         {



             for(int j=i;j*i<rant;j++)

                {

                   pri[i*j]=true;

                }

         }

  }



    for(int i=0;i<count;i++)

    {

        if(!pri.at(n.at(i)))

            ans++;

    }



  cout<<ans<<endl;

return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.27163378848587x):
#include<cstdio>

int isPrime(int x){

int i;

if(x<2)return 0;

else if(x==2)return 1;

if(x%2==0)return 0;

for(i=3;i*i<=x;i+=2){

if(x%i==0)return 0;

}

return 1;

}

int main(){

int n,x,i;

int cnt=0;

scanf("%d",&n);

for(i=0;i<n;i++){

scanf("%d",&x);

if(isPrime(x))cnt++;

}

printf("%d\n",cnt);

return 0;

}