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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

#define mem(a,b) memset((a),(b),sizeof(a))

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

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

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

			if(a[i]+a[i-1]>x)

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

using namespace std;

#define INF 0x3f3f3f3f







int main()

{

	

	int i, a[200000];

	long long n, x, z, sum;

	std::ios::sync_with_stdio(false);

	while (cin >> n >> x)

	{

		z = 0;

		sum = 0;

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

			cin >> a[i];

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

		{

			if (a[i] + a[i + 1] > x)

			{

				sum += a[i + 1];

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

				sum -= a[i + 1];

			}

		}

		cout << sum << endl;

	}





	return 0;

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

#define mem(a,b) memset((a),(b),sizeof(a))

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

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

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

			if(a[i]+a[i-1]>x)

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for (int i=(a); i<(b); i++)

using namespace std;

typedef long long ll;

const int MAX_N = 7 + 100000;

///----------------------------------------------

int dig[MAX_N];

int main() {



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



    ///read

    int n,m; cin>>n>>m;

    rep(i,1,n+1) scanf("%d",&dig[i]);



    ///work

    ll ans=0;

    rep(i,1,n+1) if (dig[i]+dig[i-1]>m) {

        ans+=dig[i]+dig[i-1]-m;

        dig[i]=m-dig[i-1];

    }

    cout << ans;



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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

#define mem(a,b) memset((a),(b),sizeof(a))

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

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

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

			if(a[i]+a[i-1]>x)

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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



using namespace std;



int main()

{

	long arr[100005];

	int n;

	long x;

	cin >> n >> x;

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

		cin >> arr[i];

   	}

   	long long ans = 0;

   	if(arr[0] > x) {

   	 	ans += arr[0] - x;

   	 	arr[0] = x;

   	}

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

   		if((arr[i] + arr[i - 1] - x ) > 0) {

   		 	ans += (arr[i] - x + arr[i - 1]);

   		 	arr[i] -= (arr[i] - x + arr[i - 1]) ;

   		}

   	}

   	cout << ans << endl;



	return 0;

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

using namespace std;

const int maxi=200010;

long long  a[maxi],n,x,sum,k,i;

int main()

{

    while (cin>>n>>x)

    {

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

             cin>>a[i];

          sum=0;

         if (a[0]>x)

         {

             sum+=a[0]-x;

             a[0]=x;

         }

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

         {

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

             if (k>0)

             {

                 sum+=k;

                 a[i]-=k;

             }

         }

         cout<<sum<<endl;

     }

     return 0;

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

using namespace std;

long long a[100005];

int main()

{

	long long n,ans,nmax,num;

	cin>>n>>nmax;

	ans=0;

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

	{

		cin>>a[i];

	}

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

	{

		if(a[i]+a[i+1]>nmax)

		{

			num=a[i]+a[i+1]-nmax;

			ans+=(a[i]+a[i+1]-nmax);

			if(a[i+1]>=num)

			{

				a[i+1]-=num;

				

			}

			else

			{

				a[i+1]=0;

			}

		}

		

	 } 

	 cout<<ans<<endl;

	 return 0;

} 

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#define ll long long

using namespace std;



const int maxn = 1e5+10;

int a[maxn];

int main(){

  ll k,n,x,ans=0;

  cin>>n>>x;

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

    cin>>a[i];

  if(a[0]>x){

    ans=a[0]-x;

    a[0]=x;

  }

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

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

    if(k>0){

      ans+=k;

      a[i]-=k;

    }

  }

  cout<<ans<<endl;

  return 0;

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

using namespace std;

int main()

{

    long long int n,x,t,s=0;

    long long int a[150000];

    cin>>n>>x;

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

    {

        cin>>a[i];

    }

    if(a[0]>x)  {s+=a[0]-x; a[0]=x;}

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

    {

       if(a[i]+a[i-1]>x) {

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

        a[i]-=t;

        s+=t;

       }

    }

   cout<<s<<endl;

    return 0;

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

#include <sstream>

#include <cmath>

using namespace std;

const int inf =0x3f3f3f3f;

typedef long long LL;

const int MAXN=100010;

int a[MAXN];

int main()

{

    LL n, x;

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

    {

        LL sum=0;

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

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

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

        {

            if(a[i]+a[i+1]>=x)

            {

                LL t=a[i]+a[i+1]-x;

                sum+=t;

                if(t>=a[i+1])

                    a[i+1]=0;

                else

                    a[i+1]-=t;

            }

        }

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

    }

    return 0;

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include<algorithm>

#include<cstdio>

#include<cstring>

#include<vector>

#include<queue>

#include<map>

#include<cmath>

#define N 100009

using namespace std;

const int INF = 0x3f3f3f3f;

int a[N];



int main()

{

    int n, x;

    scanf("%d%d", &n, &x);

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

    long long ans, now; ans = now = 0;

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

    {

        if(now + a[i] <= x) now = a[i];

        else ans += now + a[i] - x, now = a[i] - (now + a[i] - x);

    }

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

    return 0;

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include<string.h>

#include<algorithm>

using namespace std;

int a[1000001];

main()

{

    int i,j;

    long long n,m,sum,p;

    long long a[100001];

    memset(a,0,sizeof(a));

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

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

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

    sum=0;

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

    {

        if (a[i]+a[i+1]>m)

        {

            sum+=a[i]+a[i+1]-m;

             //printf("%lld\n",sum);

            p=a[i]+a[i+1]-m;

            a[i+1]=a[i+1]-p;

            //printf("%lld\n",a[i+1]);

            p=0;

        }

    }

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

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

#define mem(a,b) memset((a),(b),sizeof(a))

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

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

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

			if(a[i]+a[i-1]>x)

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include<string.h>

#include<stdlib.h>

#include<algorithm>

#include<iostream>

#include<ctype.h>

#include<stack>

#include<queue>

#include <cmath>  

using namespace std;

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <string.h>

#include <algorithm>

using namespace std;

#define  inf 0x3fffffff 

int main()

{

	int i, n, x, a[110000];

	long long sum;

	while (cin>>n>>x)

	{

		sum = 0;

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

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

		if (a[1] > x)

		{

			sum += a[1] - x;

			a[1] = x;

		}

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

		{

			int flag = a[i] + a[i - 1] - x;

			if (flag > 0)

			{

				sum += flag;

				a[i] -= flag;

			}

		}

		cout << sum << endl;

	}

	return 0;

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

using namespace std;

#define INF 0x3f3f3f3f







int main()

{

	

	int i, a[200000];

	long long n, x, z, sum;

	std::ios::sync_with_stdio(false);

	while (cin >> n >> x)

	{

		z = 0;

		sum = 0;

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

			cin >> a[i];

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

		{

			if (a[i] + a[i + 1] > x)

			{

				sum += a[i + 1];

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

				sum -= a[i + 1];

			}

		}

		cout << sum << endl;

	}





	return 0;

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for (int i=(a); i<(b); i++)

using namespace std;

typedef long long ll;

const int MAX_N = 7 + 100000;

///----------------------------------------------

int dig[MAX_N];

int main() {



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



    ///read

    int n,m; cin>>n>>m;

    rep(i,1,n+1) scanf("%d",&dig[i]);



    ///work

    ll ans=0;

    rep(i,1,n+1) if (dig[i]+dig[i-1]>m) {

        ans+=dig[i]+dig[i-1]-m;

        dig[i]=m-dig[i-1];

    }

    cout << ans;



}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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



using namespace std;



int main()

{

	long arr[100005];

	int n;

	long x;

	cin >> n >> x;

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

		cin >> arr[i];

   	}

   	long long ans = 0;

   	if(arr[0] > x) {

   	 	ans += arr[0] - x;

   	 	arr[0] = x;

   	}

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

   		if((arr[i] + arr[i - 1] - x ) > 0) {

   		 	ans += (arr[i] - x + arr[i - 1]);

   		 	arr[i] -= (arr[i] - x + arr[i - 1]) ;

   		}

   	}

   	cout << ans << endl;



	return 0;

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

	scanf("%lld %lld",&a,&b);

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

	for (i=1;i<=a;i++){

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

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

using namespace std;

const int maxi=200010;

long long  a[maxi],n,x,sum,k,i;

int main()

{

    while (cin>>n>>x)

    {

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

             cin>>a[i];

          sum=0;

         if (a[0]>x)

         {

             sum+=a[0]-x;

             a[0]=x;

         }

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

         {

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

             if (k>0)

             {

                 sum+=k;

                 a[i]-=k;

             }

         }

         cout<<sum<<endl;

     }

     return 0;

}


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

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<ctime>

#include<vector>

#include<queue>

#include<stack>

#include<map>

using namespace std;

#define FOR(i,s,e) for (int i=s;i<e;i++)

#define FOE(i,s,e) for (int i=s;i<=e;i++)

#define FOD(i,s,e) for (int i=s;i>=e;i--)

#define SET(a,e) memset(a,e,sizeof(a))

#define LL long long

#define LD long double

#define pb push_back

#define x first

#define y second

#define PII pair<int,int>

#define PLI pair<LL,int>

#define PIL pair<int,LL>

#define PLL pair<LL,LL>

#define eps 1e-9

#define mp make_pair



int n,x,a[100005];

LL ans;



int main () {

	scanf("%d%d",&n,&x);

	a[0]=0;

	FOE(i,1,n) {

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

		if (a[i]>x) {

			ans=(LL)ans+a[i]-x;	

			a[i]=x;

		}

		if (a[i]+a[i-1]>x) {

			ans=(LL)ans+a[i]+a[i-1]-x;

			a[i]-=(a[i]+a[i-1]-x);

		}

		//printf("%lld %lld\n",ans,a[i]);

	}

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

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

using namespace std;

long long a[100005];

int main()

{

	long long n,ans,nmax,num;

	cin>>n>>nmax;

	ans=0;

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

	{

		cin>>a[i];

	}

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

	{

		if(a[i]+a[i+1]>nmax)

		{

			num=a[i]+a[i+1]-nmax;

			ans+=(a[i]+a[i+1]-nmax);

			if(a[i+1]>=num)

			{

				a[i+1]-=num;

				

			}

			else

			{

				a[i+1]=0;

			}

		}

		

	 } 

	 cout<<ans<<endl;

	 return 0;

} 

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

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<ctime>

#include<vector>

#include<queue>

#include<stack>

#include<map>

using namespace std;

#define FOR(i,s,e) for (int i=s;i<e;i++)

#define FOE(i,s,e) for (int i=s;i<=e;i++)

#define FOD(i,s,e) for (int i=s;i>=e;i--)

#define SET(a,e) memset(a,e,sizeof(a))

#define LL long long

#define LD long double

#define pb push_back

#define x first

#define y second

#define PII pair<int,int>

#define PLI pair<LL,int>

#define PIL pair<int,LL>

#define PLL pair<LL,LL>

#define eps 1e-9

#define mp make_pair



int n,x,a[100005];

LL ans;



int main () {

	scanf("%d%d",&n,&x);

	a[0]=0;

	FOE(i,1,n) {

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

		if (a[i]>x) {

			ans=(LL)ans+a[i]-x;	

			a[i]=x;

		}

		if (a[i]+a[i-1]>x) {

			ans=(LL)ans+a[i]+a[i-1]-x;

			a[i]-=(a[i]+a[i-1]-x);

		}

		//printf("%lld %lld\n",ans,a[i]);

	}

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

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

#define ll long long

using namespace std;



const int maxn = 1e5+10;

int a[maxn];

int main(){

  ll k,n,x,ans=0;

  cin>>n>>x;

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

    cin>>a[i];

  if(a[0]>x){

    ans=a[0]-x;

    a[0]=x;

  }

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

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

    if(k>0){

      ans+=k;

      a[i]-=k;

    }

  }

  cout<<ans<<endl;

  return 0;

}

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

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<ctime>

#include<vector>

#include<queue>

#include<stack>

#include<map>

using namespace std;

#define FOR(i,s,e) for (int i=s;i<e;i++)

#define FOE(i,s,e) for (int i=s;i<=e;i++)

#define FOD(i,s,e) for (int i=s;i>=e;i--)

#define SET(a,e) memset(a,e,sizeof(a))

#define LL long long

#define LD long double

#define pb push_back

#define x first

#define y second

#define PII pair<int,int>

#define PLI pair<LL,int>

#define PIL pair<int,LL>

#define PLL pair<LL,LL>

#define eps 1e-9

#define mp make_pair



int n,x,a[100005];

LL ans;



int main () {

	scanf("%d%d",&n,&x);

	a[0]=0;

	FOE(i,1,n) {

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

		if (a[i]>x) {

			ans=(LL)ans+a[i]-x;	

			a[i]=x;

		}

		if (a[i]+a[i-1]>x) {

			ans=(LL)ans+a[i]+a[i-1]-x;

			a[i]-=(a[i]+a[i-1]-x);

		}

		//printf("%lld %lld\n",ans,a[i]);

	}

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

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

using namespace std;

int main()

{

    long long int n,x,t,s=0;

    long long int a[150000];

    cin>>n>>x;

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

    {

        cin>>a[i];

    }

    if(a[0]>x)  {s+=a[0]-x; a[0]=x;}

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

    {

       if(a[i]+a[i-1]>x) {

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

        a[i]-=t;

        s+=t;

       }

    }

   cout<<s<<endl;

    return 0;

}

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

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<ctime>

#include<vector>

#include<queue>

#include<stack>

#include<map>

using namespace std;

#define FOR(i,s,e) for (int i=s;i<e;i++)

#define FOE(i,s,e) for (int i=s;i<=e;i++)

#define FOD(i,s,e) for (int i=s;i>=e;i--)

#define SET(a,e) memset(a,e,sizeof(a))

#define LL long long

#define LD long double

#define pb push_back

#define x first

#define y second

#define PII pair<int,int>

#define PLI pair<LL,int>

#define PIL pair<int,LL>

#define PLL pair<LL,LL>

#define eps 1e-9

#define mp make_pair



int n,x,a[100005];

LL ans;



int main () {

	scanf("%d%d",&n,&x);

	a[0]=0;

	FOE(i,1,n) {

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

		if (a[i]>x) {

			ans=(LL)ans+a[i]-x;	

			a[i]=x;

		}

		if (a[i]+a[i-1]>x) {

			ans=(LL)ans+a[i]+a[i-1]-x;

			a[i]-=(a[i]+a[i-1]-x);

		}

		//printf("%lld %lld\n",ans,a[i]);

	}

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

}